middleman 0.99.1.pre → 0.99.2.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/Rakefile +9 -17
  2. data/VERSION +1 -1
  3. data/features/builder.feature +16 -0
  4. data/features/coffee-script.feature +7 -0
  5. data/features/helpers_auto_stylesheet_link_tag.feature +17 -0
  6. data/features/helpers_page_classes.feature +17 -0
  7. data/features/less-css.feature +7 -0
  8. data/features/padrino_helpers.feature +10 -0
  9. data/features/scss-support.feature +7 -0
  10. data/features/step_definitions/asset_host_steps.rb +1 -1
  11. data/features/step_definitions/builder_steps.rb +45 -0
  12. data/features/step_definitions/env.rb +1 -1
  13. data/features/step_definitions/generator_steps.rb +9 -3
  14. data/features/step_definitions/middleman_steps.rb +8 -6
  15. data/features/step_definitions/page_layout_steps.rb +2 -2
  16. data/features/{asset_host.feature → w_asset_host.feature} +0 -0
  17. data/features/{automatic_image_sizes.feature → x_automatic_image_sizes.feature} +0 -0
  18. data/features/{cache_buster.feature → y_cache_buster.feature} +0 -0
  19. data/features/{relative_assets.feature → z_relative_assets.feature} +0 -0
  20. data/{spec/fixtures/sample → fixtures/test-app}/config.rb +0 -0
  21. data/{spec/fixtures/sample → fixtures/test-app}/public/images/blank.gif +0 -0
  22. data/{spec/fixtures/sample → fixtures/test-app}/public/static.html +0 -0
  23. data/{spec/fixtures/sample → fixtures/test-app}/public/stylesheets/auto-css.css +0 -0
  24. data/{spec/fixtures/sample → fixtures/test-app}/public/stylesheets/static.css +0 -0
  25. data/{spec/fixtures/sample → fixtures/test-app}/public/stylesheets/sub1/auto-css.css +0 -0
  26. data/{spec/fixtures/sample → fixtures/test-app}/public/stylesheets/sub1/sub2/auto-css.css +0 -0
  27. data/{spec/fixtures/sample → fixtures/test-app}/views/_partial.haml +0 -0
  28. data/{spec/fixtures/sample → fixtures/test-app}/views/asset_host.html.haml +0 -0
  29. data/{spec/fixtures/sample → fixtures/test-app}/views/auto-css.html.haml +0 -0
  30. data/{spec/fixtures/sample → fixtures/test-app}/views/auto-image-sizes.html.haml +0 -0
  31. data/{spec/fixtures/sample → fixtures/test-app}/views/cache-buster.html.haml +0 -0
  32. data/{spec/fixtures/sample → fixtures/test-app}/views/custom-layout.html.haml +0 -0
  33. data/{spec/fixtures/sample → fixtures/test-app}/views/index.html.haml +0 -0
  34. data/{spec/fixtures/sample → fixtures/test-app}/views/inline-css.html.haml +0 -0
  35. data/{spec/fixtures/sample → fixtures/test-app}/views/inline-js.html.haml +0 -0
  36. data/fixtures/test-app/views/javascripts/coffee_test.js.coffee +3 -0
  37. data/{spec/fixtures/sample → fixtures/test-app}/views/layout.haml +0 -0
  38. data/{spec/fixtures/sample/views → fixtures/test-app/views/layouts}/custom.haml +0 -0
  39. data/fixtures/test-app/views/padrino_test.html.haml +5 -0
  40. data/{spec/fixtures/sample → fixtures/test-app}/views/page-classes.html.haml +0 -0
  41. data/{spec/fixtures/sample → fixtures/test-app}/views/services/index.html.haml +0 -0
  42. data/{spec/fixtures/sample → fixtures/test-app}/views/stylesheets/asset_host.css.sass +0 -0
  43. data/{spec/fixtures/sample → fixtures/test-app}/views/stylesheets/relative_assets.css.sass +0 -0
  44. data/{spec/fixtures/sample → fixtures/test-app}/views/stylesheets/site.css.sass +0 -0
  45. data/{spec/fixtures/sample → fixtures/test-app}/views/stylesheets/site_scss.css.scss +0 -0
  46. data/{spec/fixtures/sample → fixtures/test-app}/views/stylesheets/test_less.css.less +0 -0
  47. data/lib/middleman.rb +9 -1
  48. data/lib/middleman/features.rb +29 -36
  49. data/lib/middleman/features/asset_host.rb +16 -15
  50. data/lib/middleman/features/automatic_image_sizes.rb +26 -24
  51. data/lib/middleman/features/cache_buster.rb +34 -33
  52. data/lib/middleman/features/default_helpers.rb +26 -33
  53. data/lib/middleman/features/livereload.rb +1 -1
  54. data/lib/middleman/features/minify_css.rb +8 -7
  55. data/lib/middleman/features/minify_javascript.rb +11 -10
  56. data/lib/middleman/features/relative_assets.rb +30 -29
  57. data/lib/middleman/features/slickmap.rb +43 -42
  58. data/lib/middleman/features/smush_pngs.rb +29 -29
  59. data/lib/middleman/features/ugly_haml.rb +7 -6
  60. data/lib/middleman/renderers/{coffee.rb → coffee_script.rb} +11 -8
  61. data/lib/middleman/renderers/haml.rb +28 -33
  62. data/lib/middleman/renderers/sass.rb +30 -28
  63. data/lib/middleman/server.rb +44 -49
  64. data/lib/middleman/template/config.rbt +6 -6
  65. data/middleman.gemspec +49 -50
  66. metadata +79 -75
  67. data/lib/middleman/renderers.rb +0 -26
  68. data/spec/builder_spec.rb +0 -62
  69. data/spec/fixtures/sample/views/maruku.html.maruku +0 -1
  70. data/spec/helpers_spec.rb +0 -43
  71. data/spec/spec_helper.rb +0 -8
