staticmatic 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +24 -0
  3. data/README.rdoc +48 -0
  4. data/Rakefile +22 -27
  5. data/bin/staticmatic +0 -0
  6. data/lib/staticmatic.rb +12 -4
  7. data/lib/staticmatic/base.rb +30 -242
  8. data/lib/staticmatic/mixins/build.rb +46 -0
  9. data/lib/staticmatic/mixins/helpers.rb +15 -0
  10. data/lib/staticmatic/mixins/render.rb +125 -0
  11. data/lib/staticmatic/mixins/rescue.rb +12 -0
  12. data/lib/staticmatic/mixins/server.rb +6 -0
  13. data/lib/staticmatic/mixins/setup.rb +20 -0
  14. data/lib/staticmatic/template_error.rb +40 -0
  15. data/lib/staticmatic/templates/{application.haml → default/application.haml} +0 -0
  16. data/lib/staticmatic/templates/{application.sass → default/application.sass} +0 -0
  17. data/lib/staticmatic/templates/{index.haml → default/index.haml} +0 -0
  18. data/lib/staticmatic/templates/rescues/default.haml +7 -0
  19. data/lib/staticmatic/templates/rescues/template.haml +18 -0
  20. data/test/test_helper.rb +20 -48
  21. metadata +55 -124
  22. data/CHANGELOG +0 -57
  23. data/LICENSE +0 -21
  24. data/README +0 -56
  25. data/example/site/contact.html +0 -17
  26. data/example/site/index.html +0 -16
  27. data/example/site/javascripts/application.css +0 -2
  28. data/example/src/layouts/application.haml +0 -11
  29. data/example/src/pages/contact.haml +0 -3
  30. data/example/src/pages/index.haml +0 -3
  31. data/example/src/pages/test test/blah.haml +0 -1
  32. data/example/src/stylesheets/application.sass +0 -4
  33. data/lib/staticmatic/version.rb +0 -34
  34. data/test/base_test.rb +0 -60
  35. data/test/helpers_test.rb +0 -296
  36. data/test/sandbox/test_site/configuration.rb +0 -0
  37. data/test/sandbox/test_site/site/index.html +0 -10
  38. data/test/sandbox/test_site/site/stylesheets/application.css +0 -2
  39. data/test/sandbox/test_site/src/helpers/application_helper.rb +0 -5
  40. data/test/sandbox/test_site/src/layouts/alternate_layout.haml +0 -3
  41. data/test/sandbox/test_site/src/layouts/application.haml +0 -7
  42. data/test/sandbox/test_site/src/layouts/projects.haml +0 -1
  43. data/test/sandbox/test_site/src/pages/index.haml +0 -5
  44. data/test/sandbox/test_site/src/pages/layout_test.haml +0 -2
  45. data/test/sandbox/test_site/src/partials/menu.haml +0 -1
  46. data/test/sandbox/test_site/src/stylesheets/application.sass +0 -2
  47. data/test/server_test.rb +0 -12
  48. data/test/test_helper_test.rb +0 -49
  49. data/test/version_test.rb +0 -28
  50. data/website/site/download.html +0 -84
  51. data/website/site/faq.html +0 -101
  52. data/website/site/helper_central/index.html +0 -144
  53. data/website/site/how_to_use.html +0 -307
  54. data/website/site/images/bycurve21.gif +0 -0
  55. data/website/site/images/curve21.jpg +0 -0
  56. data/website/site/images/homepage-build.jpg +0 -0
  57. data/website/site/images/homepage-previewing.jpg +0 -0
  58. data/website/site/images/homepage-templating.jpg +0 -0
  59. data/website/site/index.html +0 -98
  60. data/website/site/releases/0_8_10.html +0 -106
  61. data/website/site/releases/0_8_4.html +0 -101
  62. data/website/site/releases/0_8_8.html +0 -96
  63. data/website/site/releases/0_9_0.html +0 -124
  64. data/website/site/stylesheets/application.css +0 -287
  65. data/website/src/helpers/application_helper.rb +0 -5
  66. data/website/src/layouts/application.haml +0 -43
  67. data/website/src/layouts/test.haml +0 -4
  68. data/website/src/pages/_qa.haml +0 -2
  69. data/website/src/pages/download.haml +0 -15
  70. data/website/src/pages/faq.haml +0 -8
  71. data/website/src/pages/helper_central/_helper.haml +0 -7
  72. data/website/src/pages/helper_central/index.haml +0 -21
  73. data/website/src/pages/how_to_use.haml +0 -270
  74. data/website/src/pages/index.haml +0 -27
  75. data/website/src/pages/releases/0_8_10.haml +0 -22
  76. data/website/src/pages/releases/0_8_4.haml +0 -25
  77. data/website/src/pages/releases/0_8_8.haml +0 -35
  78. data/website/src/pages/releases/0_9_0.haml +0 -34
  79. data/website/src/partials/news.haml +0 -10
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ == 0.10.0 2009-01-01
2
+
3
+ * Refactoring for forthcoming improvements
4
+ * Improved Error Reporting
5
+ * More useful error pages
6
+ * Removed Haml specific error handling
data/Manifest.txt ADDED
@@ -0,0 +1,24 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/staticmatic
6
+ lib/staticmatic.rb
7
+ lib/staticmatic/base.rb
8
+ lib/staticmatic/configuration.rb
9
+ lib/staticmatic/error.rb
10
+ lib/staticmatic/helpers.rb
11
+ lib/staticmatic/mixins/build.rb
12
+ lib/staticmatic/mixins/helpers.rb
13
+ lib/staticmatic/mixins/render.rb
14
+ lib/staticmatic/mixins/server.rb
15
+ lib/staticmatic/mixins/setup.rb
16
+ lib/staticmatic/server.rb
17
+ lib/staticmatic/templates/default/application.haml
18
+ lib/staticmatic/templates/default/application.sass
19
+ lib/staticmatic/templates/default/index.haml
20
+ lib/staticmatic/templates/default/index.haml
21
+ lib/staticmatic/templates/rescues/default.haml
22
+ lib/staticmatic/templates/rescues/template.haml
23
+ lib/staticmatic/template_error.rb
24
+ lib/staticmatic/mixins/rescue.rb
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = staticmatic-core
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIXME full name
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,33 +1,28 @@
1
- require 'rubygems'
2
- require 'rake/testtask'
3
- require 'rake/clean'
4
- Gem::manage_gems
5
- require 'rake/gempackagetask'
6
- require File.join(File.dirname(__FILE__), 'lib/staticmatic/version')
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/staticmatic'
7
3
 
