class StyleGuide::Section

Attributes

id[R]
path[R]

Public Class Methods

from_paths(paths) click to toggle source
# File lib/style_guide/section.rb, line 11
def self.from_paths(paths)
  [*paths].reduce({}) do |sections, path|
    id = id_from_path(path)
    section = sections[id] ||= []
    section << new("#{id}#{section.empty? ? '' : section.count}", path)
    sections
  end.values.flatten
end
id_from_path(path) click to toggle source
# File lib/style_guide/section.rb, line 7
def self.id_from_path(path)
  File.basename(path).downcase.gsub(/[^a-zA-Z0-9]/, " ").strip.gsub(/\s+/, "_")
end
new(id, path) click to toggle source
# File lib/style_guide/section.rb, line 20
def initialize(id, path)
  @id = id
  @path = path
end

Public Instance Methods

partials() click to toggle source
# File lib/style_guide/section.rb, line 29
def partials
  partial_paths.map { |path| StyleGuide::Partial.new(path, self) }.sort_by { |p| p.title }
end
title() click to toggle source
# File lib/style_guide/section.rb, line 25
def title
  @title ||= File.basename(path).titleize
end

Private Instance Methods

partial_paths() click to toggle source
# File lib/style_guide/section.rb, line 35
def partial_paths
  @partial_paths ||= Dir.glob(File.expand_path("_*", path))
end