staticmatic 0.11.0.alpha.8 → 0.11.0.alpha.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rubygems"
2
2
  require 'spec/rake/spectask'
3
3
 
4
- require File.dirname(__FILE__) + '/lib/staticmatic'
4
+ require File.expand_path("../lib/staticmatic", __FILE__)
5
5
 
6
6
  begin
7
7
  require 'jeweler'
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :major: 0
3
3
  :minor: 11
4
4
  :patch: 0
5
- :build: alpha.8
5
+ :build: alpha.9
@@ -1,211 +1,3 @@
1
- module StaticMatic
2
- module Helpers
3
- self.extend self
4
-
5
- # Generates links to all stylesheets in the source directory
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)
15
- end
16
- options[:media] = 'all' unless options.has_key?(:media)
17
- options[:rel] = 'stylesheet'; options[:type] = 'text/css'
18
-
19
- relative_path = current_page_relative_path
20
-
21
- output = ""
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,scss}')]
26
-
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
- puts search_filename
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
40
- end
41
-
42
- stylesheet_directories.each do |path|
43
-
44
- filename_without_extension = File.basename(path).chomp(File.extname(path))
45
-
46
- if !filename_without_extension.match(/^\_/)
47
-
48
- path = path.gsub(/#{@staticmatic.src_dir}/, "").
49
- gsub(/#{@staticmatic.site_dir}/, "").
50
- gsub(/#{filename_without_extension}\.(sass|scss|css)/, "")
51
-
52
- options[:href] = "#{relative_path}#{path}#{filename_without_extension}.css"
53
- output << tag(:link, options)
54
- end
55
- end
56
- else
57
- #specific files requested and in a specific order
58
- params.each do |file|
59
- if File.exist?(File.join(@staticmatic.src_dir, 'stylesheets', "#{file}.sass")) ||
60
- File.exist?(File.join(@staticmatic.site_dir, 'stylesheets', "#{file}.css"))
61
- options[:href] = "#{relative_path}stylesheets/#{file}.css"
62
- output << tag(:link, options)
63
- end
64
- end
65
- end
66
-
67
- output
68
- end
69
-
70
- # Generate javascript source tags for the specified files
71
- #
72
- # javascripts('test') -> <script language="javascript" src="javascripts/test.js"></script>
73
- #
74
- def javascripts(*files)
75
- relative_path = current_page_relative_path
76
-
77
- output = ""
78
- files.each do |file|
79
- file_str = file.to_s
80
- src = file_str.match(%r{^((\.\.?)?/|https?://)}) ? file_str : "#{relative_path}javascripts/#{file_str}.js"
81
- output << tag(:script, :language => 'javascript', :src => src, :type => "text/javascript") { "" }
82
- end
83
- output
84
- end
85
-
86
- # Generates a form text field
87
- #
88
- def text_field(name, value, options = {})
89
- options.merge!(:type => "text", :name => name, :value => value)
90
- tag(:input, options)
91
- end
92
-
93
- # Generate a form textarea
94
- #
95
- def text_area(name, value, options = {})
96
- options.merge!(:name => name)
97
- tag(:textarea, options) { value }
98
- end
99
-
100
- # Generate an HTML link
101
- #
102
- # If only the title is passed, it will automatically
103
- # create a link from this value:
104
- #
105
- # link('Test') -> <a href="test.html">Test</a>
106
- #
107
- def link(title, href = "", options = {})
108
- if href.is_a?(Hash)
109
- options = href
110
- href = ""
111
- end
112
-
113
- if href.nil? || href.strip.length < 1
114
- path_prefix = ''
115
- if title.match(/^(\.\.?)?\//)
116
- # starts with relative path so strip it off and prepend it to the urlified title
117
- path_prefix_match = title.match(/^[^\s]*\//)
118
- path_prefix = path_prefix_match[0] if path_prefix_match
119
- title = title[path_prefix.length, title.length]
120
- end
121
- href = path_prefix + urlify(title) + ".html"
122
- end
123
-
124
- options[:href] = "#{current_page_relative_path(href)}#{href}"
125
-
126
- local_page = (options[:href].match(/^(\#|.+?\:)/) == nil)
127
- unless @staticmatic.configuration.use_extensions_for_page_links || !local_page
128
- options[:href].chomp!(".html")
129
- options[:href].chomp!("index") if options[:href][-5, 5] == 'index'
130
- end
131
-
132
- tag(:a, options) { title }
133
- end
134
- alias link_to link
135
-
136
- # Generates an image tag always relative to the current page unless absolute path or http url specified.
137
- #
138
- # img('test_image.gif') -> <img src="/images/test_image.gif" alt="Test image"/>
139
- # img('contact/test_image.gif') -> <img src="/images/contact/test_image.gif" alt="Test image"/>
140
- # img('http://localhost/test_image.gif') -> <img src="http://localhost/test_image.gif" alt="Test image"/>
141
- def img(name, options = {})
142
- options[:src] = name.match(%r{^((\.\.?)?/|https?://)}) ? name : "#{current_page_relative_path}images/#{name}"
143
- options[:alt] ||= name.split('/').last.split('.').first.capitalize.gsub(/_|-/, ' ')
144
- tag :img, options
145
- end
146
-
147
- # Generates HTML tags:
148
- #
149
- # tag(:br) -> <br/>
150
- # tag(:a, :href => 'test.html') { "Test" } -> <a href="test.html">Test</a>
151
- #
152
- def tag(name, options = {}, &block)
153
- options[:id] ||= options[:name] if options[:name]
154
- output = "<#{name}"
155
- options.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |key|
156
- output << " #{key}=\"#{options[key]}\"" if options[key]
157
- end
158
-
159
- if block_given?
160
- output << ">"
161
- output << yield
162
- output << "</#{name}>"
163
- else
164
- format = @staticmatic.configuration.haml_options[:format]
165
-
166
- if format.nil? || format == :xhtml
167
- output << "/>"
168
- else
169
- output << ">"
170
- end
171
- end
172
- output
173
- end
174
-
175
- # Generates a URL friendly string from the value passed:
176
- #
177
- # "We love Haml" -> "we_love_haml"
178
- # "Elf & Ham" -> "elf_and_ham"
179
- # "Stephen's gem" -> "stephens_gem"
180
- #
181
- def urlify(string)
182
- string.tr(" ", "_").
183
- sub("&", "and").
184
- sub("@", "at").
185
- tr("^A-Za-z0-9_", "").
186
- sub(/_{2,}/, "_").
187
- downcase
188
- end
189
-
190
- # Include a partial template
191
- def partial(name, options = {})
192
- @staticmatic.generate_partial(name, options)
193
- end
194
-
195
- def current_page
196
- @staticmatic.current_page
197
- end
198
-
199
- private
200
-
201
- def current_page_relative_path(current_path = nil)
202
- if current_path.nil? || current_path.match(/^((\.\.?)?\/|\#|.+?\:)/) == nil
203
- current_page_depth = current_page.split('/').length - 2;
204
- (current_page_depth > 0) ? ([ '..' ] * current_page_depth).join('/') + '/' : ''
205
- else
206
- ''
207
- end
208
- end
209
-
210
- end
1
+ ["assets", "form", "current_path", "render", "tag", "url"].each do |helper|
2
+ require File.join(File.dirname(__FILE__), "helpers", "#{helper}_helper")
211
3
  end
@@ -0,0 +1,100 @@
1
+
2
+ module StaticMatic
3
+ module Helpers
4
+ module AssetTagHelper
5
+ self.extend self
6
+
7
+ # Generates links to all stylesheets in the source directory
8
+ # = stylesheets
9
+ # or specific stylesheets in a specific order
10
+ # = stylesheets :reset, :application
11
+ # Can also pass options hash in at the end so you can specify :media => :print
12
+ def stylesheets(*params)
13
+ options = {}
14
+ if params.last.is_a?(Hash)
15
+ options = params.last
16
+ params.slice!(-1, 1)
17
+ end
18
+ options[:media] = 'all' unless options.has_key?(:media)
19
+ options[:rel] = 'stylesheet'; options[:type] = 'text/css'
20
+
21
+ relative_path = current_page_relative_path
22
+
23
+ output = ""
24
+ if params.length == 0
25
+ # no specific files requested so include all in no particular order
26
+ stylesheet_dir = File.join(@staticmatic.src_dir, 'stylesheets')
27
+ stylesheet_directories = Dir[File.join(stylesheet_dir, '**','*.{sass,scss}')]
28
+
29
+ # Bit of a hack here - adds any stylesheets that exist in the site/ dir that haven't been generated from source sass
30
+ Dir[File.join(@staticmatic.site_dir, 'stylesheets', '*.css')].each do |filename|
31
+ search_filename = File.basename(filename).chomp(File.extname(filename))
32
+ puts search_filename
33
+ already_included = false
34
+ stylesheet_directories.each do |path|
35
+ if File.basename(path).include?(search_filename)
36
+ already_included = true
37
+ break
38
+ end
39
+ end
40
+
41
+ stylesheet_directories << filename unless already_included
42
+ end
43
+
44
+ stylesheet_directories.each do |path|
45
+
46
+ filename_without_extension = File.basename(path).chomp(File.extname(path))
47
+
48
+ if !filename_without_extension.match(/^\_/)
49
+
50
+ path = path.gsub(/#{@staticmatic.src_dir}/, "").
51
+ gsub(/#{@staticmatic.site_dir}/, "").
52
+ gsub(/#{filename_without_extension}\.(sass|scss|css)/, "")
53
+
54
+ options[:href] = File.join(relative_path, path, "#{filename_without_extension}.css")
55
+ output << tag(:link, options)
56
+ end
57
+ end
58
+ else
59
+ #specific files requested and in a specific order
60
+ params.each do |file|
61
+ if File.exist?(File.join(@staticmatic.src_dir, 'stylesheets', "#{file}.sass")) ||
62
+ File.exist?(File.join(@staticmatic.site_dir, 'stylesheets', "#{file}.css"))
63
+ options[:href] = File.join(relative_path, "stylesheets", "#{file}.css")
64
+ output << tag(:link, options)
65
+ end
66
+ end
67
+ end
68
+
69
+ output
70
+ end
71
+
72
+ # Generate javascript source tags for the specified files
73
+ #
74
+ # javascripts('test') -> <script language="javascript" src="javascripts/test.js"></script>
75
+ #
76
+ def javascripts(*files)
77
+ relative_path = current_page_relative_path
78
+
79
+ output = ""
80
+ files.each do |file|
81
+ file_str = file.to_s
82
+ src = file_str.match(%r{^((\.\.?)?/|https?://)}) ? file_str : "#{relative_path}javascripts/#{file_str}.js"
83
+ output << tag(:script, :language => 'javascript', :src => src, :type => "text/javascript") { "" }
84
+ end
85
+ output
86
+ end
87
+
88
+ # Generates an image tag always relative to the current page unless absolute path or http url specified.
89
+ #
90
+ # img('test_image.gif') -> <img src="/images/test_image.gif" alt="Test image"/>
91
+ # img('contact/test_image.gif') -> <img src="/images/contact/test_image.gif" alt="Test image"/>
92
+ # img('http://localhost/test_image.gif') -> <img src="http://localhost/test_image.gif" alt="Test image"/>
93
+ def img(name, options = {})
94
+ options[:src] = name.match(%r{^((\.\.?)?/|https?://)}) ? name : "#{current_page_relative_path}images/#{name}"
95
+ options[:alt] ||= name.split('/').last.split('.').first.capitalize.gsub(/_|-/, ' ')
96
+ tag :img, options
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,22 @@
1
+ module StaticMatic
2
+ module Helpers
3
+ module CurrentPathHelper
4
+ self.extend self
5
+
6
+ def current_page
7
+ @staticmatic.current_page
8
+ end
9
+
10
+ private
11
+
12
+ def current_page_relative_path(current_path = nil)
13
+ if current_path.nil? || current_path.match(/^((\.\.?)?\/|\#|.+?\:)/) == nil
14
+ current_page_depth = current_page.split('/').length - 2;
15
+ (current_page_depth > 0) ? ([ '..' ] * current_page_depth).join('/') + '/' : ''
16
+ else
17
+ ''
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module StaticMatic
3
+ module Helpers
4
+ module FormHelper
5
+ self.extend self
6
+
7
+ # Generates a form text field
8
+ #
9
+ def text_field(name, value, options = {})
10
+ options.merge!(:type => "text", :name => name, :value => value)
11
+ tag(:input, options)
12
+ end
13
+
14
+
15
+ # Generate a form textarea
16
+ #
17
+ def text_area(name, value, options = {})
18
+ options.merge!(:name => name)
19
+ tag(:textarea, options) { value }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module StaticMatic
3
+ module Helpers
4
+ module RenderHelper
5
+ self.extend self
6
+
7
+ # Include a partial template
8
+ def partial(name, options = {})
9
+ @staticmatic.generate_partial(name, options)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ module StaticMatic
2
+ module Helpers
3
+ module TagHelper
4
+ self.extend self
5
+
6
+ # Generates HTML tags:
7
+ #
8
+ # tag(:br) -> <br/>
9
+ # tag(:a, :href => 'test.html') { "Test" } -> <a href="test.html">Test</a>
10
+ #
11
+ def tag(name, options = {}, &block)
12
+ options[:id] ||= options[:name] if options[:name]
13
+ output = "<#{name}"
14
+ options.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |key|
15
+ output << " #{key}=\"#{options[key]}\"" if options[key]
16
+ end
17
+
18
+ if block_given?
19
+ output << ">"
20
+ output << yield
21
+ output << "</#{name}>"
22
+ else
23
+ format = @staticmatic.configuration.haml_options[:format]
24
+
25
+ if format.nil? || format == :xhtml
26
+ output << "/>"
27
+ else
28
+ output << ">"
29
+ end
30
+ end
31
+ output
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,59 @@
1
+ module StaticMatic
2
+ module Helpers
3
+ module UrlHelper
4
+ self.extend self
5
+
6
+ # Generate an HTML link
7
+ #
8
+ # If only the title is passed, it will automatically
9
+ # create a link from this value:
10
+ #
11
+ # link('Test') -> <a href="test.html">Test</a>
12
+ #
13
+ def link(title, href = "", options = {})
14
+ if href.is_a?(Hash)
15
+ options = href
16
+ href = ""
17
+ end
18
+
19
+ if href.nil? || href.strip.length < 1
20
+ path_prefix = ''
21
+ if title.match(/^(\.\.?)?\//)
22
+ # starts with relative path so strip it off and prepend it to the urlified title
23
+ path_prefix_match = title.match(/^[^\s]*\//)
24
+ path_prefix = path_prefix_match[0] if path_prefix_match
25
+ title = title[path_prefix.length, title.length]
26
+ end
27
+ href = path_prefix + urlify(title) + ".html"
28
+ end
29
+
30
+ options[:href] = "#{current_page_relative_path(href)}#{href}"
31
+
32
+ local_page = (options[:href].match(/^(\#|.+?\:)/) == nil)
33
+ unless @staticmatic.configuration.use_extensions_for_page_links || !local_page
34
+ options[:href].chomp!(".html")
35
+ options[:href].chomp!("index") if options[:href][-5, 5] == 'index'
36
+ end
37
+
38
+ tag(:a, options) { title }
39
+ end
40
+ alias link_to link
41
+
42
+ # Generates a URL friendly string from the value passed:
43
+ #
44
+ # "We love Haml" -> "we_love_haml"
45
+ # "Elf & Ham" -> "elf_and_ham"
46
+ # "Stephen's gem" -> "stephens_gem"
47
+ #
48
+ def urlify(string)
49
+ string.tr(" ", "_").
50
+ sub("&", "and").
51
+ sub("@", "at").
52
+ tr("^A-Za-z0-9_", "").
53
+ sub(/_{2,}/, "_").
54
+ downcase
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -1,6 +1,7 @@
1
1
  module StaticMatic::ServerMixin
2
2
  def preview
3
- puts "StaticMatic Preview Server Starting..."
3
+ puts "StaticMatic Preview Server"
4
+ puts "Ctrl+C to exit"
4
5
  StaticMatic::Server.start(self)
5
6
  end
6
7
  end
@@ -3,6 +3,8 @@ module StaticMatic
3
3
  def initialize(staticmatic, default = nil)
4
4
  @files = default || Rack::File.new(staticmatic.site_dir)
5
5
  @staticmatic = staticmatic
6
+
7
+
6
8
  end
7
9
 
8
10
  def call(env)
@@ -41,6 +43,13 @@ module StaticMatic
41
43
 
42
44
  # Starts the StaticMatic preview server
43
45
  def self.start(staticmatic)
46
+ [ 'INT', 'TERM' ].each do |signal|
47
+ Signal.trap(signal) do
48
+ puts
49
+ puts "Exiting"
50
+ exit!(0)
51
+ end
52
+ end
44
53
  port = staticmatic.configuration.preview_server_port || 3000
45
54
 
46
55
  host = staticmatic.configuration.preview_server_host || ""
@@ -48,7 +57,8 @@ module StaticMatic
48
57
  app = Rack::Builder.new do
49
58
  use Rack::ShowExceptions
50
59
  run StaticMatic::Server.new(staticmatic)
51
- end
60
+ end
61
+
52
62
  Rack::Handler::WEBrick.run(app, :Port => port, :Host => host)
53
63
  end
54
64
 
@@ -1,17 +1,15 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+
2
+ require File.dirname(__FILE__) + "/../spec_helper"
2
3
 
3
4
  describe "Helpers:" do
4
- include StaticMatic::Helpers
5
+ include StaticMatic::Helpers::AssetTagHelper
6
+ include StaticMatic::Helpers::CurrentPathHelper
7
+ include StaticMatic::Helpers::TagHelper
5
8
  before do
6
9
  setup_staticmatic
7
10
  @staticmatic.instance_variable_set("@current_page", "")
8
11
  end
9
12
 
10
- it "should include custom helper" do
11
- content = @staticmatic.generate_html_with_layout("index")
12
- content.should match(/Hello, Steve!/)
13
- end
14
-
15
13
  context "When using the stylesheet helper" do
16
14
  before do
17
15
  @links = stylesheets
@@ -38,4 +36,4 @@ describe "Helpers:" do
38
36
  @links.should match(/\.\.\/stylesheets/)
39
37
  end
40
38
  end
41
- end
39
+ end
@@ -0,0 +1,18 @@
1
+
2
+ require File.dirname(__FILE__) + "/../spec_helper"
3
+
4
+ describe "Helpers:" do
5
+ include StaticMatic::Helpers::AssetTagHelper
6
+ include StaticMatic::Helpers::CurrentPathHelper
7
+ include StaticMatic::Helpers::TagHelper
8
+ before do
9
+ setup_staticmatic
10
+ @staticmatic.instance_variable_set("@current_page", "")
11
+ end
12
+
13
+ it "should include custom helper" do
14
+ content = @staticmatic.generate_html_with_layout("index")
15
+ content.should match(/Hello, Steve!/)
16
+ end
17
+
18
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'stringio'
3
3
  require 'spec'
4
4
 
5
- require File.dirname(__FILE__) + '/../lib/staticmatic'
5
+ require 'lib/staticmatic'
6
6
 
7
7
  TEST_SITE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "sandbox", "test_site"))
8
8
 
@@ -11,4 +11,4 @@ end
11
11
 
12
12
  def setup_staticmatic
13
13
  @staticmatic = StaticMatic::Base.new(TEST_SITE_PATH)
14
- end
14
+ end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 11
8
8
  - 0
9
9
  - alpha
10
- - 8
11
- version: 0.11.0.alpha.8
10
+ - 9
11
+ version: 0.11.0.alpha.9
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-06-05 00:00:00 +01:00
19
+ date: 2010-09-16 00:00:00 +01:00
20
20
  default_executable: staticmatic
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,12 @@ files:
84
84
  - lib/staticmatic/configuration.rb
85
85
  - lib/staticmatic/error.rb
86
86
  - lib/staticmatic/helpers.rb
87
+ - lib/staticmatic/helpers/assets_helper.rb
88
+ - lib/staticmatic/helpers/current_path_helper.rb
89
+ - lib/staticmatic/helpers/form_helper.rb
90
+ - lib/staticmatic/helpers/render_helper.rb
91
+ - lib/staticmatic/helpers/tag_helper.rb
92
+ - lib/staticmatic/helpers/url_helper.rb
87
93
  - lib/staticmatic/mixins/build.rb
88
94
  - lib/staticmatic/mixins/helpers.rb
89
95
  - lib/staticmatic/mixins/render.rb
@@ -101,7 +107,8 @@ files:
101
107
  - lib/staticmatic/templates/rescues/template.haml
102
108
  - spec/base_spec.rb
103
109
  - spec/compass_integration_spec.rb
104
- - spec/helpers_spec.rb
110
+ - spec/helpers/asset_helper_spec.rb
111
+ - spec/helpers/custom_helper_spec.rb
105
112
  - spec/render_spec.rb
106
113
  - spec/rescue_spec.rb
107
114
  - spec/sandbox/test_site/config/compass.rb
@@ -175,7 +182,8 @@ summary: Lightweight Static Site Framework
175
182
  test_files:
176
183
  - spec/base_spec.rb
177
184
  - spec/compass_integration_spec.rb
178
- - spec/helpers_spec.rb
185
+ - spec/helpers/asset_helper_spec.rb
186
+ - spec/helpers/custom_helper_spec.rb
179
187
  - spec/render_spec.rb
180
188
  - spec/rescue_spec.rb
181
189
  - spec/sandbox/test_site/config/compass.rb