html_mockup 0.3.5 → 0.4.0
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/README.rdoc +5 -0
- data/lib/html_mockup/template.rb +17 -7
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -39,6 +39,11 @@ through standard instance methods. The example below would create the instance v
|
|
39
39
|
|
40
40
|
<!-- [START:partial_name?key=value] -->Text<!-- [STOP:partial_name] -->
|
41
41
|
|
42
|
+
=== Partials in subdirectories
|
43
|
+
|
44
|
+
The partials path can have it's own directory structure. You can create tags with slashes in them
|
45
|
+
to access partials in subdirectories.
|
46
|
+
|
42
47
|
|
43
48
|
=== Mockup commandline
|
44
49
|
|
data/lib/html_mockup/template.rb
CHANGED
@@ -27,7 +27,7 @@ module HtmlMockup
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def partial_files(path)
|
30
|
-
filter = "
|
30
|
+
filter = "**/*.part.{?h,h}tml"
|
31
31
|
files = []
|
32
32
|
Dir.chdir(Pathname.new(path)) do
|
33
33
|
files = Dir.glob(filter)
|
@@ -58,10 +58,13 @@ module HtmlMockup
|
|
58
58
|
|
59
59
|
# Renders the template and returns it as a string
|
60
60
|
#
|
61
|
+
# ==== Parameters
|
62
|
+
# env<Hash>:: An environment hash (mostly used in combination with Rack)
|
63
|
+
#
|
61
64
|
# ==== Returns
|
62
65
|
# String:: The rendered template
|
63
66
|
#--
|
64
|
-
def render
|
67
|
+
def render(env={})
|
65
68
|
out = ""
|
66
69
|
while (partial = self.parse_partial_tag!) do
|
67
70
|
tag,params,scanned = partial
|
@@ -70,7 +73,7 @@ module HtmlMockup
|
|
70
73
|
|
71
74
|
# scan until end of tag
|
72
75
|
current_content = self.scanner.scan_until(/<!-- \[STOP:#{tag}\] -->/)
|
73
|
-
out << (render_partial(tag,params) || current_content)
|
76
|
+
out << (render_partial(tag, params) || current_content)
|
74
77
|
end
|
75
78
|
out << scanner.rest
|
76
79
|
end
|
@@ -92,7 +95,7 @@ module HtmlMockup
|
|
92
95
|
begin_of_tag = self.scanner.scan_until(/<!-- \[START:/)
|
93
96
|
return nil unless begin_of_tag
|
94
97
|
scanned << begin_of_tag
|
95
|
-
scanned << tag = self.scanner.scan(/[a-z0-9_]+/)
|
98
|
+
scanned << tag = self.scanner.scan(/[a-z0-9_\/\-]+/)
|
96
99
|
if scanned_questionmark = self.scanner.scan(/\?/)
|
97
100
|
scanned << scanned_questionmark
|
98
101
|
scanned << raw_params = self.scanner.scan_until(/\] -->/)
|
@@ -107,21 +110,28 @@ module HtmlMockup
|
|
107
110
|
[tag,params,scanned]
|
108
111
|
end
|
109
112
|
|
110
|
-
|
113
|
+
# Actually renders the tag as ERB
|
114
|
+
def render_partial(tag, params, env = {})
|
111
115
|
unless self.available_partials[tag]
|
112
116
|
raise MissingPartial.new("Could not find partial '#{tag}' in partial path '#{@options[:partial_path]}'")
|
113
117
|
end
|
114
118
|
template = ERB.new(self.available_partials[tag])
|
115
|
-
context = TemplateContext.new(params)
|
119
|
+
context = TemplateContext.new(params, env)
|
116
120
|
"\n" + template.result(context.get_binding).rstrip + "\n<!-- [STOP:#{tag}] -->"
|
117
121
|
end
|
118
122
|
|
119
123
|
class TemplateContext
|
120
|
-
|
124
|
+
# Params will be set as instance variables
|
125
|
+
def initialize(params, env = {})
|
121
126
|
params.each do |k,v|
|
122
127
|
self.instance_variable_set("@#{k}",v)
|
123
128
|
end
|
129
|
+
|
130
|
+
@_env = env;
|
124
131
|
end
|
132
|
+
|
133
|
+
def env; @_env; end
|
134
|
+
|
125
135
|
def get_binding; binding(); end
|
126
136
|
end
|
127
137
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_mockup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-04-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70245084497540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.12.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70245084497540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack
|
27
|
-
requirement: &
|
27
|
+
requirement: &70245084496900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70245084496900
|
36
36
|
description:
|
37
37
|
email: flurin@digitpaint.nl
|
38
38
|
executables:
|