staticmatic 0.3.0 → 0.7.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.
@@ -18,12 +18,20 @@ module StaticMatic
18
18
  'application.sass' => 'stylesheets',
19
19
  'index.haml' => 'pages'
20
20
  }
21
-
21
+
22
22
  def initialize(base_dir)
23
23
  @base_dir = base_dir
24
24
  @src_dir = "#{@base_dir}/src"
25
25
  @site_dir = "#{@base_dir}/site"
26
26
  @templates_dir = File.dirname(__FILE__) + '/templates'
27
+ @layout = "application"
28
+ @scope = Object.new
29
+ @scope.instance_variable_set("@base_dir", @base_dir)
30
+ end
31
+
32
+
33
+ def base_dir
34
+ @base_dir
27
35
  end
28
36
 
29
37
  def run(command)
@@ -89,20 +97,13 @@ module StaticMatic
89
97
  puts "created #{path}"
90
98
  end
91
99
 
92
- # Keeps track of the layout template to use when generating the site
93
- #
94
- def layout=(name)
95
- if name != @layout_name
96
- @layout_name = name
97
- end
98
- end
99
-
100
- def layout
101
- if !@layout_name
102
- @layout_name = "application"
100
+ def source_for_layout
101
+ layout_template = "#{@src_dir}/layouts/#{@layout}.haml"
102
+ if File.exists?(layout_template)
103
+ File.read(layout_template)
104
+ else
105
+ raise StaticMatic::Error.new("", layout_template, "Layout not found")
103
106
  end
104
-
105
- File.read("#{@src_dir}/layouts/#{@layout_name}.haml")
106
107
  end
107
108
 
108
109
  # Generate html from source file:
@@ -110,8 +111,15 @@ module StaticMatic
110
111
  def generate_html(source_file)
111
112
  full_file_path = "#{@src_dir}/pages/#{source_file}.haml"
112
113
  begin
113
- page = Haml::Engine.new(File.read(full_file_path), :locals => {:base_dir => @base_dir})
114
- page.render
114
+ page = Haml::Engine.new(File.read(full_file_path), :locals => {:base_dir => base_dir})
115
+ html = page.render(@scope)
116
+
117
+ # TODO: DRY this up
118
+ if @scope.instance_variable_get("@layout")
119
+ @layout = @scope.instance_variable_get("@layout")
120
+ end
121
+
122
+ html
115
123
  rescue Haml::Error => haml_error
116
124
  raise StaticMatic::Error.new(haml_error.haml_line, full_file_path, haml_error.message)
117
125
  end
@@ -119,16 +127,17 @@ module StaticMatic
119
127
 
120
128
  def generate_html_with_layout(source)
121
129
  begin
122
- Haml::Engine.new(layout, :locals => {:base_dir => @base_dir}).to_html { generate_html(source) }
130
+ generated_content = generate_html(source)
131
+ Haml::Engine.new(source_for_layout, :locals => {:base_dir => base_dir}).render(@scope) { generated_content }
123
132
  rescue StaticMatic::Error => staticmatic_error
124
133
  # Catch any errors from the actual template - otherwise the error will be assumed to be from the
125
134
  # layout
126
135
  raise staticmatic_error
127
136
  rescue Haml::Error => haml_error
128
- raise StaticMatic::Error.new(haml_error.haml_line, "Layout: #{@layout_name}", haml_error.message)
137
+ raise StaticMatic::Error.new(haml_error.haml_line, "Layout: #{@layout}", haml_error.message)
129
138
  end
130
139
  end
131
-
140
+
132
141
  def generate_css(source)
133
142
  full_file_path = "#{@src_dir}/stylesheets/#{source}.sass"
134
143
  begin
@@ -138,6 +147,7 @@ module StaticMatic
138
147
  raise StaticMatic::Error.new(sass_error.sass_line, full_file_path, sass_error.message)
139
148
  end
140
149
  end
150
+
141
151
 
142
152
  def template_exists?(name)
143
153
  File.exists?("#{@src_dir}/pages/#{name}.haml") || File.exists?("#{@src_dir}/stylesheets/#{name}.sass")
@@ -1,5 +1,6 @@
1
- module Haml
1
+ module StaticMatic
2
2
  module Helpers
3
+ self.extend self
3
4
 
4
5
  # Generates links to all stylesheets in the source directory
5
6
  def stylesheets
data/lib/staticmatic.rb CHANGED
@@ -2,6 +2,11 @@ require 'rubygems'
2
2
  require 'haml'
3
3
  require 'mongrel'
4
4
  require File.dirname(__FILE__) + '/staticmatic/helpers'
5
+
6
+ Haml::Helpers.class_eval("include StaticMatic::Helpers")
7
+
5
8
  require File.dirname(__FILE__) + '/staticmatic/error'
