Class: Bridgetown::Tags::RubyRender
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Bridgetown::Tags::RubyRender
- Defined in:
- bridgetown-core/lib/bridgetown-core/tags/ruby_render.rb
Instance Method Summary collapse
-
#initialize(tag_name, input, tokens) ⇒ RubyRender
constructor
A new instance of RubyRender.
-
#render(context) ⇒ String
Constructor Details
#initialize(tag_name, input, tokens) ⇒ RubyRender
Returns a new instance of RubyRender.
13 14 15 16 17 18 19 20 21 |
# File 'bridgetown-core/lib/bridgetown-core/tags/ruby_render.rb', line 13 def initialize(tag_name, input, tokens) super @input = input @attributes = {} input.scan(Liquid::TagAttributes) do |key, value| @attributes[key.to_sym] = parse_expression(value) end end |
Instance Method Details
#render(context) ⇒ String
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'bridgetown-core/lib/bridgetown-core/tags/ruby_render.rb', line 25 def render(context) view_context = Bridgetown::RubyTemplateView.new(context.registers[:resource]) component_class_name_snakecase = @input.split(",").first component_class_name = component_class_name_snakecase.tr("\"'", "").camelize.strip component_class = self.class.const_get(component_class_name) @attributes.each do |key, value| @attributes[key] = value.evaluate(context) if value.is_a?(Liquid::VariableLookup) end component_instance = component_class.new(**@attributes) if component_instance.respond_to?(:render_in) component_instance.render_in(view_context) else component_instance.to_s end end |