@@ -1,38 +1,38 @@
1
- class Middleman::Features::SmushPngs
2
- def initialize(app, config)
3
- require "middleman/builder"
1
+ module Middleman::Features::SmushPNGs
2
+ class << self
3
+ def registered(app)
4
+ require "middleman/builder"
4
5
 
5
- Middleman::Server.alias_method :pre_smush_after_run, :after_run
6
- Middleman::Server.define_method :after_run do
7
- pre_smush_after_run
8
- smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
6
+ app.alias_method :pre_smush_after_run, :after_run
7
+ app.define_method :after_run do
8
+ pre_smush_after_run
9
+ smush_dir = File.join(Middleman::Server.build_dir, Middleman::Server.images_dir)
9
10
 
10
- # Read cache
11
- cache_file = File.join(Middleman::Server.root, ".smush-cache")
12
- cache_data = if File.exists?(cache_file)
13
- Marshal.restore(File.read(cache_file))
14
- else
15
- {}
16
- end
11
+ # Read cache
12
+ cache_file = File.join(Middleman::Server.root, ".smush-cache")
13
+ cache_data = if File.exists?(cache_file)
14
+ Marshal.restore(File.read(cache_file))
15
+ else
16
+ {}
17
+ end
17
18
 
18
- require "smusher"
19
- require "json/pure"
20
- ::Smusher.class_eval do
21
- images_in_folder(smush_dir).each do |file|
22
- original_file_size = size(file)
23
- return if original_file_size.zero?
24
- return if cache_data[file] && cache_data[file] == original_file_size
19
+ require "smusher"
20
+ require "json/pure"
21
+ ::Smusher.class_eval do
22
+ images_in_folder(smush_dir).each do |file|
23
+ original_file_size = size(file)
24
+ return if original_file_size.zero?
25
+ return if cache_data[file] && cache_data[file] == original_file_size
25
26
 
26
- with_logging(file, true) do
27
- write_optimized_data(file)
28
- cache_data[file] = size(file) # Add or update cache
29
- File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
30
- say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Server.build_dir+"/", '')
27
+ with_logging(file, true) do
28
+ write_optimized_data(file)
29
+ cache_data[file] = size(file) # Add or update cache
30
+ File.open(cache_file, "w") { |f| f.write Marshal.dump(cache_data) } # Write cache
31
+ say "<%= color('#{"[SMUSHED]".rjust(12)}', :yellow) %> " + file.gsub(Middleman::Server.build_dir+"/", '')
32
+ end
31
33
  end
32
34
  end
33
35
  end
34
36
  end
35
37
  end
36
- end
37
-
38
- Middleman::Features.register :smush_pngs, Middleman::Features::SmushPngs
38
+ end
@@ -1,7 +1,8 @@
1
- class Middleman::Features::UglyHaml
2
- def initialize(app, config)
3
- Middleman::Server.set :haml, Middleman::Server.settings.haml.merge({ :ugly_haml => true })
1
+ module Middleman::Features::UglyHaml
2
+ class << self
3
+ def registered(app)
4
+ app.set :haml, app.settings.haml.merge({ :ugly_haml => true })
5
+ end
6
+ alias :included :registered
4
7
  end
