Sha256: 7af0052b03bc8caa8b6b98f2f1f8d616405bb2ab27d074d39749bb5104433b96
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
class Styleguide attr_reader :section_names, :styleguide def initialize @styleguide ||= Kss::Parser.new( Stylin::APP_CONFIG[:stylesheets_path] ) @section_names ||= styleguide.sections.map{|s| s[1].section}.sort end def find(conditions) section = conditions.delete(:section) section_group = conditions.delete(:section_group) if section_group.present? find_grouped_sections(section_group) elsif section.present? find_by_section(section) end end def build_section_hierarchy end def self.sluggify(section) numbers = section.split(' ')[0].split('.') strings = section.split(' ')[1..-1] "#{numbers.join('-')}-#{strings.join('-')}" end def self.desluggify(slug) slug_parts = slug.split('-') numbers = [] strings = [] slug_parts.each do |slug_part| if is_integer?(slug_part) numbers << slug_part else strings << slug_part end end "#{numbers.join('.')} #{strings.join(' ')}" end private def find_by_section(section) styleguide.section(section) end def find_grouped_sections(section_group) grouped_sections.select{|k,v| k.to_i == section_group}.values.flatten.map do |section_name| find_by_section(section_name) end end def grouped_sections @grouped_sections ||= section_names.group_by do |x| x.split('.')[0] end end def self.is_integer?(string) /\A[-+]?[0-9]+\Z/ === string end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stylin-0.1.0 | app/models/styleguide.rb |