Class: Razor::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/razor/renderer.rb

Direct Known Subclasses

BlueRenderer, RedRenderer, SassRenderer, ScssRenderer

Defined Under Namespace

Classes: BlueRenderer, Getter, RedRenderer, SassRenderer, ScssRenderer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Renderer

Returns a new instance of Renderer.



95
96
97
# File 'lib/razor/renderer.rb', line 95

def initialize(string)
	@string = string
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



93
94
95
# File 'lib/razor/renderer.rb', line 93

def string
  @string
end

Class Method Details

.extension(ext) ⇒ Object



88
89
90
# File 'lib/razor/renderer.rb', line 88

def extension(ext)
	Getter.define_extension(ext, self)
end

.get(path, proc) ⇒ Object



62
63
64
# File 'lib/razor/renderer.rb', line 62

def get(path, proc)
	Getter.new(path, proc).renderer
end

.name(n) ⇒ Object



84
85
86
# File 'lib/razor/renderer.rb', line 84

def name(n)
	Getter.define_renderer(n, self)
end

.name_ext(n) ⇒ Object



79
80
81
82
# File 'lib/razor/renderer.rb', line 79

def name_ext(n)
	name(n)
	extension(n)
end

.try_loadObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/razor/renderer.rb', line 66

def try_load
	constants.each { |constname|
		const = const_get constname
		const.is_a? Class or next
		const.ancestors.include? Renderer or next
		const.respond_to? :load or next
		begin
			const.load
		rescue LoadError
		end
	}
end

Instance Method Details

#layout_render(context) ⇒ Object



99
100
101
102
# File 'lib/razor/renderer.rb', line 99

def layout_render(context)
	valid? or return context['yield']
	render(context)
end

#render(context) ⇒ Object



108
109
110
111
# File 'lib/razor/renderer.rb', line 108

def render(context)
	valid? or return ''
	Mustache.render(@string, context)
end

#valid?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/razor/renderer.rb', line 104

def valid?
	!!@string
end