Class: Undercase::Pattern
- Inherits:
-
Object
- Object
- Undercase::Pattern
- 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
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #category ⇒ Object
- #description ⇒ Object
- #display_code? ⇒ Boolean
- #highlighted_source ⇒ Object
-
#initialize(key) ⇒ Pattern
constructor
A new instance of Pattern.
- #name ⇒ Object
- #to_partial_path ⇒ Object
- #usage ⇒ Object
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/undercase/pattern.rb', line 12 def key @key end |
Class Method Details
.all ⇒ Object
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
#category ⇒ Object
35 36 37 |
# File 'lib/undercase/pattern.rb', line 35 def category .fetch('category') end |
#description ⇒ Object
31 32 33 |
# File 'lib/undercase/pattern.rb', line 31 def description .fetch('description') end |
#display_code? ⇒ Boolean
39 40 41 |
# File 'lib/undercase/pattern.rb', line 39 def display_code? .fetch('display', true) end |
#highlighted_source ⇒ Object
43 44 45 46 |
# File 'lib/undercase/pattern.rb', line 43 def highlighted_source source = File.read(File.("../../../app/views/undercase/patterns/_#@key.html.haml", __FILE__)) CodeRay.scan(source, :haml).div(:css => :class).html_safe end |
#name ⇒ Object
23 24 25 |
# File 'lib/undercase/pattern.rb', line 23 def name .fetch('name') end |
#to_partial_path ⇒ Object
19 20 21 |
# File 'lib/undercase/pattern.rb', line 19 def to_partial_path 'undercase/patterns/pattern' end |
#usage ⇒ Object
27 28 29 |
# File 'lib/undercase/pattern.rb', line 27 def usage .fetch('usage') end |