Class: Lookbook::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_object, arg_names = nil, parser: nil, **options) ⇒ Tag

Returns a new instance of Tag.



8
9
10
11
12
13
14
15
16
17
# File 'lib/lookbook/tag.rb', line 8

def initialize(tag_object, arg_names = nil, parser: nil, **options)
  @tag_object = tag_object
  @arg_names = arg_names
  @args = {}
  @opts = {}
  @options = options
  @parser = parser
  @data = Store.new
  run_parser
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



100
101
102
103
104
105
106
# File 'lib/lookbook/tag.rb', line 100

def method_missing(name, *method_args)
  if name.end_with? "="
    data[name.to_s.chomp("=").to_sym] = method_args.first
  else
    data[name] || args[name]
  end
end

Instance Attribute Details

#arg_namesObject (readonly)

Returns the value of attribute arg_names.



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

def arg_names
  @arg_names
end

#argsObject

Returns the value of attribute args.



6
7
8
# File 'lib/lookbook/tag.rb', line 6

def args
  @args
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#optsObject

Returns the value of attribute opts.



6
7
8
# File 'lib/lookbook/tag.rb', line 6

def opts
  @opts
end

Instance Method Details

#get_opt(key, fallback = nil) ⇒ Object



27
28
29
# File 'lib/lookbook/tag.rb', line 27

def get_opt(key, fallback = nil)
  opts[key] || fallback
end

#opts_strObject



31
32
33
# File 'lib/lookbook/tag.rb', line 31

def opts_str
  @opts_str ||= text_tokens.size > args_count ? text_tokens.slice(args_count, text_tokens.size).join(" ") : ""
end

#tag_bodyObject



23
24
25
# File 'lib/lookbook/tag.rb', line 23

def tag_body
  @tag_object.text
end

#tag_nameObject



19
20
21
# File 'lib/lookbook/tag.rb', line 19

def tag_name
  @name ||= @tag_object.tag_name.to_sym
end