Class: Razor::Renderer::Getter
- Inherits:
-
Object
- Object
- Razor::Renderer::Getter
- Defined in:
- lib/razor/renderer.rb
Class Attribute Summary collapse
-
.extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
.renderers ⇒ Object
readonly
Returns the value of attribute renderers.
Instance Attribute Summary collapse
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Class Method Summary collapse
Instance Method Summary collapse
- #from_file(filename) ⇒ Object
-
#initialize(path, proc) ⇒ Getter
constructor
A new instance of Getter.
Constructor Details
#initialize(path, proc) ⇒ Getter
Returns a new instance of Getter.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/razor/renderer.rb', line 31 def initialize(path, proc) @path = path if proc @renderer = instance_exec &proc else @renderer = instance_exec { nil } end if @renderer.is_a? String or @renderer.is_a? NilClass @renderer = Renderer.new(@renderer) end return @renderer end |
Class Attribute Details
.extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
9 10 11 |
# File 'lib/razor/renderer.rb', line 9 def extensions @extensions end |
.renderers ⇒ Object (readonly)
Returns the value of attribute renderers.
9 10 11 |
# File 'lib/razor/renderer.rb', line 9 def renderers @renderers end |
Instance Attribute Details
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
29 30 31 |
# File 'lib/razor/renderer.rb', line 29 def renderer @renderer end |
Class Method Details
.define_extension(name, renderer) ⇒ Object
20 21 22 |
# File 'lib/razor/renderer.rb', line 20 def define_extension(name, renderer) @extensions[".#{name}"] = renderer end |
.define_renderer(name, renderer) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/razor/renderer.rb', line 11 def define_renderer(name, renderer) @renderers[name] = renderer class_eval(<<-END) def #{name}(string) self.class.renderers[#{name.inspect}].new(string) end END end |
Instance Method Details
#from_file(filename) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/razor/renderer.rb', line 44 def from_file(filename) filepath = File.join(@path, filename) #str = (File.read(filepath, :mode=>'rb') rescue nil) begin str = File.open(filepath, 'rb') { |f| f.read } rescue str = nil end ext = File.extname filename renderer = self.class.extensions[ext] renderer ||= Renderer return renderer.new(str) end |