Class: JsDuck::Tag::Aside

Inherits:
Tag
  • Object
show all
Defined in:
lib/jsduck/tag/aside.rb

Constant Summary

Constants inherited from Tag

Tag::POS_ASIDE, Tag::POS_DEFAULT, Tag::POS_DEPRECATED, Tag::POS_DOC, Tag::POS_ENUM, Tag::POS_FIRES, Tag::POS_LOCALDOC, Tag::POS_OVERRIDES, Tag::POS_PARAM, Tag::POS_PREVENTABLE, Tag::POS_PRIVATE, Tag::POS_RETURN, Tag::POS_SINCE, Tag::POS_SUBPROPERTIES, Tag::POS_TEMPLATE, Tag::POS_THROWS

Instance Attribute Summary collapse

Attributes inherited from Tag

#css, #ext_define_default, #ext_define_pattern, #html_position, #pattern, #repeatable, #signature, #tagname

Instance Method Summary collapse

Methods inherited from Tag

descendants, #format, #parse_ext_define

Constructor Details

#initializeAside

Returns a new instance of Aside.



6
7
8
9
10
11
# File 'lib/jsduck/tag/aside.rb', line 6

def initialize
  @pattern = "aside"
  @tagname = :aside
  @repeatable = true
  @html_position = POS_ASIDE
end

Instance Attribute Details

#assetsObject

special accessor for @aside alone through which assets are set



54
55
56
# File 'lib/jsduck/tag/aside.rb', line 54

def assets
  @assets
end

Instance Method Details

#aside_type(p) ⇒ Object



22
23
24
# File 'lib/jsduck/tag/aside.rb', line 22

def aside_type(p)
  p.look(/\w+/) ? p.ident.to_sym : nil
end

#get_assets_group(type) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/jsduck/tag/aside.rb', line 56

def get_assets_group(type)
  case type
  when :guide then @assets.guides
  when :video then @assets.videos
  when :example then @assets.examples
  else {}
  end
end

#parse_doc(p, pos) ⇒ Object

Parses: @aside [ guide | video| example ] name



14
15
16
17
18
19
20
# File 'lib/jsduck/tag/aside.rb', line 14

def parse_doc(p, pos)
  {
    :tagname => :aside,
    :type => aside_type(p),
    :name => p.hw.ident,
  }
end

#process_doc(h, tags, pos) ⇒ Object



26
27
28
# File 'lib/jsduck/tag/aside.rb', line 26

def process_doc(h, tags, pos)
  h[:aside] = tags
end

#to_html(context) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jsduck/tag/aside.rb', line 30

def to_html(context)
  context[:aside].map do |aside|
    type = aside[:type]
    name = aside[:name]
    assets_group = get_assets_group(type)
    asset = assets_group[name]
    if asset
      url = "#!/#{type}/#{name}"
      heading = type.to_s.capitalize
      title = asset["title"]
      icon_url = assets_group.icon_url(asset)
      <<-EOHTML
        <div class='aside #{type}'>
          <h4>#{heading}</h4>
          <p><a href='#{url}'><img src='#{icon_url}' alt=''> #{title}</a></p>
        </div>
      EOHTML
    else
      warn("Unknown @aside name: #{type} #{name}", context)
    end
  end.compact
end

#warn(msg, context) ⇒ Object



65
66
67
68
# File 'lib/jsduck/tag/aside.rb', line 65

def warn(msg, context)
  JsDuck::Logger.warn(:aside, msg, context[:files][0])
  nil
end