staticmatic 0.8.10 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ *SVN*
2
+
3
+ *0.9.0* (October 16th, 2007)
4
+
5
+ * [NEW] added StaticMatic::VERSION.requirements_met? [Brent Beardsley]
6
+
7
+ * [NEW] added LICENSE and CHANGELOG files [Brent Beardsley]
8
+
9
+ * [NEW] can now specify relative paths when only specifying a title - link("../How to download") [Brent Beardsley]
10
+
11
+ * [NEW] add src_dir/stylesheets directory to sass load path so you can use @import styles.sass [Brent Beardsley]
12
+
13
+ * [NEW] added sass_options hash to configuration so you can configure sass (ie: :style => :compact) [Brent Beardsley]
14
+
15
+ * [NEW] added configuration.use_extensions_for_page_links (defaults to true) when false will strip index.html and .html off the end of links for pretty urls [Brent Beardsley]
16
+
17
+ * [NEW] made all "local" links (pages/stylesheets/images) relative to the current page and removed use_relative_path_for_* configuration settings [Brent Beardsley]
18
+
19
+ * [FIX] no longer add \n after the tag in the tag helper [Brent Beardsley]
20
+
21
+ * [FIX] mailto: links were getting a / inserted at in front of the mailto: [Brent Beardsley]
22
+
23
+ * [NEW] stylesheets helper can now take a list of stylesheets to include and the order as well as options (ie: :media => :print) [Brent Beardsley]
24
+
25
+ * [FIX] clear all instance variables in @scope except @staticmatic [Brent Beardsley]
26
+
27
+ * [NEW] added clean and clobber tasks to Rakefile [Brent Beardsley]
28
+
29
+ * [NEW] added StaticMatic::VERSION in version.rb [Brent Beardsley]
30
+
31
+ * [NEW] added package task to Rakefile and made it the default [Brent Beardsley]
32
+
33
+ *0.8.10* (October 12th, 2007)
34
+
35
+ * [NEW] rails-like partials. Partials can start with an underscore and live in the pages directory tree, old way still works [Brent Beardsley]
36
+
37
+ * [NEW] img helper changes and tests [Jason Tennier]
38
+
39
+ * [NEW] added current_page helper for use in other helpers, layouts, or pages [Brent Beardsley]
40
+
41
+ * [NEW] add src_dir, site_dir, and current_page attr_reader's on staticmatic class [Brent Beardsley]
42
+
43
+ * [FIX] removed dependency on rails needing to be installed [Brent Beardsley]
44
+
45
+ * [FIX] fixed preview bug where setting a layout in a page would cause it to be used even for pages that did not have a layout specified and should be using the default [Brent Beardsley]
46
+
47
+ * [FIX] tag helper only outputs the attribute if it has a value [Brent Beardsley]
48
+
49
+ * [FIX] renamed RakeFile to Rakefile so it'll work on non-windows boxes [Brent Beardsley]
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (C) 2007 Stephen Bartholomew
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README CHANGED
@@ -32,10 +32,12 @@ After this command you'll have the following files:
32
32
  stylesheets/
33
33
  javascripts/
34
34
  src/
35
- pages/
36
- index.haml
35
+ helpers/
37
36
  layouts/
38
37
  application.haml
38
+ pages/
39
+ index.haml
40
+ partials/
39
41
  stylesheets/
40
42
  application.sass
41
43
 
@@ -51,28 +53,4 @@ All of the pages are parsed and wrapped up in application.haml and put into the
51
53
  StaticMatic adds a few helpers to the core Haml helpers:
52
54
 
53
55
  = link 'Title', 'url'
54
- = img 'my_image.jpg'
55
-
56
-
57
- **_Coming soon:_**
58
-
59
- I'm already extending these to include some neat conventions to speed up coding. For example, in the next version:
60
-
61
- = link 'Contact Us'
62
-
63
- will produce
64
-
65
- <a href="contact_us.html">Contact Us</a>
66
-
67
- Or with the Rewriting enabled:
68
-
69
- <a href="contact_us">Contact Us</a>
70
-
71
- ## What's Next?
72
-
73
- * Multiple directories of content
74
- * Layouts based on directory of page template
75
- * Additional Helpers
76
- * Tests, tests, tests!
77
- * Configuration
78
- * Default Rewriting for HTML pages (drop the .html)
56
+ = img 'my_image.jpg'
data/Rakefile CHANGED
@@ -1,7 +1,30 @@
1
+ require 'rubygems'
1
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')
2
7
 
