Module: Bridgetown::Builders::DSL::Liquid
- Included in:
- PluginBuilder
- Defined in:
- lib/bridgetown-builder/dsl/liquid.rb
Instance Method Summary collapse
- #liquid_filter(filter_name, method_name = nil, filters_scope: false, &block) ⇒ Object
- #liquid_tag(tag_name, method_name = nil, as_block: false, &block) ⇒ Object
Instance Method Details
#liquid_filter(filter_name, method_name = nil, filters_scope: false, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bridgetown-builder/dsl/liquid.rb', line 7 def liquid_filter(filter_name, method_name = nil, filters_scope: false, &block) builder_self = self m = Module.new if block && !filters_scope m.define_method filter_name do |*args| builder_self.instance_exec(*args, &block) end else block = method(method_name) if method_name m.define_method filter_name, &block end ::Liquid::Template.register_filter(m) functions << { name: name, filter: m } end |
#liquid_tag(tag_name, method_name = nil, as_block: false, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bridgetown-builder/dsl/liquid.rb', line 25 def liquid_tag(tag_name, method_name = nil, as_block: false, &block) block = method(method_name) if method_name.is_a?(Symbol) local_name = name # pull the name method into a local variable tag_class = as_block ? ::Liquid::Block : ::Liquid::Tag tag = Class.new(tag_class) do define_method(:_builder_block) { block } define_singleton_method(:custom_name) { local_name } def inspect "#{self.class.custom_name} (Liquid Tag)" end attr_reader :content, :context def render(context) @context = context @content = super if is_a?(::Liquid::Block) _builder_block.call(@markup.strip, self) end end ::Liquid::Template.register_tag tag_name, tag functions << { name: name, tag: [tag_name, tag] } end |