middleman 0.14.1 → 0.99.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -18
- data/VERSION +1 -1
- data/features/automatic_image_sizes.feature +7 -7
- data/features/cache_buster.feature +10 -10
- data/features/minify_css.feature +10 -10
- data/features/minify_javascript.feature +6 -6
- data/features/step_definitions/asset_host_steps.rb +1 -0
- data/features/step_definitions/middleman_steps.rb +1 -1
- data/lib/middleman.rb +1 -18
- data/lib/middleman/assets.rb +33 -0
- data/lib/middleman/base.rb +25 -66
- data/lib/middleman/builder.rb +8 -4
- data/lib/middleman/features.rb +39 -0
- data/lib/middleman/features/asset_host.rb +16 -19
- data/lib/middleman/features/automatic_image_sizes.rb +24 -24
- data/lib/middleman/{fastimage.rb → features/automatic_image_sizes/fastimage.rb} +0 -0
- data/lib/middleman/features/cache_buster.rb +31 -38
- data/lib/middleman/{helpers.rb → features/default_helpers.rb} +8 -11
- data/lib/middleman/features/livereload.rb +19 -0
- data/lib/middleman/features/minify_css.rb +9 -0
- data/lib/middleman/features/minify_javascript.rb +15 -17
- data/lib/middleman/features/minify_javascript/rack.rb +31 -0
- data/lib/middleman/features/relative_assets.rb +29 -40
- data/lib/middleman/features/slickmap.rb +69 -70
- data/lib/middleman/features/smush_pngs.rb +8 -6
- data/lib/middleman/features/ugly_haml.rb +7 -0
- data/lib/middleman/renderers.rb +26 -0
- data/lib/middleman/renderers/coffee.rb +28 -0
- data/lib/middleman/renderers/haml.rb +2 -25
- data/lib/middleman/renderers/sass.rb +40 -87
- data/lib/middleman/template/init.rbt +30 -7
- data/middleman.gemspec +58 -69
- data/spec/builder_spec.rb +10 -4
- data/spec/fixtures/sample/views/stylesheets/site_scss.css.scss +1 -0
- data/spec/fixtures/sample/views/stylesheets/test_less.css.less +5 -0
- metadata +125 -113
- data/lib/middleman/rack/minify_css.rb +0 -25
- data/lib/middleman/rack/minify_javascript.rb +0 -25
- data/lib/middleman/rack/sprockets.rb +0 -61
- data/lib/middleman/renderers/builder.rb +0 -23
- data/lib/middleman/renderers/erb.rb +0 -24
- data/lib/middleman/renderers/less.rb +0 -23
- data/spec/fixtures/sample/public/javascripts/to-be-included.js +0 -1
- data/spec/fixtures/sample/views/javascripts/empty-with-include.js +0 -1
data/Rakefile
CHANGED
@@ -13,24 +13,20 @@ begin
|
|
13
13
|
gem.authors = ["Thomas Reynolds"]
|
14
14
|
gem.rubyforge_project = "middleman"
|
15
15
|
gem.executables = %w(mm-init mm-build mm-server)
|
16
|
-
gem.add_dependency("rack")
|
17
|
-
gem.add_dependency("thin")
|
18
|
-
|
19
|
-
gem.add_dependency("
|
20
|
-
gem.add_dependency("
|
21
|
-
gem.add_dependency("
|
22
|
-
gem.add_dependency("
|
23
|
-
gem.add_dependency("
|
24
|
-
gem.add_dependency("
|
25
|
-
gem.add_dependency("
|
26
|
-
gem.add_dependency("
|
27
|
-
gem.add_dependency("
|
28
|
-
gem.add_dependency("
|
29
|
-
gem.add_dependency("
|
30
|
-
gem.add_dependency("fancy-buttons")
|
31
|
-
gem.add_dependency("json_pure")
|
32
|
-
gem.add_dependency("smusher")
|
33
|
-
gem.add_dependency("compass-slickmap")
|
16
|
+
gem.add_dependency("rack", "~>1.0")
|
17
|
+
gem.add_dependency("thin", "~>1.2.0")
|
18
|
+
gem.add_dependency("shotgun", "~>0.8.0")
|
19
|
+
gem.add_dependency("templater", "~>1.0.0")
|
20
|
+
gem.add_dependency("sinatra", "~>1.0")
|
21
|
+
gem.add_dependency("sinatra-content-for", "~>0.2.0")
|
22
|
+
gem.add_dependency("rack-test", "~>0.5.0")
|
23
|
+
gem.add_dependency("yui-compressor", "~>0.9.0")
|
24
|
+
gem.add_dependency("haml", "~>3.0")
|
25
|
+
gem.add_dependency("compass", "~>0.10.0")
|
26
|
+
gem.add_dependency("json_pure", "~>1.4.0")
|
27
|
+
gem.add_dependency("smusher", "~>0.4.5")
|
28
|
+
gem.add_dependency("compass-slickmap", "~>0.3.0")
|
29
|
+
# gem.add_dependency("livereload", "~>1.4.0")
|
34
30
|
|
35
31
|
gem.add_development_dependency("rspec")
|
36
32
|
gem.add_development_dependency("cucumber")
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.99.0.pre
|
@@ -1,14 +1,14 @@
|
|
1
1
|
Feature: Automatically detect and insert image dimensions into tags
|
2
2
|
In order to speed up development and appease YSlow
|
3
|
-
|
4
|
-
Scenario: Rendering an image with the feature enabled
|
5
|
-
Given "automatic_image_sizes" feature is "enabled"
|
6
|
-
When I go to "/auto-image-sizes.html"
|
7
|
-
Then I should see "width="
|
8
|
-
And I should see "height="
|
9
3
|
|
10
4
|
Scenario: Rendering an image with the feature disabled
|
11
5
|
Given "automatic_image_sizes" feature is "disabled"
|
12
6
|
When I go to "/auto-image-sizes.html"
|
13
7
|
Then I should not see "width="
|
14
|
-
And I should not see "height="
|
8
|
+
And I should not see "height="
|
9
|
+
|
10
|
+
Scenario: Rendering an image with the feature enabled
|
11
|
+
Given "automatic_image_sizes" feature is "enabled"
|
12
|
+
When I go to "/auto-image-sizes.html"
|
13
|
+
Then I should see "width="
|
14
|
+
And I should see "height="
|
@@ -1,15 +1,5 @@
|
|
1
1
|
Feature: Generate mtime-based query string for busting browser caches
|
2
2
|
In order to display the most recent content for IE & CDNs and appease YSlow
|
3
|
-
|
4
|
-
Scenario: Rendering css with the feature enabled
|
5
|
-
Given "cache_buster" feature is "enabled"
|
6
|
-
When I go to "/stylesheets/relative_assets.css"
|
7
|
-
Then I should see "?"
|
8
|
-
|
9
|
-
Scenario: Rendering html with the feature enabled
|
10
|
-
Given "cache_buster" feature is "enabled"
|
11
|
-
When I go to "/cache-buster.html"
|
12
|
-
Then I should not see "?"
|
13
3
|
|
14
4
|
Scenario: Rendering css with the feature disabled
|
15
5
|
Given "cache_buster" feature is "disabled"
|
@@ -19,4 +9,14 @@ Feature: Generate mtime-based query string for busting browser caches
|
|
19
9
|
Scenario: Rendering html with the feature disabled
|
20
10
|
Given "cache_buster" feature is "disabled"
|
21
11
|
When I go to "/cache-buster.html"
|
12
|
+
Then I should not see "?"
|
13
|
+
|
14
|
+
Scenario: Rendering css with the feature enabled
|
15
|
+
Given "cache_buster" feature is "enabled"
|
16
|
+
When I go to "/stylesheets/relative_assets.css"
|
17
|
+
Then I should see "?"
|
18
|
+
|
19
|
+
Scenario: Rendering html with the feature enabled
|
20
|
+
Given "cache_buster" feature is "enabled"
|
21
|
+
When I go to "/cache-buster.html"
|
22
22
|
Then I should not see "?"
|
data/features/minify_css.feature
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
Feature: Minify CSS
|
2
2
|
In order reduce bytes sent to client and appease YSlow
|
3
|
-
|
4
|
-
Scenario: Rendering inline css with the feature enabled
|
5
|
-
Given "minify_css" feature is "enabled"
|
6
|
-
When I go to "/inline-css.html"
|
7
|
-
Then I should see "1" lines
|
8
3
|
|
9
4
|
Scenario: Rendering inline css with the feature disabled
|
10
5
|
Given "minify_css" feature is "disabled"
|
11
6
|
When I go to "/inline-css.html"
|
12
7
|
Then I should see "4" lines
|
13
8
|
|
14
|
-
Scenario: Rendering external css with the feature
|
15
|
-
Given "minify_css" feature is "
|
9
|
+
Scenario: Rendering external css with the feature disabled
|
10
|
+
Given "minify_css" feature is "disabled"
|
16
11
|
When I go to "/stylesheets/site.css"
|
12
|
+
Then I should see "51" lines
|
13
|
+
|
14
|
+
Scenario: Rendering inline css with the feature enabled
|
15
|
+
Given "minify_css" feature is "enabled"
|
16
|
+
When I go to "/inline-css.html"
|
17
17
|
Then I should see "1" lines
|
18
18
|
|
19
|
-
Scenario: Rendering external css with the feature
|
20
|
-
Given "minify_css" feature is "
|
19
|
+
Scenario: Rendering external css with the feature enabled
|
20
|
+
Given "minify_css" feature is "enabled"
|
21
21
|
When I go to "/stylesheets/site.css"
|
22
|
-
Then I should see "
|
22
|
+
Then I should see "1" lines
|
@@ -1,12 +1,12 @@
|
|
1
1
|
Feature: Minify Javascript
|
2
2
|
In order reduce bytes sent to client and appease YSlow
|
3
3
|
|
4
|
-
Scenario: Rendering inline js with the feature enabled
|
5
|
-
Given "minify_javascript" feature is "enabled"
|
6
|
-
When I go to "/inline-js.html"
|
7
|
-
Then I should see "1" lines
|
8
|
-
|
9
4
|
Scenario: Rendering inline js with the feature disabled
|
10
5
|
Given "minify_javascript" feature is "disabled"
|
11
6
|
When I go to "/inline-js.html"
|
12
|
-
Then I should see "10" lines
|
7
|
+
Then I should see "10" lines
|
8
|
+
|
9
|
+
Scenario: Rendering inline js with the feature enabled
|
10
|
+
Given "minify_javascript" feature is "enabled"
|
11
|
+
When I go to "/inline-js.html"
|
12
|
+
Then I should see "1" lines
|
@@ -23,6 +23,6 @@ Then /^I should not see "([^\"]*)"$/ do |expected|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
Then /^I should see "([^\"]*)" lines$/ do |lines|
|
26
|
-
puts @browser.last_response.body
|
26
|
+
$stderr.puts @browser.last_response.body
|
27
27
|
@browser.last_response.body.chomp.split($/).length.should == lines.to_i
|
28
28
|
end
|
data/lib/middleman.rb
CHANGED
@@ -4,22 +4,5 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
4
4
|
require 'rubygems'
|
5
5
|
|
6
6
|
module Middleman
|
7
|
-
|
8
|
-
module Rack
|
9
|
-
autoload :Sprockets, "middleman/rack/sprockets"
|
10
|
-
autoload :MinifyJavascript, "middleman/rack/minify_javascript"
|
11
|
-
autoload :MinifyCSS, "middleman/rack/minify_css"
|
12
|
-
end
|
13
|
-
|
14
|
-
module Renderers
|
15
|
-
autoload :ERb, "middleman/renderers/erb"
|
16
|
-
autoload :Builder, "middleman/renderers/builder"
|
17
|
-
autoload :Less, "middleman/renderers/less"
|
18
|
-
end
|
19
|
-
|
20
|
-
autoload :Base, "middleman/base"
|
21
|
-
autoload :Haml, "middleman/renderers/haml"
|
22
|
-
autoload :Sass, "middleman/renderers/sass"
|
23
|
-
autoload :Helpers, "middleman/helpers"
|
24
|
-
|
7
|
+
autoload :Base, "middleman/base"
|
25
8
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Assets
|
3
|
+
@@asset_handler_map = []
|
4
|
+
@@asset_handler_stack = []
|
5
|
+
|
6
|
+
def self.register(handler_name, &block)
|
7
|
+
if block_given?
|
8
|
+
@@asset_handler_stack << block
|
9
|
+
@@asset_handler_map << handler_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_url(path, prefix="", request=nil)
|
14
|
+
@@asset_handler_stack.last.call(path, prefix, request)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.before(position, *args)
|
18
|
+
current_index = @@asset_handler_map.index(position)
|
19
|
+
return nil unless current_index
|
20
|
+
|
21
|
+
previous = current_index - 1
|
22
|
+
if (previous >= 0) && (previous < @@asset_handler_map.length)
|
23
|
+
@@asset_handler_stack[previous].call(*args)
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Middleman::Assets.register :base do |path, prefix, request|
|
32
|
+
path.include?("://") ? path : File.join(Middleman::Base.http_prefix || "/", prefix, path)
|
33
|
+
end
|
data/lib/middleman/base.rb
CHANGED
@@ -7,7 +7,6 @@ class Sinatra::Request
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module Middleman
|
10
|
-
module Rack; end
|
11
10
|
class Base < Sinatra::Base
|
12
11
|
set :app_file, __FILE__
|
13
12
|
set :root, ENV["MM_DIR"] || Dir.pwd
|
@@ -15,7 +14,6 @@ module Middleman
|
|
15
14
|
set :sessions, false
|
16
15
|
set :logging, false
|
17
16
|
set :environment, ENV['MM_ENV'] || :development
|
18
|
-
set :supported_formats, %w(erb)
|
19
17
|
set :index_file, "index.html"
|
20
18
|
set :js_dir, "javascripts"
|
21
19
|
set :css_dir, "stylesheets"
|
@@ -42,10 +40,9 @@ module Middleman
|
|
42
40
|
def self.set(option, value=self, &block)
|
43
41
|
if block_given?
|
44
42
|
value = Proc.new { block }
|
45
|
-
super(option, value, &nil)
|
46
|
-
else
|
47
|
-
super
|
48
43
|
end
|
44
|
+
|
45
|
+
super(option, value, &nil)
|
49
46
|
end
|
50
47
|
|
51
48
|
@@afters = []
|
@@ -58,22 +55,6 @@ module Middleman
|
|
58
55
|
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
59
56
|
::Rack::Mime::MIME_TYPES[ext.to_s] = type
|
60
57
|
end
|
61
|
-
|
62
|
-
# Convenience function to discover if a template exists for the requested renderer (haml, sass, etc)
|
63
|
-
def template_exists?(path, renderer=nil)
|
64
|
-
template_path = path.dup
|
65
|
-
template_path << ".#{renderer}" if renderer
|
66
|
-
File.readable? File.join(settings.views, template_path)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Base case renderer (do nothing), Should be over-ridden
|
70
|
-
module StaticRender
|
71
|
-
def render_path(path, layout)
|
72
|
-
return false if !template_exists?(path, :erb)
|
73
|
-
erb(path.to_sym, :layout => layout)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
include StaticRender
|
77
58
|
|
78
59
|
@@layout = nil
|
79
60
|
def self.page(url, options={}, &block)
|
@@ -106,7 +87,7 @@ module Middleman
|
|
106
87
|
not_found do
|
107
88
|
process_request
|
108
89
|
end
|
109
|
-
|
90
|
+
|
110
91
|
private
|
111
92
|
def process_request(layout = :layout)
|
112
93
|
# Normalize the path and add index if we're looking at a directory
|
@@ -114,44 +95,33 @@ module Middleman
|
|
114
95
|
path << settings.index_file if path.match(%r{/$})
|
115
96
|
path.gsub!(%r{^/}, '')
|
116
97
|
|
117
|
-
|
118
|
-
if
|
98
|
+
template_path = locate_template_file(path)
|
99
|
+
if template_path
|
119
100
|
content_type mime_type(File.extname(path)), :charset => 'utf-8'
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
101
|
+
|
102
|
+
renderer = Middleman::Renderers.get_method(template_path)
|
103
|
+
if respond_to? renderer
|
104
|
+
status 200
|
105
|
+
return send(renderer, path.to_sym, { :layout => layout })
|
106
|
+
end
|
124
107
|
end
|
108
|
+
|
109
|
+
status 404
|
110
|
+
end
|
111
|
+
|
112
|
+
def locate_template_file(path)
|
113
|
+
template_path = File.join(settings.views, "#{path}.*")
|
114
|
+
Dir.glob(template_path).first
|
125
115
|
end
|
126
116
|
end
|
127
117
|
end
|
128
118
|
|
129
|
-
require "middleman/
|
130
|
-
require "middleman/renderers
|
131
|
-
require "middleman/
|
132
|
-
require "middleman/renderers/less"
|
133
|
-
require "middleman/renderers/builder"
|
119
|
+
require "middleman/assets"
|
120
|
+
require "middleman/renderers"
|
121
|
+
require "middleman/features"
|
134
122
|
|
123
|
+
# The Rack App
|
135
124
|
class Middleman::Base
|
136
|
-
helpers Middleman::Helpers
|
137
|
-
|
138
|
-
# Features disabled by default
|
139
|
-
enable :asset_host
|
140
|
-
disable :slickmap
|
141
|
-
disable :cache_buster
|
142
|
-
disable :minify_css
|
143
|
-
disable :minify_javascript
|
144
|
-
disable :relative_assets
|
145
|
-
disable :smush_pngs
|
146
|
-
disable :automatic_image_sizes
|
147
|
-
disable :relative_assets
|
148
|
-
disable :cache_buster
|
149
|
-
disable :ugly_haml
|
150
|
-
|
151
|
-
# Default build features
|
152
|
-
configure :build do
|
153
|
-
end
|
154
|
-
|
155
125
|
def self.new(*args, &block)
|
156
126
|
# Check for and evaluate local configuration
|
157
127
|
local_config = File.join(self.root, "init.rb")
|
@@ -164,22 +134,11 @@ class Middleman::Base
|
|
164
134
|
# loop over enabled feature
|
165
135
|
features.flatten.each do |feature_name|
|
166
136
|
next unless send(:"#{feature_name}?")
|
167
|
-
|
168
|
-
|
169
|
-
if File.exists? File.join(File.dirname(__FILE__), "#{feature_path}.rb")
|
170
|
-
puts "== Enabling: #{feature_name.to_s.capitalize}" if logging?
|
171
|
-
require "middleman/#{feature_path}"
|
172
|
-
end
|
137
|
+
$stderr.puts "== Enabling: #{feature_name.to_s.capitalize}" if logging?
|
138
|
+
Middleman::Features.run(feature_name, self)
|
173
139
|
end
|
174
140
|
|
175
|
-
use ::Rack::ConditionalGet
|
176
|
-
use Middleman::Rack::MinifyJavascript if minify_javascript?
|
177
|
-
use Middleman::Rack::MinifyCSS if minify_css?
|
178
|
-
|
179
|
-
# Built-in javascript combination
|
180
|
-
use Middleman::Rack::Sprockets, :root => Middleman::Base.root,
|
181
|
-
:load_path => [ File.join("public", Middleman::Base.js_dir),
|
182
|
-
File.join("views", Middleman::Base.js_dir) ]
|
141
|
+
use ::Rack::ConditionalGet if environment == :development
|
183
142
|
|
184
143
|
@@afters.each { |block| class_eval(&block) }
|
185
144
|
|
data/lib/middleman/builder.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'middleman/base'
|
1
2
|
require 'templater'
|
2
3
|
require 'middleman/templater+dynamic_renderer.rb'
|
3
4
|
|
4
5
|
# Placeholder for any methods the builder needs to abstract to allow feature integration
|
5
6
|
module Middleman
|
6
7
|
class Builder < ::Templater::Generator
|
8
|
+
|
9
|
+
@@template_extensions = ::Tilt.mappings.keys << "js"
|
10
|
+
|
7
11
|
# Define source and desintation
|
8
12
|
def self.source_root; Dir.pwd; end
|
9
13
|
def destination_root; File.join(Dir.pwd, Middleman::Base.build_dir); end
|
@@ -28,7 +32,8 @@ module Middleman
|
|
28
32
|
|
29
33
|
def self.file(name, *args, &block)
|
30
34
|
file_ext = File.extname(args[0])
|
31
|
-
|
35
|
+
|
36
|
+
return unless ::Tilt[file_ext].nil?
|
32
37
|
|
33
38
|
if (args[0] === args[1])
|
34
39
|
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "").gsub("#{File.basename(Middleman::Base.public)}/", "")
|
@@ -37,9 +42,8 @@ module Middleman
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def self.init!
|
40
|
-
glob! File.basename(Middleman::Base.public),
|
41
|
-
glob! File.basename(Middleman::Base.views),
|
42
|
-
glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats - %w(sass js)
|
45
|
+
glob! File.basename(Middleman::Base.public), @@template_extensions
|
46
|
+
glob! File.basename(Middleman::Base.views), @@template_extensions
|
43
47
|
end
|
44
48
|
|
45
49
|
def after_run
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Features
|
3
|
+
# Top-level method to register a new feature
|
4
|
+
@@features = {}
|
5
|
+
def self.register(feature_name, feature_class=nil, options={})
|
6
|
+
@@features[feature_name] = feature_class
|
7
|
+
|
8
|
+
# Default to disabled, unless the class asks to auto-enable
|
9
|
+
activate_method = (options.has_key?(:auto_enable) && options[:auto_enable]) ? :enable : :disable
|
10
|
+
Middleman::Base.send(activate_method, feature_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run(feature_name, scope)
|
14
|
+
feature_class = @@features[feature_name]
|
15
|
+
feature_class.new(scope) unless feature_class.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all
|
19
|
+
@@features
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# livereload
|
26
|
+
%w(asset_host
|
27
|
+
automatic_image_sizes
|
28
|
+
cache_buster
|
29
|
+
default_helpers
|
30
|
+
minify_css
|
31
|
+
minify_javascript
|
32
|
+
relative_assets
|
33
|
+
slickmap
|
34
|
+
smush_pngs
|
35
|
+
ugly_haml).each do |feature|
|
36
|
+
|
37
|
+
require File.join("middleman/features", feature)
|
38
|
+
|
39
|
+
end
|