8
- task :default => [:package]
9
-
10
- spec = Gem::Specification.new do |s|
11
- s.name = "staticmatic"
12
- s.rubyforge_project = "staticmatic"
13
- s.version = StaticMatic::VERSION::STRING
14
- s.author = "Stephen Bartholomew"
15
- s.email = "steve@curve21.com"
16
- s.authors << "Brent Beardsley (brentbeardsley@gmail.com)"
17
- s.homepage = "http//staticmatic.rubyforge.org"
18
- s.summary = "Manage static sites using Haml & Sass"
19
- files = FileList["**/**/**"]
20
- files.exclude 'pkg'
21
- files.exclude 'contrib'
22
- s.files = files.to_a
23
- s.test_files = Dir.glob("test/*_test.rb")
24
- s.add_dependency("haml", ">=2.0.0")
25
- s.add_dependency("mongrel")
26
- s.executables=['staticmatic']
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('staticmatic', StaticMatic::VERSION) do |p|
7
+ p.developer('Stephen Bartholomew', 'steve@curve21.com')
8
+ p.rubyforge_name = p.name
9
+ p.extra_deps = [
10
+ ['haml','>= 2.0'],
11
+ ['mongrel','>= 1.0']
12
+ ]
13
+ p.extra_dev_deps = [
14
+ ['newgem', ">= #{::Newgem::VERSION}"]
15
+ ]
16
+
17
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
18
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
19
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
20
+ p.rsync_args = '-av --delete --ignore-errors'
27
21
  end
28
22
 
29
- Rake::GemPackageTask.new(spec) do |pkg|
30
- end
23
+ require 'newgem/tasks' # load /tasks/*.rake
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
31
26
 
32
27
  desc "Run all unit tests"
33
28
  Rake::TestTask.new(:test) do |t|
data/bin/staticmatic CHANGED
File without changes
data/lib/staticmatic.rb CHANGED
@@ -2,11 +2,19 @@ require 'rubygems'
2
2
  require 'haml'
