class Undercase::Pattern

Constants

HAML_PATH
PATTERNS
SCSS_FILE
SCSS_PATH
YAML_PATH

Attributes

key[R]

Public Class Methods

new(key) click to toggle source
# File lib/undercase/pattern.rb, line 14
def initialize(key)
  @key = key
  @metadata = YAML.load_file(yaml_path)
end

Private Class Methods

all() click to toggle source
# File lib/undercase/pattern.rb, line 55
def all
  directory = File.dirname(__FILE__)
  Dir["#{directory}/patterns/*.yml"].map do |d|
    filename_as_symbol = File.basename(d).sub(/\.yml/, '').to_sym
    Pattern.new(filename_as_symbol)
  end
end
for_category(category) click to toggle source
# File lib/undercase/pattern.rb, line 63
def for_category(category)
  Pattern.all.select { |pattern| pattern.category == category }
end

Public Instance Methods

category() click to toggle source
# File lib/undercase/pattern.rb, line 35
def category
  @metadata.fetch('category')
end
description() click to toggle source
# File lib/undercase/pattern.rb, line 31
def description
  @metadata.fetch('description')
end
display_code?() click to toggle source
# File lib/undercase/pattern.rb, line 39
def display_code?
  @metadata.fetch('display', true)
end
highlighted_source() click to toggle source
# File lib/undercase/pattern.rb, line 43
def highlighted_source
  source = File.read(File.expand_path("../../../app/views/undercase/patterns/_#@key.html.haml", __FILE__))
  CodeRay.scan(source, :haml).div(:css => :class).html_safe
end
name() click to toggle source
# File lib/undercase/pattern.rb, line 23
def name
  @metadata.fetch('name')
end
to_partial_path() click to toggle source
# File lib/undercase/pattern.rb, line 19
def to_partial_path
  'undercase/patterns/pattern'
end
usage() click to toggle source
# File lib/undercase/pattern.rb, line 27
def usage
  @metadata.fetch('usage')
end

Private Instance Methods

yaml_path() click to toggle source
# File lib/undercase/pattern.rb, line 50
def yaml_path
  File.expand_path("../patterns/#{key}.yml", __FILE__)
end