5
- end
6
-
7
- Middleman::Features.register :ugly_haml, Middleman::Features::UglyHaml
8
+ end
@@ -1,7 +1,13 @@
1
- class Middleman::Server
2
- def coffee(template, options={}, locals={})
3
- options[:layout] = false
4
- render :coffee, template, options, locals
1
+ module Middleman
2
+ module Renderers
3
+ module CoffeeScript
4
+ class << self
5
+ def registered(app)
6
+ Tilt.register 'coffee', Tilt::CoffeeTemplate
7
+ end
8
+ alias :included :registered
9
+ end
10
+ end
5
11
  end
6
12
  end
7
13
 
@@ -22,7 +28,4 @@ unless defined? Tilt::CoffeeTemplate
22
28
  @output ||= ::CoffeeScript::compile(data, options)
23
29
  end
24
30
  end
25
- Tilt.register 'coffee', Tilt::CoffeeTemplate
26
- end
27
-
28
- Middleman::Renderers.register(:coffee, Tilt::CoffeeTemplate)
31
+ end
@@ -1,47 +1,42 @@
1
1
  require "haml"
2
2
 
3
3
  module Middleman
4
- module Haml
5
- module Helpers
6
- def haml_partial(name, options = {})
7
- item_name = name.to_sym
8
- counter_name = "#{name}_counter".to_sym
9
- if collection = options.delete(:collection)
10
- collection.enum_for(:each_with_index).collect do |item,index|
11
- haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
12
- end.join
13
- elsif object = options.delete(:object)
14
- haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
15
- else
16
- haml "_#{name}".to_sym, options.merge(:layout => false)
4
+ module Renderers
5
+ module Haml
6
+ class << self
7
+ def registered(app)
8
+ app.helpers Middleman::Renderers::Haml::Helpers
9
+ end
10
+ alias :included :registered
11
+ end
12
+
13
+ module Helpers
14
+ def haml_partial(name, options = {})
15
+ partial(name, options)
17
16
  end
18
17
  end
19
- end
20
18
 
21
- module Table
22
- include ::Haml::Filters::Base
19
+ module Table
20
+ include ::Haml::Filters::Base
23
21
 
24
- def render(text)
25
- output = '<div class="table"><table cellspacing="0" cellpadding="0">'
26
- line_num = 0
27
- text.each_line do |line|
28
- line_num += 1
29
- next if line.strip.empty?
30
- output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
22
+ def render(text)
23
+ output = '<div class="table"><table cellspacing="0" cellpadding="0">'
24
+ line_num = 0
25
+ text.each_line do |line|
26
+ line_num += 1
27
+ next if line.strip.empty?
28
+ output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
31
29
 
32
- columns = line.split("|").map { |p| p.strip }
33
- columns.each_with_index do |col, i|
34
- output << %Q{<td class="col#{i+1}">#{col}</td>}
35
- end
30
+ columns = line.split("|").map { |p| p.strip }
31
+ columns.each_with_index do |col, i|
32
+ output << %Q{<td class="col#{i+1}">#{col}</td>}
33
+ end
36
34
 
37
- output << "</tr>"
35
+ output << "</tr>"
36
+ end
37
+ output + "</table></div>"
38
38
  end
39
- output + "</table></div>"
40
39
  end
41
40
  end
42
41
  end
43
- end
44
-
45
- class Middleman::Server
46
- helpers Middleman::Haml::Helpers
47
42
  end
@@ -1,32 +1,36 @@
1
1
  require "sass"
2
2
  require "compass"
3
3
 
4
- class Middleman::Server
5
- def scss(template, options={}, locals={})
6
- options[:layout] = false
7
- render :scss, template, options, locals
8
- end
4
+ module Middleman
5
+ module Renderers
6
+ module Sass
7
+ class << self
8
+ def registered(app)
9
+ app.after_feature_init do
10
+ ::Compass.configuration do |config|
11
+ config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
12
+ config.project_path = self.root
13
+ config.sass_dir = File.join(File.basename(self.views), self.css_dir)
14
+ config.output_style = :nested
15
+ config.fonts_dir = File.join(File.basename(self.public), self.fonts_dir)
16
+ config.css_dir = File.join(File.basename(self.public), self.css_dir)
17
+ config.images_dir = File.join(File.basename(self.public), self.images_dir)
18
+ config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir)
19
+ config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir)
20
+ config.asset_cache_buster { false }
9
21
 
