laydown 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/laydown.gemspec +1 -1
  3. data/lib/laydown.rb +45 -21
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.7.0
data/laydown.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{laydown}
8
- s.version = "0.6.2"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jbe"]
data/lib/laydown.rb CHANGED
@@ -9,43 +9,67 @@ module Laydown
9
9
 
10
10
  DEFAULTS = {
11
11
  :charset => 'utf-8',
12
- :title => nil,
12
+ :title => '#{@title}',
13
13
  :description => nil,
14
14
  :favicon => nil,
15
- :keywords => [],
16
- :css => [],
17
- :js => [],
18
- :inline_js => [],
15
+ :keywords => [:@keywords],
16
+ :css => [:@css, :@stylesheets],
17
+ :js => [:@javascripts, :@js],
18
+ :inline_js => [:@inline_js],
19
19
  :head => [],
20
20
  :body_class => [],
21
21
  :body => :yield,
22
22
  :ga_code => :@ga_code
23
23
  }
24
24
 
25
- ARRAY_PROPS = [:keywords, :css, :js, :inline_js, :head, :body_class]
25
+ class << self
26
26
 
27
- def self.compile(template={})
27
+ def properties
28
+ DEFAULTS.keys
29
+ end
28
30
 
29
- template = DEFAULTS.merge(template)
31
+ def plural_properties
32
+ properties.select {|name| DEFAULTS[name].is_a?(Array) }
33
+ end
30
34
 
31
- ARRAY_PROPS.each do |k|
32
- template[k] = Array(template[k]).flatten.compact
35
+ def compile(values={})
36
+ process(values)
37
+ validate(values)
38
+ make_template_from(values)
33
39
  end
34
40
 
35
- TEMPLATE.gsub(/data\[:([a-zA-Z0-9_]+)\]/) do |m|
36
- literalize template[:"#{$1}"]
41
+ def process(values)
42
+ DEFAULTS.each {|k,v| values[k] ||= v }
43
+ plural_properties.each do |k|
44
+ values[k] = Array(values[k]).flatten.compact
45
+ end
46
+ end
47
+
48
+ def validate(values)
49
+ values.keys.each do |value|
50
+ unless DEFAULTS.keys.include?(value)
51
+ raise "no Laydown property called #{value.inspect}"
52
+ end
53
+ end
54
+ end
55
+
56
+ def make_template_from(values)
57
+ TEMPLATE.gsub(/data\[:([a-zA-Z0-9_]+)\]/) do |m|
58
+ literalize values[:"#{$1}"]
59
+ end
37
60
  end
38
- end
39
61
 
40
- def self.literalize(obj)
41
- case obj
42
- when String then obj.inspect.gsub(/\\#\{/, '#{') + "+''"
43
- when Symbol then obj.to_s
44
- when nil then 'nil'
45
- when Array
46
- '[' + obj.map {|o| literalize(o) }.join(', ') + ']'
47
- else obj.to_s.inspect
62
+ def literalize(obj)
63
+ case obj
64
+ when String then obj.inspect.gsub(/\\#\{/, '#{') + "+''"
65
+ when Symbol then obj.to_s
66
+ when nil then 'nil'
67
+ when Array
68
+ '[' + obj.map {|o| literalize(o) }.join(', ') + ']'
69
+ else obj.to_s.inspect
70
+ end
48
71
  end
72
+
49
73
  end
50
74
 
51
75
  class Template < Tilt::Template
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 2
9
- version: 0.6.2
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jbe