Class: Undercase::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/undercase/pattern.rb

Constant Summary collapse

PATTERNS =
Array.new
SCSS_FILE =
'app/assets/stylesheets/undercase/_patterns.scss'
YAML_PATH =
'lib/undercase/patterns/'
SCSS_PATH =
'app/assets/stylesheets/undercase/patterns/'
HAML_PATH =
'app/views/undercase/patterns/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Pattern

Returns a new instance of Pattern.



14
15
16
17
# File 'lib/undercase/pattern.rb', line 14

def initialize(key)
  @key = key
   = YAML.load_file(yaml_path)
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



12
13
14
# File 'lib/undercase/pattern.rb', line 12

def key
  @key
end

Class Method Details

.allObject



55
56
57
58
59
60
61
# 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) ⇒ Object



63
64
65
# File 'lib/undercase/pattern.rb', line 63

def for_category(category)
  Pattern.all.select { |pattern| pattern.category == category }
end

Instance Method Details

#categoryObject



35
36
37
# File 'lib/undercase/pattern.rb', line 35

def category
  .fetch('category')
end

#descriptionObject



31
32
33
# File 'lib/undercase/pattern.rb', line 31

def description
  .fetch('description')
end

#display_code?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/undercase/pattern.rb', line 39

def display_code?
  .fetch('display', true)
end

#highlighted_sourceObject



43
44
45
46
# 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

#nameObject



23
24
25
# File 'lib/undercase/pattern.rb', line 23

def name
  .fetch('name')
end

#to_partial_pathObject



19
20
21
# File 'lib/undercase/pattern.rb', line 19

def to_partial_path
  'undercase/patterns/pattern'
end

#usageObject



27
28
29
# File 'lib/undercase/pattern.rb', line 27

def usage
  .fetch('usage')
end