10
- after_feature_init do
11
- ::Compass.configuration do |config|
12
- config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
13
- config.project_path = self.root
14
- config.sass_dir = File.join(File.basename(self.views), self.css_dir)
15
- config.output_style = :nested
16
- config.fonts_dir = File.join(File.basename(self.public), self.fonts_dir)
17
- config.css_dir = File.join(File.basename(self.public), self.css_dir)
18
- config.images_dir = File.join(File.basename(self.public), self.images_dir)
19
- config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir)
20
- config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir)
21
- config.asset_cache_buster { false }
22
-
23
- config.add_import_path(config.sass_dir)
24
- end
25
-
26
- configure :build do
27
- ::Compass.configuration do |config|
28
- config.css_dir = File.join(File.basename(self.build_dir), self.css_dir)
29
- config.images_dir = File.join(File.basename(self.build_dir), self.images_dir)
22
+ config.add_import_path(config.sass_dir)
23
+ end
24
+
25
+ configure :build do
26
+ ::Compass.configuration do |config|
27
+ config.css_dir = File.join(File.basename(self.build_dir), self.css_dir)
28
+ config.images_dir = File.join(File.basename(self.build_dir), self.images_dir)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ alias :included :registered
30
34
  end
31
35
  end
32
36
  end
@@ -45,7 +49,6 @@ class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
45
49
  end
46
50
  end
47
51
  Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
48
- Middleman::Renderers.register(:sass, Tilt::SassPlusCSSFilenameTemplate)
49
52
 
50
53
  class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
51
54
  def sass_options
@@ -53,10 +56,9 @@ class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
53
56
  end
54
57
  end
55
58
  Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
56
- Middleman::Renderers.register(:scss, Tilt::ScssPlusCSSFilenameTemplate)
57
59
 
58
60
 
59
- module Middleman::Haml
61
+ module Middleman::Renderers::Haml
60
62
  module Sass
61
63
  include ::Haml::Filters::Base
62
64
 
@@ -1,14 +1,9 @@
1
1
  # We're riding on Sinatra, so let's include it.
2
2
  require "sinatra/base"
3
3
 
4
- # The content_for plugin allows Sinatra to use the throw/yield block
5
- # system similar to Rails views.
6
- require "sinatra/content_for"
7
-
8
- # Monkey-patch Sinatra to expose the layout parameter
9
- class Sinatra::Request
10
- attr_accessor :layout
11
- end
4
+ # Use the padrino project's helpers
5
+ require "padrino-core/application/rendering"
6
+ require "padrino-helpers"
12
7
 
13
8
  module Middleman
14
9
  class Server < Sinatra::Base
@@ -20,8 +15,7 @@ module Middleman
20
15
  set :logging, false
21
16
  set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
22
17
 
23
- # Import content_for methods
24
- helpers Sinatra::ContentFor
18
+ # Import padrino helper methods
25
19
 
26
20
  # Middleman-specific options
27
21
  set :index_file, "index.html" # What file responds to folder requests
@@ -36,20 +30,18 @@ module Middleman
36
30
  set :build_dir, "build" # Which folder are builds output to
37
31
  set :http_prefix, nil # During build, add a prefix for absolute paths
38
32
 
39
- # A hash of enabled features
40
- @@enabled_features = {}
33
+ # Use Padrino Helpers
34
+ register Padrino::Helpers
35
+ set :asset_stamp, false # Disable Padrino cache buster until explicitly enabled
41
36
 
42
- # Override Sinatra's enable to keep track of enabled features
43
- def self.enable(feature_name, config={})
44
- @@enabled_features[feature_name] = config
45
- super(feature_name)
46
- end
37
+ # Activate custom features
38
+ register Middleman::Features
47
39
 
48
- # Disable a feature, then pass to Sinatra's method
49
- def self.disable(feature_name)
50
- @@enabled_features.delete(feature_name)
51
- super(feature_name)
52
- end
40
+ # Activate built-in helpers
41
+ register Middleman::Features::DefaultHelpers
42
+
43
+ # Tilt-aware renderer
44
+ register Padrino::Rendering
53
45
 
54
46
  # Override Sinatra's set to accept a block
55
47
  def self.set(option, value=self, &block)
@@ -68,37 +60,48 @@ module Middleman
68
60
  @@run_after_features << block
69
61
  end
70
62
 
63
+ # Activate custom renderers
64
+ register Middleman::Renderers::CoffeeScript
65
+ register Middleman::Renderers::Haml
66
+ register Middleman::Renderers::Sass
67
+
71
68
  # Rack helper for adding mime-types during local preview
72
69
  def self.mime(ext, type)
73
70
  ext = ".#{ext}" unless ext.to_s[0] == ?.
74
71
  ::Rack::Mime::MIME_TYPES[ext.to_s] = type
75
72
  end
76
73
 