6
9
  require File.dirname(__FILE__) + '/staticmatic/base'
7
10
  require File.dirname(__FILE__) + '/staticmatic/server'
11
+
12
+
data/test/base_test.rb CHANGED
@@ -26,18 +26,18 @@ class StaticMaticBaseTest < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  end
29
-
30
- def test_should_set_layout_template
31
- @staticmatic.layout = "application"
32
- assert_match "StaticMatic - Test Site Template", @staticmatic.layout
33
- end
34
29
 
35
30
  def test_should_generate_html_with_layout
36
31
  content = @staticmatic.generate_html_with_layout("index")
37
- assert_match "StaticMatic - Test Site Template", content
32
+ assert_match "StaticMatic", content
38
33
  assert_match "This is some test content", content
39
34
  end
40
35
 
36
+ def test_should_generate_html_with_layout_assigned_in_template
37
+ content = @staticmatic.generate_html_with_layout("layout_test")
38
+ assert_match "Alternate Layout", content
39
+ end
40
+
41
41
  def test_should_generate_css
42
42
  content = @staticmatic.generate_css("application")
43
43
  end
data/test/helpers_test.rb CHANGED
@@ -2,11 +2,10 @@ require 'test/unit'
2
2
  require File.dirname(__FILE__) + '/../lib/staticmatic'
3
3
 
4
4
  class HelpersTest < Test::Unit::TestCase
5
- include Haml::Helpers
5
+ include StaticMatic::Helpers
6
6
 
7
- # Provide method in place of local variable for the helpers - don'tcha just love ruby?
8
- def base_dir
9
- File.dirname(__FILE__) + '/sandbox/test_site'
7
+ def setup
8
+ @base_dir = File.dirname(__FILE__) + '/sandbox/test_site'
10
9
  end
11
10
 
12
11
  def test_should_generate_stylesheet_links
@@ -38,7 +37,7 @@ class HelpersTest < Test::Unit::TestCase
38
37
  end
39
38
 
40
39
  def test_should_generate_js_links
41
- expected_output = %q{<script src="javascripts/test.js" language="javascript"></script>}
40
+ expected_output = %q{src="javascripts/test.js"}
42
41
  assert_match expected_output, javascripts('test')
43
42
  end
44
43
  end
@@ -0,0 +1,3 @@
1
+ %h1 Alternate Layout
2
+
3
+ = yield
@@ -1 +1,3 @@
1
- %h1 StaticMatic!
1
+ %h1 StaticMatic!
2
+
3
+ %p This is some test content
@@ -0,0 +1,2 @@
1
+ - @layout = "alternate_layout"
2
+ %p This is a layout test
data/test.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Blah
2
+ module Helpers
3
+ end
4
+ end
5
+
6
+ module MyBlah
7
+ module Helpers
8
+ self.extend self
9
+ def say(string)
10
+ puts "You said: #{string}"
11
+ end
12
+ end
13
+ end
14
+
15
+ Blah::Helpers.extend MyBlah::Helpers
16
+ Blah::Helpers.say("hello")
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: staticmatic
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-07-26 00:00:00 +01:00
6
+ version: 0.7.0
7
+ date: 2007-08-26 00:00:00 +01:00
8
8
  summary: Manage static sites using Haml & Sass
9
9
  require_paths:
10
10
  - lib
@@ -74,13 +74,16 @@ files:
74
74
  - test/sandbox/test_site/site/stylesheets/application.css
75
75
  - test/sandbox/test_site/src
76
76
  - test/sandbox/test_site/src/layouts
77
+ - test/sandbox/test_site/src/layouts/alternate_layout.haml
77
78
  - test/sandbox/test_site/src/layouts/application.haml
78
79
  - test/sandbox/test_site/src/pages
79
80
  - test/sandbox/test_site/src/pages/index.haml
81
+ - test/sandbox/test_site/src/pages/layout_test.haml
80
82
  - test/sandbox/test_site/src/stylesheets
81
83
  - test/sandbox/test_site/src/stylesheets/application.sass
82
84
  - test/sandbox/tmp
83
85
  - test/server_test.rb
86
+ - test.rb
84
87
  test_files:
85
88
  - test/base_test.rb
86
89
  - test/helpers_test.rb
@@ -105,3 +108,12 @@ dependencies:
105
108
  - !ruby/object:Gem::Version
106
109
  version: 0.0.0
107
110
  version:
111
+ - !ruby/object:Gem::Dependency
112
+ name: mongrel
113
+ version_requirement:
114
+ version_requirements: !ruby/object:Gem::Version::Requirement
115
+ requirements:
116
+ - - ">"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.0.0
119
+ version: