staticmatic 0.11.0.alpha.4 → 0.11.0.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml
CHANGED
data/lib/staticmatic/base.rb
CHANGED
@@ -24,10 +24,10 @@ module StaticMatic
|
|
24
24
|
@site_dir = File.join(@base_dir, "site")
|
25
25
|
|
26
26
|
if File.exists?(File.join(@src_dir, "layouts", "application.haml"))
|
27
|
-
puts "DEPRECATION: layouts/application.haml will be renamed to layouts/default.haml in
|
28
|
-
@
|
27
|
+
puts "DEPRECATION: layouts/application.haml will be renamed to layouts/default.haml in 0.12.0"
|
28
|
+
@default_layout = "application"
|
29
29
|
else
|
30
|
-
@
|
30
|
+
@default_layout = "default"
|
31
31
|
end
|
32
32
|
|
33
33
|
@scope = Object.new
|
@@ -53,7 +53,6 @@ module StaticMatic
|
|
53
53
|
|
54
54
|
# TODO: DRY this _exists? section up
|
55
55
|
def template_exists?(name, dir = '')
|
56
|
-
|
57
56
|
File.exists?(File.join(@src_dir, 'pages', dir, "#{name}.haml")) || File.exists?(File.join(@src_dir, 'stylesheets', "#{name}.sass")) || File.exists?(File.join(@src_dir, 'stylesheets', "#{name}.scss"))
|
58
57
|
end
|
59
58
|
|
@@ -1,10 +1,18 @@
|
|
1
1
|
module StaticMatic::RenderMixin
|
2
2
|
|
3
|
+
# clear all scope variables except @staticmatic
|
4
|
+
def clear_template_variables!
|
5
|
+
|
6
|
+
@scope.instance_variables.each do |var|
|
7
|
+
@scope.instance_variable_set(var, nil) unless var == '@staticmatic' || var == :@staticmatic
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
def source_for_layout
|
4
|
-
if layout_exists?(
|
5
|
-
File.read(full_layout_path(
|
12
|
+
if layout_exists?(determine_layout)
|
13
|
+
File.read(full_layout_path(determine_layout))
|
6
14
|
else
|
7
|
-
raise StaticMatic::Error.new("", full_layout_path(
|
15
|
+
raise StaticMatic::Error.new("", full_layout_path(determine_layout), "Layout not found")
|
8
16
|
end
|
9
17
|
end
|
10
18
|
|
@@ -14,13 +22,8 @@ module StaticMatic::RenderMixin
|
|
14
22
|
full_file_path = File.join(@src_dir, 'pages', source_dir, "#{source_file}.haml")
|
15
23
|
|
16
24
|
begin
|
17
|
-
|
18
|
-
@scope.instance_variables.each do |var|
|
19
|
-
@scope.instance_variable_set(var, nil) unless var == '@staticmatic' || var == :@staticmatic
|
20
|
-
end
|
25
|
+
|
21
26
|
html = generate_html_from_template_source(File.read(full_file_path))
|
22
|
-
|
23
|
-
@layout = determine_layout(source_dir)
|
24
27
|
rescue StaticMatic::TemplateError => e
|
25
28
|
raise e # re-raise inline errors
|
26
29
|
rescue Exception => e
|
@@ -35,11 +38,11 @@ module StaticMatic::RenderMixin
|
|
35
38
|
@current_file_stack.unshift(File.join(source_dir, "#{source}.haml"))
|
36
39
|
begin
|
37
40
|
template_content = generate_html(source, source_dir)
|
38
|
-
@layout = determine_layout(source_dir)
|
39
41
|
generate_html_from_template_source(source_for_layout) { template_content }
|
40
42
|
rescue Exception => e
|
41
43
|
render_rescue_from_error(e)
|
42
44
|
ensure
|
45
|
+
clear_template_variables!
|
43
46
|
@current_page = nil
|
44
47
|
@current_file_stack.shift
|
45
48
|
end
|
@@ -106,7 +109,7 @@ module StaticMatic::RenderMixin
|
|
106
109
|
end
|
107
110
|
|
108
111
|
def determine_layout(dir = '')
|
109
|
-
layout_name
|
112
|
+
layout_name ||= @default_layout
|
110
113
|
|
111
114
|
if @scope.instance_variable_get("@layout")
|
112
115
|
layout_name = @scope.instance_variable_get("@layout")
|
@@ -119,7 +122,7 @@ module StaticMatic::RenderMixin
|
|
119
122
|
end
|
120
123
|
end
|
121
124
|
|
122
|
-
layout_name
|
125
|
+
layout_name
|
123
126
|
end
|
124
127
|
|
125
128
|
# Returns a raw template name from a source file path:
|
data/spec/render_spec.rb
CHANGED
@@ -34,4 +34,11 @@ describe "StaticMatic::Render" do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
it "should clear template variables" do
|
38
|
+
@staticmatic.generate_html("page_one")
|
39
|
+
@staticmatic.clear_template_variables!
|
40
|
+
output = @staticmatic.generate_html("page_two")
|
41
|
+
output.should match(/The variable is/)
|
42
|
+
output.should_not match(/hello/)
|
43
|
+
end
|
37
44
|
end
|
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 11
|
8
8
|
- 0
|
9
9
|
- alpha
|
10
|
-
-
|
11
|
-
version: 0.11.0.alpha.
|
10
|
+
- 5
|
11
|
+
version: 0.11.0.alpha.5
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Stephen Bartholomew
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-05-24 00:00:00 +01:00
|
20
20
|
default_executable: staticmatic
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -125,6 +125,8 @@ files:
|
|
125
125
|
- spec/sandbox/test_site/src/pages/hello_world.erb
|
126
126
|
- spec/sandbox/test_site/src/pages/index.haml
|
127
127
|
- spec/sandbox/test_site/src/pages/layout_test.haml
|
128
|
+
- spec/sandbox/test_site/src/pages/page_one.haml
|
129
|
+
- spec/sandbox/test_site/src/pages/page_two.haml
|
128
130
|
- spec/sandbox/test_site/src/pages/page_with_error.haml
|
129
131
|
- spec/sandbox/test_site/src/pages/page_with_partial_error.haml
|
130
132
|
- spec/sandbox/test_site/src/partials/menu.haml
|