templette 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/templette/data_accessors.rb +55 -4
- data/lib/templette/engineer.rb +4 -0
- data/lib/templette/page.rb +2 -0
- metadata +2 -2
@@ -1,23 +1,68 @@
|
|
1
1
|
module Templette
|
2
2
|
module DataAccessors
|
3
|
-
def attributes
|
3
|
+
def attributes # :nodoc:
|
4
4
|
@attributes ||= {}
|
5
5
|
end
|
6
6
|
|
7
|
-
def generate_accessors(accessors = {})
|
7
|
+
def generate_accessors(accessors = {}) # :nodoc:
|
8
8
|
accessors.each_pair { |k,v| generate_accessor(k, v) }
|
9
9
|
end
|
10
10
|
|
11
|
-
def include_helpers(helpers)
|
11
|
+
def include_helpers(helpers) # :nodoc:
|
12
12
|
helpers.each { |helper| add_helper(helper) }
|
13
13
|
end
|
14
14
|
|
15
|
-
def method_missing(symbol)
|
15
|
+
def method_missing(symbol) # :nodoc:
|
16
16
|
raise PageError.new(page, "No method '#{symbol}' defined in the yaml")
|
17
17
|
end
|
18
|
+
|
19
|
+
def partial(filename) # :nodoc:
|
20
|
+
raise PageError.new(page, "Rendering #{filename} failed. File not found.") unless File.exists?(filename)
|
21
|
+
Engineer.engine_for(Engineer.determine_type(filename)).render(File.read(filename), page._binding)
|
22
|
+
rescue RenderError => e
|
23
|
+
raise PageError.new(page, e.message)
|
24
|
+
end
|
18
25
|
|
26
|
+
# Generates an image tag. Default options {:alt => filename }
|
27
|
+
#
|
28
|
+
# Ex.
|
29
|
+
# image_tag('ball.png', :alt => 'a red ball')
|
30
|
+
# => "<img src='/images/ball.png' alt='a red ball' />"
|
31
|
+
|
32
|
+
def image_tag(path, options = {})
|
33
|
+
options = {:alt => path}.merge(options)
|
34
|
+
"<img src='/images/#{path}' #{params_to_attributes(options)}/>"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates a link to a stylesheet. Default options {:type => 'text/css'}
|
38
|
+
#
|
39
|
+
# Ex.
|
40
|
+
# stylesheet_tag('print', :media => 'print')
|
41
|
+
# => "<link href='/stylesheets/print.css' media='print' type='text/css' />"
|
42
|
+
|
43
|
+
def stylesheet_tag(path, options = {})
|
44
|
+
options = {:type => 'text/css'}.merge(options)
|
45
|
+
"<link href='/stylesheets/#{path}.css' #{params_to_attributes(options)}/>"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Genrates a javascript scrip tag.
|
49
|
+
#
|
50
|
+
# Ex.
|
51
|
+
# script_tag('slider')
|
52
|
+
# => <script src='/javascripts/slider.js' type='text/javascript'></script>
|
53
|
+
|
54
|
+
def script_tag(path)
|
55
|
+
"<script src='/javascripts/#{path}.js' type='text/javascript'></script>"
|
56
|
+
end
|
57
|
+
|
19
58
|
private
|
20
59
|
|
60
|
+
def params_to_attributes(options)
|
61
|
+
options.inject('') do |str, h|
|
62
|
+
str << "#{h[0]}='#{h[1]}' "
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
21
66
|
def generate_accessor(k, v)
|
22
67
|
raise TempletteError.new(page, "Method already defined: #{k}. Change your config file and stop using it!") if self.methods.include?(k.to_s)
|
23
68
|
if v.kind_of?(Hash)
|
@@ -27,6 +72,12 @@ module Templette
|
|
27
72
|
v = File.open($1) {|f| f.read}
|
28
73
|
elsif v.nil?
|
29
74
|
v = Page::Section.new(page, {})
|
75
|
+
elsif v =~/render[:\ ](.*)/
|
76
|
+
instance_eval "
|
77
|
+
def #{k.to_s}
|
78
|
+
partial '#{$1.strip}'
|
79
|
+
end"
|
80
|
+
return
|
30
81
|
end
|
31
82
|
attributes[k.to_s] = v
|
32
83
|
instance_eval "def #{k.to_s}; attributes['#{k.to_s}']; end"
|
data/lib/templette/engineer.rb
CHANGED
data/lib/templette/page.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: templette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Dunphy and Steve Holder
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-14 00:00:00 -08:00
|
13
13
|
default_executable: templette
|
14
14
|
dependencies: []
|
15
15
|
|