3
3
  require 'sass'
4
4
  require 'mongrel'
5
- require File.dirname(__FILE__) + '/staticmatic/helpers'
5
+ require 'fileutils'
6
6
 
7
- Haml::Helpers.class_eval("include StaticMatic::Helpers")
7
+ module StaticMatic
8
+ VERSION = '0.10.0'
9
+ end
10
+
11
+ ["render", "build", "setup", "server", "helpers", "rescue"].each do |mixin|
12
+ require File.join(File.dirname(__FILE__), "staticmatic", "mixins", mixin)
13
+ end
8
14
 
9
- %w(version configuration error base server).each do |file|
10
- require File.join(File.dirname(__FILE__), 'staticmatic', file)
15
+ ["base", "configuration", "error", "server", "helpers", "template_error"].each do |lib|
16
+ require File.join(File.dirname(__FILE__), "staticmatic", lib)
11
17
  end
12
18
 
19
+ Haml::Helpers.class_eval("include StaticMatic::Helpers")
20
+
@@ -1,33 +1,38 @@
1
- require 'fileutils'
2
-
3
1
  module StaticMatic
4
- class Base
5
- # Directories generated for a new site setup
6
- @@base_dirs = %w{
7
- site/
8
- site/stylesheets
9
- site/images
10
- site/javascripts
11
- src/
12
- src/pages/
13
- src/layouts
14
- src/stylesheets
15
- src/partials
16
- src/helpers
17
- }
2
+ # Directories generated for a new site setup
3
+ BASE_DIRS = %w{
4
+ site/
5
+ site/stylesheets
6
+ site/images
7
+ site/javascripts
8
+ src/
9
+ src/pages/
10
+ src/layouts
11
+ src/stylesheets
12
+ src/helpers
13
+ }
14
+
15
+ # Templates for setup and their location
16
+ TEMPLATES = {
17
+ 'application.haml' => 'layouts',
18
+ 'application.sass' => 'stylesheets',
19
+ 'index.haml' => 'pages'
20
+ }
18
21
 
19
- # Templates for setup and their location
20
- @@templates = {
21
- 'application.haml' => 'layouts',
22
- 'application.sass' => 'stylesheets',
23
- 'index.haml' => 'pages'
24
- }
22
+ class Base
25
23
 
24
+ include StaticMatic::RenderMixin
25
+ include StaticMatic::BuildMixin
26
+ include StaticMatic::SetupMixin
27
+ include StaticMatic::HelpersMixin
28
+ include StaticMatic::ServerMixin
29
+ include StaticMatic::RescueMixin
30
+
26
31
  attr_accessor :configuration
27
32
  attr_reader :current_page, :src_dir, :site_dir
28
33
 
29
34
  def current_file
30
- @current_file_stack[0]
35
+ @current_file_stack[0] || ""
31
36
  end
32
37
 
33
38
  def initialize(base_dir, configuration = Configuration.new)
@@ -37,7 +42,7 @@ module StaticMatic
37
42
  @base_dir = base_dir
38
43
  @src_dir = "#{@base_dir}/src"
39
44
  @site_dir = "#{@base_dir}/site"
40
- @templates_dir = File.dirname(__FILE__) + '/templates'
45
+ @templates_dir = File.dirname(__FILE__) + '/templates/default/'
41
46
  @layout = "application"
42
47
  @scope = Object.new
43
48
  @scope.instance_variable_set("@staticmatic", self)
@@ -55,185 +60,7 @@ module StaticMatic
55
60
  puts "#{command} is not a valid StaticMatic command"
56
61
  end
57
62
  end
58
-
59
- def build
60
- build_css
61
- build_html
62
- end
63
-
64
- def setup
65
- Dir.mkdir(@base_dir) unless File.exists?(@base_dir)
66
-
67
- @@base_dirs.each do |directory|
68
- directory = "#{@base_dir}/#{directory}"
69
- if !File.exists?(directory)
70
- Dir.mkdir(directory)
71
- puts "created #{directory}"
72
- end
73
- end
74
-
75
- @@templates.each do |template, destination|
76
- copy_file("#{@templates_dir}/#{template}", "#{@src_dir}/#{destination}")
77
- end
78
-
79
- puts "Done"
80
- end
81
-
82
- def preview
83
- puts "StaticMatic Preview Server Starting..."
84
- StaticMatic::Server.start(self)
85
- end
86
-
87
- def copy_file(from, to)
88
- FileUtils.cp(from, to)
89
- end
90
-
91
- def save_page(filename, content)
92
- generate_site_file(filename, 'html', content)
93
- end
94
-
95
- def save_stylesheet(filename, content)
96
- generate_site_file(File.join('stylesheets', filename), 'css', content)
97
- end
98
-
99
- def generate_site_file(filename, extension, content)
100
- path = File.join(@site_dir,"#{filename}.#{extension}")
101
- FileUtils.mkdir_p(File.dirname(path))
102
- File.open(path, 'w+') do |f|
103
- f << content
104
- end
105
-
106
- puts "created #{path}"
107
- end
108
-
109
- def source_for_layout
110
- if layout_exists?(@layout)
111
- File.read(full_layout_path(@layout))
112
- else
113
- raise StaticMatic::Error.new("", full_layout_path(@layout), "Layout not found")
114
- end
115
- end
116
-
117
- # Generate html from source file:
118
- # generate_html("index.haml")
119
- def generate_html(source_file, source_dir = '')
120
- full_file_path = File.join(@src_dir, 'pages', source_dir, "#{source_file}.haml")
121
-
122
- begin
123
- # clear all scope variables except @staticmatic
124
- @scope.instance_variables.each do |var|
125
- @scope.instance_variable_set(var, nil) unless var == '@staticmatic'
126
- end
127
- html = generate_html_from_template_source(File.read(full_file_path))
128
63
 
129
- @layout = detirmine_layout(source_dir)
130
- rescue StaticMatic::Error => staticmatic_error
131
- # Catch any errors from the actual template - otherwise the error will be assumed to be from the
132
- # layout
133
- raise staticmatic_error
134
- rescue Haml::Error => haml_error
135
- raise StaticMatic::Error.new(haml_error.line, "#{source_dir}/#{source_file}", haml_error.message)
136
- end
137
-
138
- #
139
- # # TODO: DRY this up
140
- # if @scope.instance_variable_get("@layout")
141
- # @layout = @scope.instance_variable_get("@layout")
142
- # end
143
- #
144
- html
145
- end
146
-
147
- def generate_html_with_layout(source, source_dir = '')
148
- @current_page = File.join(source_dir, "#{source}.html")
149
- @current_file_stack.unshift(File.join(source_dir, "#{source}.haml"))
150
-
151
- template_content = generate_html(source, source_dir)
152
- @layout = detirmine_layout(source_dir)
153
-
154
- begin
155
- generate_html_from_template_source(source_for_layout) { template_content }
156
- rescue StaticMatic::Error => staticmatic_error
157
- # Catch any errors from the actual template - otherwise the error will be assumed to be from the
158
- # layout
159
- raise staticmatic_error
160
- rescue Haml::Error => haml_error
161
- raise StaticMatic::Error.new("", "Layout: #{source_dir}/#{@layout}", haml_error.message)
162
- ensure
163
- @current_page = nil
164
- @current_file_stack.shift
165
- end
166
- end
167
-
168
- def generate_partial(name, options = {})
169
- partial_dir, partial_name = File.dirname(self.current_file), name # default relative to current file
170
- partial_dir, partial_name = File.split(name) if name.index('/') # contains a path so it's absolute from src/pages dir
171
- partial_name = "_#{partial_name}.haml"
172
-
173
- partial_path = File.join(@src_dir, 'pages', partial_dir, partial_name)
174
- unless File.exists?(partial_path)
175
- # couldn't find it in the pages subdirectory tree so try old way (ignoring the path)
176
- partial_dir = 'partials'; partial_name = "#{File.basename(name)}.haml"
177
- partial_path = File.join(@src_dir, partial_dir, partial_name)
178
- end
179
-
180
- if File.exists?(partial_path)
181
- partial_rel_path = "/#{partial_dir}/#{partial_name}".gsub(/\/+/, '/')
182
- @current_file_stack.unshift(partial_rel_path)
183
- begin
184
- generate_html_from_template_source(File.read(partial_path), options)
185
- rescue Haml::Error => haml_error
186
- raise StaticMatic::Error.new(haml_error.line, "Partial: #{partial_rel_path[0,partial_rel_path.length-5]}", haml_error.message)
187
- ensure
188
- @current_file_stack.shift
189
- end
190
- else
191
- raise StaticMatic::Error.new("", name, "Partial not found")
192
- end
193
- end
194
-
195
- def generate_css(source, source_dir = '')
196
- full_file_path = File.join(@src_dir, 'stylesheets', source_dir, "#{source}.sass")
197
- begin
198
- sass_options = { :load_paths => [ File.join(@src_dir, 'stylesheets') ] }.merge(self.configuration.sass_options)
199
- stylesheet = Sass::Engine.new(File.read(full_file_path), sass_options)
200
- stylesheet.to_css
201
- rescue Sass::SyntaxError => sass_error
202
- raise StaticMatic::Error.new(sass_error.sass_line, full_file_path, sass_error.message)
203
- end
204
- end
205
-
206
- # Generates html from the passed source string
207
- #
208
- # generate_html_from_template_source("%h1 Welcome to My Site") -> "<h1>Welcome to My Site</h1>"
209
- #
210
- # Pass a block containing a string to yield within in the passed source:
211
- #
212
- # generate_html_from_template_source("content:\n= yield") { "blah" } -> "content: blah"
213
- #
214
- def generate_html_from_template_source(source, options = {})
215
- html = Haml::Engine.new(source, options)
216
-
217
- html.render(@scope) { yield }
218
- end
219
-
220
- def detirmine_layout(dir = '')
221
- layout_name = "application"
222
-
223
- if @scope.instance_variable_get("@layout")
224
- layout_name = @scope.instance_variable_get("@layout")
225
- elsif dir
226
- dirs = dir.split("/")
227
- dir_layout_name = dirs[1]
228
-
229
- if layout_exists?(dir_layout_name)
230
- layout_name = dir_layout_name
231
- end
232
- end
233
-
234
- layout_name
235
- end
236
-
237
64
  # TODO: DRY this _exists? section up