3
- desc "Default Task"
4
- task :default => [:test]
8
+ task :default => [:package]
9
+
10
+ spec = Gem::Specification.new do |s|
11
+ s.name = "staticmatic"
12
+ s.version = StaticMatic::VERSION::STRING
13
+ s.author = "Stephen Bartholomew"
14
+ s.email = "steve@curve21.com"
15
+ s.homepage = "http//www.curve21.com"
16
+ s.summary = "Manage static sites using Haml & Sass"
17
+ files = FileList["**/**/**"]
18
+ files.exclude 'pkg'
19
+ s.files = files.to_a
20
+ s.test_files = Dir.glob("test/*_test.rb")
21
+ s.add_dependency("haml")
22
+ s.add_dependency("mongrel")
23
+ s.executables=['staticmatic']
24
+ end
25
+
26
+ Rake::GemPackageTask.new(spec) do |pkg|
27
+ end
5
28
 
6
29
  desc "Run all unit tests"
7
30
  Rake::TestTask.new(:test) do |t|
@@ -5,9 +5,7 @@ require File.dirname(__FILE__) + '/staticmatic/helpers'
5
5
 
6
6
  Haml::Helpers.class_eval("include StaticMatic::Helpers")
7
7
 
8
- require File.dirname(__FILE__) + '/staticmatic/configuration'
9
- require File.dirname(__FILE__) + '/staticmatic/error'
10
- require File.dirname(__FILE__) + '/staticmatic/base'
11
- require File.dirname(__FILE__) + '/staticmatic/server'
12
-
8
+ %w(version configuration error base server).each do |file|
9
+ require File.join(File.dirname(__FILE__), 'staticmatic', file)
10
+ end
13
11
 
@@ -120,7 +120,10 @@ module StaticMatic
120
120
  full_file_path = File.join(@src_dir, 'pages', source_dir, "#{source_file}.haml")
121
121
 
122
122
  begin
123
- @scope.instance_variable_set("@layout", nil)
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
124
127
  html = generate_html_from_template_source(File.read(full_file_path))
125
128
 
126
129
  @layout = detirmine_layout(source_dir)
@@ -192,7 +195,8 @@ module StaticMatic
192
195
  def generate_css(source, source_dir = '')
193
196
  full_file_path = File.join(@src_dir, 'stylesheets', source_dir, "#{source}.sass")
194
197
  begin
195
- stylesheet = Sass::Engine.new(File.read(full_file_path))
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)
196
200
  stylesheet.to_css
197
201
  rescue Sass::SyntaxError => sass_error
198
202
  raise StaticMatic::Error.new(sass_error.sass_line, full_file_path, sass_error.message)
@@ -4,17 +4,13 @@ module StaticMatic
4
4
 
5
5
  attr_accessor :preview_server_host
6
6
 
7
- attr_accessor :use_relative_paths_for_links
8
- attr_accessor :use_relative_paths_for_images
9
- attr_accessor :use_relative_paths_for_stylesheets
10
- attr_accessor :use_relative_paths_for_javascripts
11
-
7
+ attr_accessor :use_extensions_for_page_links
8
+ attr_accessor :sass_options
9
+
12
10
  def initialize
13
11
  self.preview_server_port = 3000
14
- self.use_relative_paths_for_links = false
15
- self.use_relative_paths_for_images = false
16
- self.use_relative_paths_for_stylesheets = false
17
- self.use_relative_paths_for_javascripts = false
12
+ self.use_extensions_for_page_links = true
13
+ self.sass_options = {}
18
14
  end
19
15
  end
20
16
  end
@@ -3,35 +3,57 @@ module StaticMatic
3
3
  self.extend self
4
4
 
5
5
  # Generates links to all stylesheets in the source directory
6
- def stylesheets(options = {})
7
- stylesheet_dir = "#{@staticmatic.base_dir}/src/stylesheets"
8
-
9
- stylesheet_directories = Dir["#{stylesheet_dir}/**/*.sass"]
10
-
11
- # Bit of a hack here - adds any stylesheets that exist in the site/ dir that haven't been generated from source sass
12
- Dir["#{@staticmatic.base_dir}/site/stylesheets/*.css"].each do |filename|
13
- search_filename = File.basename(filename).chomp(File.extname(filename))
14
- already_included = false
15
- stylesheet_directories.each do |path|
16
- path = File.basename(path)
17
- if path.include?(search_filename)
18
- already_included = true
19
- end
20
- end
21
-
22
- stylesheet_directories << filename if !already_included
6
+ # = stylesheets
7
+ # or specific stylesheets in a specific order
8
+ # = stylesheets :reset, :application
9
+ # Can also pass options hash in at the end so you can specify :media => :print
10
+ def stylesheets(*params)
11
+ options = {}
12
+ if params.last.is_a?(Hash)
13
+ options = params.last
14
+ params.slice!(-1, 1)
23
15
  end
16
+ options[:media] = 'all' unless options.has_key?(:media)
17
+ options[:rel] = 'stylesheet'
18
+
19
+ relative_path = current_page_relative_path
24
20
 
