Class: StyleGuide::Partial

Inherits:
Object
  • Object
show all
Defined in:
lib/style_guide/partial.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, section) ⇒ Partial

Returns a new instance of Partial.



8
9
10
11
# File 'lib/style_guide/partial.rb', line 8

def initialize(path, section)
  @path = path
  @section = section
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/style_guide/partial.rb', line 6

def path
  @path
end

#sectionObject (readonly)

Returns the value of attribute section.



6
7
8
# File 'lib/style_guide/partial.rb', line 6

def section
  @section
end

Instance Method Details

#classesObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/style_guide/partial.rb', line 25

def classes
  @classes ||= begin
    parsed.css("[class]").reduce({}) do |output, tag|
      output.tap do |tags|
        tag["class"].split.each do |class_name|
          tags[".#{class_name}"] = true
        end
      end
    end.keys
  end
end

#descriptionObject



21
22
23
# File 'lib/style_guide/partial.rb', line 21

def description
  @description ||= GitHub::Markdown.render_gfm(translated_description)
end

#idObject



13
14
15
# File 'lib/style_guide/partial.rb', line 13

def id
  @id ||= title.downcase.gsub(/[^a-zA-Z0-9]+/, "_")
end

#identifiersObject



41
42
43
# File 'lib/style_guide/partial.rb', line 41

def identifiers
  ids + classes
end

#idsObject



37
38
39
# File 'lib/style_guide/partial.rb', line 37

def ids
  @ids ||= parsed.css("[id]").map { |tag| %(##{tag["id"]}) }
end

#renderObject



45
46
47
# File 'lib/style_guide/partial.rb', line 45

def render
  @render ||= action_view.render(:file => path)
end

#titleObject



17
18
19
# File 'lib/style_guide/partial.rb', line 17

def title
  @title ||= File.basename(path, File.extname(path)).titleize.strip
end