238
65
  def template_exists?(name, dir = '')
239
66
  File.exists?(File.join(@src_dir, 'pages', dir, "#{name}.haml")) || File.exists?(File.join(@src_dir, 'stylesheets', "#{name}.sass"))
@@ -251,48 +78,9 @@ module StaticMatic
251
78
  "#{@src_dir}/layouts/#{name}.haml"
252
79
  end
253
80
 
254
- # Build HTML from the source files
255
- def build_html
256
- Dir["#{@src_dir}/pages/**/*.haml"].each do |path|
257
- next if File.basename(path) =~ /^\_/ # skip partials
258
- file_dir, template = source_template_from_path(path.sub(/^#{@src_dir}\/pages/, ''))
259
- save_page(File.join(file_dir, template), generate_html_with_layout(template, file_dir))
260
- end
261
- end
262
-
263
- # Build CSS from the source files
264
- def build_css
265
- Dir["#{@src_dir}/stylesheets/**/*.sass"].each do |path|
266
- file_dir, template = source_template_from_path(path.sub(/^#{@src_dir}\/stylesheets/, ''))
267
- save_stylesheet(File.join(file_dir, template), generate_css(template, file_dir))
268
- end
269
- end
270
-
271
- # Returns a raw template name from a source file path:
272
- # source_template_from_path("/path/to/site/src/stylesheets/application.sass") -> "application"
273
- def source_template_from_path(path)
274
- file_dir, file_name = File.split(path)
275
- file_name.chomp!(File.extname(file_name))
276
- [ file_dir, file_name ]
277
- end
278
-
279
- # Loads any helpers present in the helpers dir and mixes them into the template helpers
280
- def load_helpers
281
-
282
- Dir["#{@src_dir}/helpers/**/*_helper.rb"].each do |helper|
283
- load_helper(helper)
284
- end
285
- end
286
-
287
- def load_helper(helper)
288
- load helper
289
- module_name = File.basename(helper, '.rb').gsub(/(^|\_)./) { |c| c.upcase }.gsub(/\_/, '')
290
- Haml::Helpers.class_eval("include #{module_name}")
291
- end
292
-
293
81
  class << self
294
82
  def base_dirs
295
- @@base_dirs
83
+ StaticMatic::BASE_DIRS
296
84
  end
297
85
  end
298
86
  end