77
- # Keep track of a block-specific layout
78
- @@layout = nil
74
+ # Default layout name
75
+ layout :layout
76
+
77
+ def self.current_layout
78
+ @layout
79
+ end
79
80
 
80
81
  # Takes a block which allows many pages to have the same layout
81
82
  # with_layout :admin do
82
83
  # page "/admin/"
83
84
  # page "/admin/login.html"
84
85
  # end
85
- def self.with_layout(layout, &block)
86
- @@layout = layout
86
+ def self.with_layout(layout_name, &block)
87
+ old_layout = current_layout
88
+
89
+ layout(layout_name)
87
90
  class_eval(&block) if block_given?
88
91
  ensure
89
- @@layout = nil
92
+ layout(old_layout)
90
93
  end
91
94
 
92
95
  # The page method allows the layout to be set on a specific path
93
96
  # page "/about.html", :layout => false
94
97
  # page "/", :layout => :homepage_layout
95
98
  def self.page(url, options={}, &block)
96
- layout = @@layout
97
- layout = options[:layout] if !options[:layout].nil?
98
-
99
+ url << settings.index_file if url.match(%r{/$})
100
+
101
+ options[:layout] ||= current_layout
99
102
  get(url) do
100
103
  return yield if block_given?
101
- process_request(layout)
104
+ process_request(options)
102
105
  end
103
106
  end
104
107
 
@@ -109,20 +112,21 @@ module Middleman
109
112
 
110
113
  private
111
114
  # Internal method to look for templates and evaluate them if found
112
- def process_request(layout = :layout)
115
+ def process_request(options={})
113
116
  # Normalize the path and add index if we're looking at a directory
114
117
  path = request.path
115
118
  path << settings.index_file if path.match(%r{/$})
116
119
  path.gsub!(%r{^/}, '')
117
-
118
- if template_path = Dir.glob(File.join(settings.views, "#{path}.*")).first
120
+
121
+ old_layout = settings.current_layout
122
+ settings.layout(options[:layout]) if !options[:layout].nil?
123
+ result = render(path, :layout => settings.fetch_layout_path.to_sym)
124
+ settings.layout(old_layout)
125
+
126
+ if result
119
127
  content_type mime_type(File.extname(path)), :charset => 'utf-8'
120
-
121
- renderer = Middleman::Renderers.get_method(template_path)
122
- if respond_to? renderer
123
- status 200
124
- return send(renderer, path.to_sym, { :layout => layout })
125
- end
128
+ status 200
129
+ return result
126
130
  end
127
131
 
128
132
  status 404
@@ -131,8 +135,6 @@ module Middleman
131
135
  end
132
136
 
133
137
  require "middleman/assets"
134
- require "middleman/renderers"
135
- require "middleman/features"
136
138
 
137
139
  # The Rack App
138
140
  class Middleman::Server
@@ -152,13 +154,6 @@ class Middleman::Server
152
154
  set :app_file, File.expand_path(local_config)
153
155
  end
154
156
 
155
- # loop over enabled feature
156
- @@enabled_features.each do |feature_name, feature_config|
157
- next unless send(:"#{feature_name}?")
158
- $stderr.puts "== Enabling: #{feature_name.to_s.capitalize}" if logging?
159
- Middleman::Features.run(feature_name, feature_config, self)
160
- end
161
-
162
157
  use ::Rack::ConditionalGet if environment == :development
163
158
 
164
159
  @@run_after_features.each { |block| class_eval(&block) }
@@ -1,8 +1,8 @@
1
1
  # Automatic sitemaps
2
- # enable :slickmap
2
+ # activate :slickmap
3
3
 
4
4
  # Automatic image dimension calculations
5
- # enable :automatic_image_sizes
5
+ # activate :automatic_image_sizes
6
6
 
7
7
  # Per-page layout changes
8
8
  # With no layout
@@ -41,16 +41,16 @@ set :images_dir, "<%= images_dir -%>"
41
41
  # Build-specific configuration
42
42
  configure :build do
43
43
  # For example, change the Compass output style for deployment
44
- # enable :minify_css
44
+ # activate :minify_css
45
45
 
46
46
  # Minify Javascript on build
47
- # enable :minify_javascript
47
+ # activate :minify_javascript
48
48
 
49
49
  # Shrink/smush PNG/JPEGs on build
50
- # enable :smush_pngs
50
+ # activate :smush_pngs
51
51
 
52
52
  # Enable cache buster
53
- # enable :cache_buster
53
+ # activate :cache_buster
54
54
 
55
55
  # Or use a different image path
56
56
  # set :http_path, "/Content/images/"