25
21
  output = ""
26
- stylesheet_directories.each do |path|
27
- filename_without_extension = File.basename(path).chomp(File.extname(path))
28
- href = "stylesheets/#{filename_without_extension}.css"
22
+ if params.length == 0
23
+ # no specific files requested so include all in no particular order
24
+ stylesheet_dir = File.join(@staticmatic.src_dir, 'stylesheets')
25
+ stylesheet_directories = Dir[File.join(stylesheet_dir, '**','*.sass')]
29
26
 
30
- unless @staticmatic.configuration.use_relative_paths_for_stylesheets
31
- href = "/#{href}"
27
+ # Bit of a hack here - adds any stylesheets that exist in the site/ dir that haven't been generated from source sass
28
+ Dir[File.join(@staticmatic.site_dir, 'stylesheets', '*.css')].each do |filename|
29
+ search_filename = File.basename(filename).chomp(File.extname(filename))
30
+
31
+ already_included = false
32
+ stylesheet_directories.each do |path|
33
+ if File.basename(path).include?(search_filename)
34
+ already_included = true
35
+ break
36
+ end
37
+ end
38
+
39
+ stylesheet_directories << filename unless already_included
32
40
  end
33
41
 
34
- output << tag(:link, :href => href, :rel => 'stylesheet', :media => 'all')
42
+ stylesheet_directories.each do |path|
43
+ filename_without_extension = File.basename(path).chomp(File.extname(path))
44
+
45
+ options[:href] = "#{relative_path}stylesheets/#{filename_without_extension}.css"
46
+ output << tag(:link, options)
47
+ end
48
+ else
49
+ #specific files requested and in a specific order
50
+ params.each do |file|
51
+ if File.exist?(File.join(@staticmatic.src_dir, 'stylesheets', "#{file}.sass")) ||
52
+ File.exist?(File.join(@staticmatic.site_dir, 'stylesheets', "#{file}.css"))
53
+ options[:href] = "#{relative_path}stylesheets/#{file}.css"
54
+ output << tag(:link, options)
55
+ end
56
+ end
35
57
  end
36
58
 
37
59
  output
@@ -42,16 +64,13 @@ module StaticMatic
42
64
  # javascripts('test') -> <script language="javascript" src="javascripts/test.js"></script>
43
65
  #
44
66
  def javascripts(*files)
67
+ relative_path = current_page_relative_path
68
+
45
69
  output = ""
46
70
  files.each do |file|
47
- if !file.match(/^http\:\/\//)
48
- src = "javascripts/#{file}.js"
49
- unless @staticmatic.configuration.use_relative_paths_for_javascripts
50
- src = "/#{src}"
51
- end
52
-
53
- output << tag(:script, :language => 'javascript', :src => src, :type => "text/javascript") { "" }
54
- end
71
+ file_str = file.to_s
72
+ src = file_str.match(%r{^((\.\.?)?/|https?://)}) ? file_str : "#{relative_path}javascripts/#{file_str}.js"
73
+ output << tag(:script, :language => 'javascript', :src => src, :type => "text/javascript") { "" }
55
74
  end
56
75
  output
57
76
  end
@@ -77,38 +96,34 @@ module StaticMatic
77
96
  end
78
97
 
79
98
  if href.nil? || href.strip.length < 1
80
- href = urlify(title) + ".html"
99
+ path_prefix = ''
100
+ if title.match(/^(\.\.?)?\//)
101
+ # starts with relative path so strip it off and prepend it to the urlified title
102
+ path_prefix_match = title.match(/^[^\s]*\//)
103
+ path_prefix = path_prefix_match[0] if path_prefix_match
104
+ title = title[path_prefix.length, title.length]
105
+ end
106
+ href = path_prefix + urlify(title) + ".html"
81
107
  end
108
+
109
+ options[:href] = "#{current_page_relative_path(href)}#{href}"
82
110
 
83
- options.merge!(:href => href)
84
-
85
- unless @staticmatic.configuration.use_relative_paths_for_links || href.match(/^#|\/|(http\:\/\/)/)
86
- options[:href] = "/#{options[:href]}"
111
+ local_page = (options[:href].match(/^(\#|.+?\:)/) == nil)
112
+ unless @staticmatic.configuration.use_extensions_for_page_links || !local_page
113
+ options[:href].chomp!(".html")
114
+ options[:href].chomp!("index") if options[:href][-5, 5] == 'index'
87
115
  end
88
-
116
+
89
117
  tag(:a, options) { title }
90
118
  end
91
119
 
92
- # Generates an image tag.
120
+ # Generates an image tag always relative to the current page unless absolute path or http url specified.
93
121
  #
94
122
  # img('test_image.gif') -> <img src="/images/test_image.gif" alt="Test image"/>
95
123
  # img('contact/test_image.gif') -> <img src="/images/contact/test_image.gif" alt="Test image"/>
96
124
  # img('http://localhost/test_image.gif') -> <img src="http://localhost/test_image.gif" alt="Test image"/>
97
- #
98
- # If you want to use relative paths instead set 'configuration.use_relative_paths_for_images = true'
99
- # in configuration.rb. This will set the image source relative to the page.
100
- #
101
- # img('test_image.gif') -> <img src="images/test_image.gif" alt="Test image"/>
102
125
  def img(name, options = {})
103
- unless name.match(%r{^(/|http://)})
104
- options[:src] = "images/#{name}"
105
- unless @staticmatic.configuration.use_relative_paths_for_images
106
- options[:src] = "/" + options[:src]
107
- end
108
- else
109
- options[:src] = name
110
- end
111
-
126
+ options[:src] = name.match(%r{^((\.\.?)?/|https?://)}) ? name : "#{current_page_relative_path}images/#{name}"
112
127
  options[:alt] ||= name.split('/').last.split('.').first.capitalize.gsub(/_|-/, ' ')
113
128
  tag :img, options
114
129
  end
@@ -127,9 +142,9 @@ module StaticMatic
127
142
  if block_given?
128
143
  output << ">"
129
144
  output << yield
130
- output << "</#{name}>\n"
145
+ output << "</#{name}>"
131
146
  else
132
- output << "/>\n"
147
+ output << "/>"
133
148
  end
134
149
  output
135
150
  end
@@ -157,5 +172,17 @@ module StaticMatic
157
172
  def current_page
158
173
  @staticmatic.current_page
159
174
  end
175
+
176
+ private
177
+
178
+ def current_page_relative_path(current_path = nil)
179
+ if current_path.nil? || current_path.match(/^((\.\.?)?\/|\#|.+?\:)/) == nil
180
+ current_page_depth = current_page.split('/').length - 2;
181
+ (current_page_depth > 0) ? ([ '..' ] * current_page_depth).join('/') + '/' : ''
182
+ else
183
+ ''
184
+ end
185
+ end
186
+
160
187
  end
161
188
  end
@@ -0,0 +1,34 @@
1
+ module StaticMatic #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 9
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ URLIFIED = STRING.tr('.', '_')
9
+
10
+ # requirements_met? can take a hash with :major, :minor, :tiny set or
11
+ # a string in the format "major.minor.tiny"
12
+ def self.requirements_met?(minimum_version = {})
13
+ major = minor = tiny = 0
14
+ if minimum_version.is_a?(Hash)
15
+ major = minimum_version[:major].to_i if minimum_version.has_key?(:major)
16
+ minor = minimum_version[:minor].to_i if minimum_version.has_key?(:minor)
17
+ tiny = minimum_version[:tiny].to_i if minimum_version.has_key?(:tiny)
18
+ else
19
+ major, minor, tiny = minimum_version.to_s.split('.').collect { |v| v.to_i }
20
+ end
21
+ met = false
22
+ if StaticMatic::VERSION::MAJOR > major
23
+ met = true
24
+ elsif StaticMatic::VERSION::MAJOR == major
25
+ if StaticMatic::VERSION::MINOR > minor
26
+ met = true
27
+ elsif StaticMatic::VERSION::MINOR == minor
28
+ met = StaticMatic::VERSION::TINY >= tiny
29
+ end
30
+ end
31
+ met
32
+ end
33
+ end
34
+ end
@@ -6,6 +6,11 @@ class StaticMaticBaseTest < Test::Unit::TestCase
6
6
  @base_dir = File.dirname(__FILE__) + '/sandbox/test_site'
7
7
  @staticmatic = StaticMatic::Base.new(@base_dir)
8
8
  end
9
+
10
+ def test_initial_configuration_settings
11
+ assert_equal true, @staticmatic.configuration.use_extensions_for_page_links
12
+ assert_equal 3000, @staticmatic.configuration.preview_server_port
13
+ end
9
14
 
10
15
  def test_should_setup_directories
11
16
  tmp_dir = File.dirname(__FILE__) + '/sandbox/tmp'
@@ -23,11 +28,9 @@ class StaticMaticBaseTest < Test::Unit::TestCase
23
28
  end
24
29
  Dir.delete("#{tmp_dir}/#{dir}") if File.exists?("#{tmp_dir}/#{dir}")
25
30
  end
26
-
27
31
  end
28
32
 
29
33
  def test_should_generate_html_with_layout
30
-
31
34
  content = @staticmatic.generate_html_with_layout("index")
32
35
  assert_match "StaticMatic", content
33
36
  assert_match "This is some test content", content