Malt  Malt::Format::Abstract

[Validate]
Generated with RDazzle Newfish 1.4.0

Abstract

Abstract format class serves as the base class for all other format classes.

Attributes

options[R]

Access to the options given to the initializer.

Public Class Methods

engine(set=nil) click to toggle source
    # File lib/malt/formats/abstract.rb, line 51
51:     def self.engine(set=nil)
52:       @engine = set if set
53:       @engine
54:     end
extensions() click to toggle source
    # File lib/malt/formats/abstract.rb, line 44
44:     def self.extensions
45:       @extensions
46:     end
new(options={}) click to toggle source
    # File lib/malt/formats/abstract.rb, line 59
59:     def initialize(options={})
60:       @options = options.rekey
61:       @type    = @options[:type]
62:       initialize_engine
63:     end
register(*exts) click to toggle source

Register the class to an extension type.

    # File lib/malt/formats/abstract.rb, line 30
30:     def self.register(*exts)
31:       @extensions = exts
32:       Malt::Format.register(self, *exts)
33: 
34:       #exts.each do |ext|
35:       #  Abstract.module_eval %{
36:       #    def to_#{ext}(*db,&yld)
37:       #      convert(:#{ext},*db,&yld)
38:       #    end
39:       #  }
40:       #end
41:     end

Public Instance Methods

default() click to toggle source

Default rendering type is :html. Override if it differs for the subclassing format.

     # File lib/malt/formats/abstract.rb, line 188
188:     def default
189:       :html
190:     end
engine() click to toggle source

Specified engine to use for rendering.

Keep in mind that the ability to specify the engine varies based on engine, format and output format.

    # File lib/malt/formats/abstract.rb, line 93
93:     def engine
94:       options[:engine] || self.class.engine
95:     end
extensions() click to toggle source
     # File lib/malt/formats/abstract.rb, line 167
167:     def extensions
168:       self.class.extensions
169:     end
file() click to toggle source

File name of document.

    # File lib/malt/formats/abstract.rb, line 80
80:     def file
81:       @file ||= options[:file].to_s
82:     end
parse_type_and_data(type_and_data) click to toggle source
     # File lib/malt/formats/abstract.rb, line 193
193:     def parse_type_and_data(type_and_data)
194:       if Symbol === type_and_data.first
195:         type = type_and_data.first
196:         data = type_and_data.last
197:       else
198:         type = nil
199:         data = type_and_data.first
200:       end
201:       return type, data
202:     end
refile(type=nil) click to toggle source

Produce a new filename replacing old extension with new extension.

type - Symbol representation of extension (e.g. :html).

Returns a String of the new file name.

     # File lib/malt/formats/abstract.rb, line 150
150:     def refile(type=nil)
151:       if file
152:         if type
153:           type = type.to_s.sub(/^\./,'')
154:           fext = self.class.extensions.find{|e| file.end_with?(e)}
155:           new_file = file.chomp(fext) + type
156:         else
157:           fext = self.class.extensions.find{|e| file.end_with?(e)}
158:           new_file = file.chomp('.'+fext)
159:         end
160:       else
161:         new_file = nil
162:       end
163:       new_file
164:     end
render(*type_and_data, &yld) click to toggle source

Render to default or given format.

If the first argument is a Symbol it is considered the format, otherwise it is taken to be the database for rendering template variables.

     # File lib/malt/formats/abstract.rb, line 106
106:     def render(*type_and_data, &yld)
107:       type, data = parse_type_and_data(type_and_data)
108:       meth = method(type || default)
109:       #__send__(type || default, data, &yld)
110:       meth.arity == 0 ?  meth.call(&yld) :  meth.call(data, &yld)
111:     end
subtype() click to toggle source
     # File lib/malt/formats/abstract.rb, line 172
172:     def subtype
173:       File.extname(file.chomp(type))
174:     end
text() click to toggle source

Document source text.

    # File lib/malt/formats/abstract.rb, line 75
75:     def text
76:       @text ||= options[:text] || File.read(file)
77:     end
to(type, data=nil, &yld) click to toggle source
     # File lib/malt/formats/abstract.rb, line 98
 98:     def to(type, data=nil, &yld)
 99:       __send__("to_#{type}", data, &yld)
100:     end
to_default(data=nil, &yld) click to toggle source
     # File lib/malt/formats/abstract.rb, line 182
182:     def to_default(data=nil, &yld)
183:       to(default, data, &yld)
184:     end
to_s() click to toggle source
     # File lib/malt/formats/abstract.rb, line 177
177:     def to_s
178:       text
179:     end
type() click to toggle source

File extension (with prefixed dot).

    # File lib/malt/formats/abstract.rb, line 85
85:     def type
86:       @type ||= File.extname(file)
87:     end

Private Instance Methods

initialize_engine() click to toggle source

Override this method to load rendering engine library.

    # File lib/malt/formats/abstract.rb, line 66
66:     def initialize_engine
67:     end

Disabled; run with --debug to generate this.