laydown 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/laydown.gemspec +1 -1
- data/lib/laydown.rb +45 -21
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/laydown.gemspec
CHANGED
data/lib/laydown.rb
CHANGED
@@ -9,43 +9,67 @@ module Laydown
|
|
9
9
|
|
10
10
|
DEFAULTS = {
|
11
11
|
:charset => 'utf-8',
|
12
|
-
:title =>
|
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
|
-
|
25
|
+
class << self
|
26
26
|
|
27
|
-
|
27
|
+
def properties
|
28
|
+
DEFAULTS.keys
|
29
|
+
end
|
28
30
|
|
29
|
-
|
31
|
+
def plural_properties
|
32
|
+
properties.select {|name| DEFAULTS[name].is_a?(Array) }
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
def compile(values={})
|
36
|
+
process(values)
|
37
|
+
validate(values)
|
38
|
+
make_template_from(values)
|
33
39
|
end
|
34
40
|
|
35
|
-
|
36
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|