Class: Faalis::Liquid::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/faalis/liquid/tag.rb

Direct Known Subclasses

RenderTag

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args, options) ⇒ Tag

Returns a new instance of Tag.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/faalis/liquid/tag.rb', line 25

def initialize(name, args, options)
  super

  if !arguments.empty? && (args.nil? || args.empty?)
      count = arguments.length
      raise ArgumentError.new "'#{count}' argument(s) is/are needed for '#{self.class.name}' tag."
  end

  @direction   = ::Faalis::I18n.direction(::I18n.locale)

  @args = args.split(',').map do |x|
    x.strip.tr('""', '').tr("''", '')
  end

  @params = {}

  arguments.each_with_index do |arg, index|
    @params[arg[:name]] = @args.fetch(index, arg[:default])
  end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/faalis/liquid/tag.rb', line 5

def arguments
  @arguments
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/faalis/liquid/tag.rb', line 5

def params
  @params
end

Class Method Details

.argument(options) ⇒ Object



18
19
20
21
22
23
# File 'lib/faalis/liquid/tag.rb', line 18

def self.argument(options)
  raise ArgumentError.new "'name' is mandatory for argument in '#{self.class.name}'" if options[:name].nil?

  @arguments ||= []
  @arguments << options
end

.nameObject



14
15
16
# File 'lib/faalis/liquid/tag.rb', line 14

def self.name
  @@name
end

.tag_name(name) ⇒ Object

This method produce the ‘tag_name` DSL which is mandatory for each tag and defines the tag name that the tag class should be registered with



10
11
12
# File 'lib/faalis/liquid/tag.rb', line 10

def self.tag_name(name)
  @@name = name
end