Class: Lookbook::CustomTag

Inherits:
YardTag
  • Object
show all
Defined in:
lib/lookbook/tags/custom_tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from YardTag

#options, supports_options, supports_options?, #text, #to_s

Constructor Details

#initialize(tag_name, text = nil, *args) ⇒ CustomTag

Returns a new instance of CustomTag.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lookbook/tags/custom_tag.rb', line 7

def initialize(tag_name, text = nil, *args)
  tag_definition = Engine.tags.get_tag(tag_name)
  unless tag_definition
    raise ParserError.new "Unknown custom tag type '#{tag_name}'"
  end

  super(tag_name, text.to_s, *args)

  @custom_attributes = Store.new
  @arg_names = tag_definition.options.fetch(:named_args, [])
  @after_parse = tag_definition.options.fetch(:after_parse, nil)

  validate_arg_names

  @tag_args = parse_tag
  @after_parse.call(self) if @after_parse.respond_to?(:call)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (protected)



49
50
51
52
53
54
55
# File 'lib/lookbook/tags/custom_tag.rb', line 49

def method_missing(name, *args)
  if name.end_with? "="
    @custom_attributes[name.to_s.chomp("=")] = args.first
  else
    @custom_attributes.public_send(name, *args) || tag_args[name]
  end
end

Instance Attribute Details

#arg_namesObject (readonly)



5
6
7
# File 'lib/lookbook/tags/custom_tag.rb', line 5

def arg_names
  @arg_names
end

#tag_argsObject (readonly)



5
6
7
# File 'lib/lookbook/tags/custom_tag.rb', line 5

def tag_args
  @tag_args
end