Class: JsDuck::Tag::Aside

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

Overview

Implementation of @aside tag.

Instance Attribute Summary

Attributes inherited from MetaTag

#assets, #boolean, #context, #formatter, #key, #multiline, #name, #position, #signature

Instance Method Summary collapse

Methods inherited from MetaTag

descendants, #format

Constructor Details

#initializeAside

Returns a new instance of Aside.



7
8
9
10
11
12
13
14
15
16
# File 'lib/jsduck/tag/aside.rb', line 7

def initialize
  @name = "aside"
  @key = :aside
  @position = :top
  @allowed_types = {
    :guide => true,
    :video => true,
    :example => true,
  }
end

Instance Method Details

#get_assets_group(type) ⇒ Object



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

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

#to_html(asides) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/jsduck/tag/aside.rb', line 34

def to_html(asides)
  asides.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}")
    end
  end.compact
end

#to_value(asides) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jsduck/tag/aside.rb', line 18

def to_value(asides)
  asides.map do |line|
    if line =~ /\A(\w+) +([^ ].*)\Z/
      type = $1.to_sym
      name = $2.strip
      if @allowed_types[type]
        {:type => type, :name => name}
      else
        warn("Unknown @aside type: #{type}")
      end
    else
      warn("Bad syntax: @aside #{line}")
    end
  end.compact
end

#warn(msg) ⇒ Object



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

def warn(msg)
  ctx = @context ? @context[:files][0] : {}
  JsDuck::Logger.warn(:aside, msg, ctx[:filename], ctx[:linenr])
  nil
end