staticmatic 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,5 @@
1
1
  module StaticMatic
2
2
  class Base
3
- VERSION = '0.2.0'
4
-
5
3
  # Directories generated for a new site setup
6
4
  @@base_dirs = %w{
7
5
  site/
@@ -110,17 +108,35 @@ module StaticMatic
110
108
  # Generate html from source file:
111
109
  # generate_html("index.haml")
112
110
  def generate_html(source_file)
113
- page = Haml::Engine.new(File.read("#{@src_dir}/pages/#{source_file}.haml"), :locals => {:base_dir => @base_dir})
114
- page.render
111
+ full_file_path = "#{@src_dir}/pages/#{source_file}.haml"
112
+ begin
113
+ page = Haml::Engine.new(File.read(full_file_path), :locals => {:base_dir => @base_dir})
114
+ page.render
115
+ rescue Haml::Error => haml_error
116
+ raise StaticMatic::Error.new(haml_error.haml_line, full_file_path, haml_error.message)
117
+ end
115
118
  end
116
119
 
117
120
  def generate_html_with_layout(source)
118
- Haml::Engine.new(layout, :locals => {:base_dir => @base_dir}).to_html { generate_html(source) }
121
+ begin
122
+ Haml::Engine.new(layout, :locals => {:base_dir => @base_dir}).to_html { generate_html(source) }
123
+ rescue StaticMatic::Error => staticmatic_error
124
+ # Catch any errors from the actual template - otherwise the error will be assumed to be from the
125
+ # layout
126
+ raise staticmatic_error
127
+ rescue Haml::Error => haml_error
128
+ raise StaticMatic::Error.new(haml_error.haml_line, "Layout: #{@layout_name}", haml_error.message)
129
+ end
119
130
  end
120
131
 
121
132
  def generate_css(source)
122
- stylesheet = Sass::Engine.new(File.read("#{@src_dir}/stylesheets/#{source}.sass"))
123
- stylesheet.to_css
133
+ full_file_path = "#{@src_dir}/stylesheets/#{source}.sass"
134
+ begin
135
+ stylesheet = Sass::Engine.new(File.read(full_file_path))
136
+ stylesheet.to_css
137
+ rescue Sass::Error => sass_error
138
+ raise StaticMatic::Error.new(sass_error.sass_line, full_file_path, sass_error.message)
139
+ end
124
140
  end
125
141
 
126
142
  def template_exists?(name)
@@ -0,0 +1,17 @@
1
+ module StaticMatic
2
+ class Error < StandardError
3
+ attr_reader :line
4
+
5
+ attr_reader :filename
6
+
7
+ def initialize(lineno, filename, message)
8
+ @line = lineno
9
+ @filename = filename
10
+ @message = message
11
+ end
12
+
13
+ def message
14
+ "#{@filename}, line #{@line}: #{@message}"
15
+ end
16
+ end
17
+ end
@@ -28,10 +28,14 @@ module StaticMatic
28
28
  output = ""
29
29
 
30
30
  if @staticmatic.template_exists?(file_name)
31
- if file_ext == "html"
32
- output = @staticmatic.generate_html_with_layout("#{file_name}")
33
- elsif file_ext == "css"
34
- output = @staticmatic.generate_css("#{file_name}")
31
+ begin
32
+ if file_ext == "html"
33
+ output = @staticmatic.generate_html_with_layout("#{file_name}")
34
+ elsif file_ext == "css"
35
+ output = @staticmatic.generate_css("#{file_name}")
36
+ end
37
+ rescue StaticMatic::Error => e
38
+ output = e.message
35
39
  end
36
40
  else
37
41
  output = "File not Found"
data/lib/staticmatic.rb CHANGED
@@ -2,5 +2,6 @@ require 'rubygems'
2
2
  require 'haml'
3
3
  require 'mongrel'
4
4
  require File.dirname(__FILE__) + '/staticmatic/helpers'
5
+ require File.dirname(__FILE__) + '/staticmatic/error'
5
6
  require File.dirname(__FILE__) + '/staticmatic/base'
6
- require File.dirname(__FILE__) + '/staticmatic/server'
7
+ require File.dirname(__FILE__) + '/staticmatic/server'
Binary file
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: staticmatic
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
6
+ version: 0.2.1
7
7
  date: 2007-06-10 00:00:00 +01:00
8
8
  summary: Manage static sites using Haml & Sass
9
9
  require_paths:
@@ -34,6 +34,7 @@ files:
34
34
  - lib
35
35
  - RakeFile
36
36
  - README
37
+ - staticmatic-0.2.0.gem
37
38
  - test
38
39
  - bin/staticmatic
39
40
  - example/site
@@ -54,6 +55,7 @@ files:
54
55
  - lib/staticmatic
55
56
  - lib/staticmatic.rb
56
57
  - lib/staticmatic/base.rb
58
+ - lib/staticmatic/error.rb
57
59
  - lib/staticmatic/helpers.rb
58
60
  - lib/staticmatic/server.rb
59
61
  - lib/staticmatic/templates