middleman 2.0.0.rc1 → 2.0.0.rc2

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 (32) hide show
  1. data/README.md +16 -0
  2. data/features/sprockets.feature +6 -0
  3. data/features/step_definitions/builder_steps.rb +1 -1
  4. data/fixtures/test-app/source/index.html.haml +6 -1
  5. data/fixtures/test-app/source/javascripts/sprockets_base.js +5 -0
  6. data/fixtures/test-app/source/javascripts/sprockets_sub.js +3 -0
  7. data/lib/middleman.rb +19 -16
  8. data/lib/middleman/core_extensions/compass.rb +59 -0
  9. data/lib/middleman/core_extensions/features.rb +2 -2
  10. data/lib/middleman/core_extensions/front_matter.rb +13 -0
  11. data/lib/middleman/core_extensions/rack_map.rb +34 -0
  12. data/lib/middleman/core_extensions/routing.rb +5 -9
  13. data/lib/middleman/core_extensions/sprockets.rb +51 -0
  14. data/lib/middleman/features/asset_host.rb +1 -1
  15. data/lib/middleman/features/cache_buster.rb +2 -2
  16. data/lib/middleman/features/live_reload.rb +1 -1
  17. data/lib/middleman/features/minify_css.rb +1 -1
  18. data/lib/middleman/features/minify_javascript.rb +36 -5
  19. data/lib/middleman/renderers/coffee_script.rb +5 -9
  20. data/lib/middleman/renderers/haml.rb +23 -35
  21. data/lib/middleman/renderers/markdown.rb +7 -8
  22. data/lib/middleman/renderers/sass.rb +40 -62
  23. data/lib/middleman/renderers/slim.rb +5 -9
  24. data/lib/middleman/server.rb +39 -17
  25. data/lib/middleman/templates/default/config.tt +19 -11
  26. data/lib/middleman/version.rb +1 -1
  27. data/middleman.gemspec +3 -5
  28. metadata +33 -49
  29. data/README.rdoc +0 -15
  30. data/lib/middleman/features/code_ray.rb +0 -12
  31. data/lib/middleman/features/minify_javascript/rack.rb +0 -57
  32. data/lib/middleman/features/ugly_haml.rb +0 -8
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # middleman
2
+
3
+ The Middleman is ever-vigilant against tag-soup, unreadable CSS and repetition. He stands-watch over your Haml, Sass, and CoffeeScript producing only the cleanest and efficient markup.
4
+
5
+ ## Getting Started
6
+
7
+ Everything you need to know is on the official site:
8
+ http://middlemanapp.com
9
+
10
+ ## Mailing List
11
+
12
+ If you have questions, answers can be found on community forum: https://convore.com/middleman/
13
+
14
+ ## Copyright
15
+
16
+ Copyright (c) 2010 Thomas Reynolds. See LICENSE for details.
@@ -0,0 +1,6 @@
1
+ Feature: Sprockets
2
+
3
+ Scenario: Sprockets require
4
+ Given the Server is running
5
+ When I go to "/javascripts/sprockets_base.js"
6
+ Then I should see "sprockets_sub_function"
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  Given /^cleanup built test app$/ do
16
16
  target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build")
17
- # FileUtils.rm_rf(target)
17
+ FileUtils.rm_rf(target)
18
18
  end
19
19
 
20
20
  Then /^"([^"]*)" should exist and include "([^"]*)"$/ do |target_file, expected|
@@ -1 +1,6 @@
1
- %h1 Welcome
1
+ %h1 Welcome
2
+
3
+ :markdown
4
+ ## H2
5
+
6
+ Paragraph
@@ -0,0 +1,5 @@
1
+ //= require "sprockets_sub"
2
+
3
+ function base() {
4
+
5
+ }
@@ -0,0 +1,3 @@
1
+ function sprockets_sub_function() {
2
+
3
+ }
data/lib/middleman.rb CHANGED
@@ -73,6 +73,9 @@ module Middleman
73
73
  end
74
74
 
75
75
  module CoreExtensions
76
+ # Add Rack::Builder.map support
77
+ autoload :RackMap, "middleman/core_extensions/rack_map"
78
+
76
79
  # Custom Feature API
77
80
  autoload :Features, "middleman/core_extensions/features"
78
81
 
@@ -91,6 +94,12 @@ module Middleman
91
94
 
92
95
  # Extended version of Padrino's rendering
93
96
  autoload :Rendering, "middleman/core_extensions/rendering"
97
+
98
+ # Compass framework for Sass
99
+ autoload :Compass, "middleman/core_extensions/compass"
100
+
101
+ # Sprockets 2
102
+ autoload :Sprockets, "middleman/core_extensions/sprockets"
94
103
 
95
104
  # Pass custom options to views
96
105
  autoload :Routing, "middleman/core_extensions/routing"
@@ -101,34 +110,28 @@ module Middleman
101
110
  # relative to the root of the project or use an absolute URL.
102
111
  autoload :RelativeAssets, "middleman/features/relative_assets"
103
112
 
104
- # AssetHost allows you to setup multiple domains to host your static assets.
105
- # Calls to asset paths in dynamic templates will then rotate through each of
106
- # the asset servers to better spread the load.
113
+ # AssetHost allows you to setup multiple domains to host your static
114
+ # assets. Calls to asset paths in dynamic templates will then rotate
115
+ # through each of the asset servers to better spread the load.
107
116
  autoload :AssetHost, "middleman/features/asset_host"
108
117
 
109
118
  # CacheBuster adds a query string to assets in dynamic templates to avoid
110
119
  # browser caches failing to update to your new content.
111
120
  autoload :CacheBuster, "middleman/features/cache_buster"
112
121
 
113
- # AutomaticImageSizes inspects the images used in your dynamic templates and
114
- # automatically adds width and height attributes to their HTML elements.
122
+ # AutomaticImageSizes inspects the images used in your dynamic templates
123
+ # and automatically adds width and height attributes to their HTML
124
+ # elements.
115
125
  autoload :AutomaticImageSizes, "middleman/features/automatic_image_sizes"
116
126
 
117
- # UglyHaml enables the non-indented output format from Haml templates. Useful
118
- # for somewhat obfuscating the output and hiding the fact that you're using Haml.
119
- autoload :UglyHaml, "middleman/features/ugly_haml"
120
-
121
127
  # MinifyCss uses the YUI compressor to shrink CSS files
122
128
  autoload :MinifyCss, "middleman/features/minify_css"
123
129
 
124
130
  # MinifyJavascript uses the YUI compressor to shrink JS files
125
131
  autoload :MinifyJavascript, "middleman/features/minify_javascript"
126
132
 
127
- # CodeRay is a syntax highlighter.
128
- autoload :CodeRay, "middleman/features/code_ray"
129
-
130
- # Lorem provides a handful of helpful prototyping methods to generate words,
131
- # paragraphs, fake images, names and email addresses.
133
+ # Lorem provides a handful of helpful prototyping methods to generate
134
+ # words, paragraphs, fake images, names and email addresses.
132
135
  autoload :Lorem, "middleman/features/lorem"
133
136
 
134
137
  # Treat project as a blog
@@ -140,8 +143,8 @@ module Middleman
140
143
  # Automatically resize images for mobile devises
141
144
  # autoload :TinySrc, "middleman/features/tiny_src"
142
145
 
143
- # LiveReload will auto-reload browsers with the live reload extension installed after changes
144
- # Currently disabled and untested.
146
+ # LiveReload will auto-reload browsers with the live reload extension
147
+ # installed after changes. Currently disabled and untested.
145
148
  # autoload :LiveReload, "middleman/features/live_reload"
146
149
  end
147
150
  end
@@ -0,0 +1,59 @@
1
+ module Middleman::CoreExtensions::Compass
2
+ class << self
3
+ def registered(app)
4
+ app.extend ClassMethods
5
+
6
+ require "compass"
7
+
8
+ # Susy grids
9
+ begin
10
+ require "susy"
11
+ rescue LoadError
12
+ end
13
+
14
+ app.after_feature_init do
15
+ views_root = File.basename(app.views)
16
+ ::Compass.configuration do |config|
17
+ config.cache = false # For sassc files
18
+ config.project_path = app.root
19
+ config.sass_dir = File.join(views_root, app.css_dir)
20
+ config.output_style = :nested
21
+ config.fonts_dir = File.join(views_root, app.fonts_dir)
22
+ config.css_dir = File.join(views_root, app.css_dir)
23
+ config.images_dir = File.join(views_root, app.images_dir)
24
+ config.http_images_path = app.http_images_path rescue File.join(app.http_prefix || "/", app.images_dir)
25
+ config.http_stylesheets_path = app.http_css_path rescue File.join(app.http_prefix || "/", app.css_dir)
26
+ config.asset_cache_buster :none
27
+
28
+ config.add_import_path(config.sass_dir)
29
+ end
30
+
31
+ # configure :build do
32
+ # build_root = File.basename(self.build_dir)
33
+ # ::Compass.configuration do |config|
34
+ # config.css_dir = File.join(build_root, self.css_dir)
35
+ # config.images_dir = File.join(build_root, self.images_dir)
36
+ # end
37
+ # end
38
+
39
+ app.execute_after_compass_init!
40
+
41
+ app.set :sass, ::Compass.configuration.to_sass_engine_options
42
+ end
43
+ end
44
+ alias :included :registered
45
+ end
46
+
47
+ module ClassMethods
48
+ # Add a block/proc to be run after features have been setup
49
+ def after_compass_init(&block)
50
+ @run_after_compass ||= []
51
+ @run_after_compass << block
52
+ end
53
+
54
+ def execute_after_compass_init!
55
+ @run_after_compass ||= []
56
+ @run_after_compass.each { |block| class_eval(&block) }
57
+ end
58
+ end
59
+ end
@@ -33,7 +33,7 @@ module Middleman::CoreExtensions::Features
33
33
  # The Feature API is itself a Feature. Mind blowing!
34
34
  class << self
35
35
  def registered(app)
36
- app.set :default_extensions, []
36
+ app.set :default_features, []
37
37
  app.extend ClassMethods
38
38
  end
39
39
  alias :included :registered
@@ -84,7 +84,7 @@ module Middleman::CoreExtensions::Features
84
84
  end
85
85
 
86
86
  # Add in defaults
87
- default_extensions.each do |ext|
87
+ default_features.each do |ext|
88
88
  activate ext
89
89
  end
90
90
 
@@ -7,10 +7,20 @@ module Middleman::CoreExtensions::FrontMatter
7
7
  app.extend ClassMethods
8
8
 
9
9
  ::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
10
+ ::Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
11
+ ::Tilt.prefer(RDiscountTemplate)
12
+
10
13
  ::Tilt::register RedClothTemplate, 'textile'
14
+ ::Tilt.prefer(RedClothTemplate)
15
+
11
16
  ::Tilt::register ERBTemplate, 'erb', 'rhtml'
17
+ ::Tilt.prefer(ERBTemplate)
18
+
12
19
  ::Tilt::register SlimTemplate, 'slim'
20
+ ::Tilt.prefer(SlimTemplate)
21
+
13
22
  ::Tilt::register HamlTemplate, 'haml'
23
+ ::Tilt.prefer(HamlTemplate)
14
24
 
15
25
  app.before do
16
26
  result = resolve_template(request.path_info, :raise_exceptions => false)
@@ -64,6 +74,9 @@ module Middleman::CoreExtensions::FrontMatter
64
74
  class RDiscountTemplate < ::Tilt::RDiscountTemplate
65
75
  include Middleman::CoreExtensions::FrontMatter::YamlAware
66
76
  end
77
+ class RedcarpetTemplate < ::Tilt::RedcarpetTemplate
78
+ include Middleman::CoreExtensions::FrontMatter::YamlAware
79
+ end
67
80
 
68
81
  class RedClothTemplate < ::Tilt::RedClothTemplate
69
82
  include Middleman::CoreExtensions::FrontMatter::YamlAware
@@ -0,0 +1,34 @@
1
+ module Middleman::CoreExtensions::RackMap
2
+ class << self
3
+ def registered(app)
4
+ app.extend ClassMethods
5
+ end
6
+ alias :included :registered
7
+ end
8
+
9
+ module ClassMethods
10
+ def map(path, &block)
11
+ @maps ||= []
12
+ @maps << [path, block]
13
+ end
14
+
15
+ def maps
16
+ @maps || []
17
+ end
18
+
19
+ # Creates a Rack::Builder instance with all the middleware set up and
20
+ # an instance of this class as end point.
21
+ def build(*args, &bk)
22
+ builder = ::Rack::Builder.new
23
+ builder.use ::Sinatra::ShowExceptions if show_exceptions?
24
+ builder.use ::Rack::CommonLogger if logging?
25
+ builder.use ::Rack::Head
26
+ middleware.each { |c,a,b| builder.use(c, *a, &b) }
27
+ maps.each { |p,b| builder.map(p, &b) }
28
+ builder.map "/" do
29
+ run Middleman::Server.new!(*args, &bk)
30
+ end
31
+ builder
32
+ end
33
+ end
34
+ end
@@ -11,11 +11,7 @@ module Middleman::CoreExtensions::Routing
11
11
  alias :included :registered
12
12
  end
13
13
 
14
- module ClassMethods
15
- def current_layout
16
- @layout
17
- end
18
-
14
+ module ClassMethods
19
15
  def path_to_index(path)
20
16
  parts = path ? path.split('/') : []
21
17
  if parts.last.nil? || parts.last.split('.').length == 1
@@ -30,12 +26,12 @@ module Middleman::CoreExtensions::Routing
30
26
  # page "/admin/login.html"
31
27
  # end
32
28
  def with_layout(layout_name, &block)
33
- old_layout = current_layout
29
+ old_layout = settings.layout
34
30
 
35
- layout(layout_name)
31
+ set :layout, layout_name
36
32
  class_eval(&block) if block_given?
37
33
  ensure
38
- layout(old_layout)
34
+ set :layout, old_layout
39
35
  end
40
36
 
41
37
  # The page method allows the layout to be set on a specific path
@@ -49,7 +45,7 @@ module Middleman::CoreExtensions::Routing
49
45
  paths << "#{url}/" if url.length > 1 && url.split("/").last.split('.').length <= 1
50
46
  paths << "#{path_to_index(url)}"
51
47
 
52
- options[:layout] = current_layout if options[:layout].nil?
48
+ options[:layout] = settings.layout if options[:layout].nil?
53
49
 
54
50
  paths.each do |p|
55
51
  get(p) do
@@ -0,0 +1,51 @@
1
+ require "sprockets"
2
+
3
+ module Middleman::CoreExtensions::Sprockets
4
+ class << self
5
+ def registered(app)
6
+ app.set :js_compressor, false
7
+
8
+ app.map "/#{app.js_dir}" do
9
+ run JavascriptEnvironment.new(app)
10
+ end
11
+ # app.map "/#{app.css_dir}" do
12
+ # run StylesheetEnvironment.new(app)
13
+ # end
14
+ end
15
+ alias :included :registered
16
+ end
17
+
18
+ class MiddlemanEnvironment < Sprockets::Environment
19
+ def initialize(app)
20
+ super File.expand_path(app.views)
21
+ end
22
+ end
23
+
24
+ class JavascriptEnvironment < MiddlemanEnvironment
25
+ def initialize(app)
26
+ super
27
+
28
+ # Disable css
29
+ unregister_processor "text/css", ::Sprockets::DirectiveProcessor
30
+
31
+ self.js_compressor = app.settings.js_compressor
32
+
33
+ # configure search paths
34
+ javascripts_path = File.join(File.expand_path(app.views), app.js_dir)
35
+ append_path javascripts_path
36
+ end
37
+ end
38
+
39
+ # class StylesheetEnvironment < MiddlemanEnvironment
40
+ # def initialize(app)
41
+ # super
42
+ #
43
+ # # Disable js
44
+ # unregister_processor "application/javascript", ::Sprockets::DirectiveProcessor
45
+ #
46
+ # # configure search paths
47
+ # stylesheets_path = File.join(File.expand_path(app.views), app.css_dir)
48
+ # append_path stylesheets_path
49
+ # end
50
+ # end
51
+ end
@@ -1,7 +1,7 @@
1
1
  module Middleman::Features::AssetHost
2
2
  class << self
3
3
  def registered(app)
4
- app.after_feature_init do
4
+ app.after_compass_init do
5
5
  if app.asset_host.is_a?(Proc)
6
6
  ::Compass.configuration.asset_host(&app.asset_host)
7
7
  end
@@ -16,7 +16,7 @@ module Middleman::Features::CacheBuster
16
16
 
17
17
  if File.readable?(real_path_static)
18
18
  http_path << "?" + File.mtime(real_path_static).strftime("%s")
19
- elsif app.environment == :build
19
+ elsif app.build?
20
20
  real_path_dynamic = File.join(app.root, app.build_dir, prefix, path)
21
21
  http_path << "?" + File.mtime(real_path_dynamic).strftime("%s") if File.readable?(real_path_dynamic)
22
22
  end
@@ -25,7 +25,7 @@ module Middleman::Features::CacheBuster
25
25
  end
26
26
  end
27
27
 
28
- app.after_feature_init do
28
+ app.after_compass_init do
29
29
  ::Compass.configuration do |config|
30
30
  config.asset_cache_buster do |path, real_path|
31
31
  real_path = real_path.path if real_path.is_a? File
@@ -1,7 +1,7 @@
1
1
  module Middleman::Features::LiveReload
2
2
  class << self
3
3
  def registered(app)
4
- return unless Middleman::Server.environment == :development
4
+ return unless Middleman::Server.development?
5
5
 
6
6
  begin
7
7
  require 'livereload'
@@ -1,7 +1,7 @@
1
1
  module Middleman::Features::MinifyCss
2
2
  class << self
3
3
  def registered(app)
4
- app.after_feature_init do
4
+ app.after_compass_init do
5
5
  ::Compass.configuration.output_style = :compressed
6
6
  end
7
7
  end
@@ -1,12 +1,43 @@
1
1
  module Middleman::Features::MinifyJavascript
2
2
  class << self
3
3
  def registered(app)
4
- # Only do minification on build or prod mode
5
- return unless [:build, :production].include? app.environment
6
-
7
- require "middleman/features/minify_javascript/rack"
8
- app.use Middleman::Rack::MinifyJavascript
4
+ require 'uglifier'
5
+ app.set :js_compressor, ::Uglifier.new
6
+ app.use InlineJavascriptRack
9
7
  end
10
8
  alias :included :registered
11
9
  end
10
+
11
+ class InlineJavascriptRack
12
+ def initialize(app, options={})
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ status, headers, response = @app.call(env)
18
+
19
+ if env["PATH_INFO"].match(/\.html$/)
20
+ compressor = ::Uglifier.new
21
+
22
+ if response.is_a?(::Rack::File) or response.is_a?(::Sinatra::Helpers::StaticFile)
23
+ uncompressed_source = File.read(response.path)
24
+ else
25
+ uncompressed_source = response.join
26
+ end
27
+
28
+ minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m|
29
+ first = $1
30
+ uncompressed_source = $2
31
+ last = $3
32
+ minified_js = compressor.compile(uncompressed_source)
33
+
34
+ first << minified_js << "\n" << last
35
+ end
36
+ headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
37
+ response = [minified]
38
+ end
39
+
40
+ [status, headers, response]
41
+ end
42
+ end
12
43
  end
@@ -1,12 +1,8 @@
1
- module Middleman
2
- module Renderers
3
- module CoffeeScript
4
- class << self
5
- def registered(app)
6
- require "coffee_script"
7
- end
8
- alias :included :registered
9
- end
1
+ module Middleman::Renderers::CoffeeScript
2
+ class << self
3
+ def registered(app)
4
+ require "coffee_script"
10
5
  end
6
+ alias :included :registered
11
7
  end
12
8
  end
@@ -1,43 +1,31 @@
1
- require "haml"
2
- require "coffee-filter"
1
+ module Middleman::Renderers::Haml
2
+ class << self
3
+ def registered(app)
4
+ # Base library
5
+ require "haml"
3
6
 
4
- module Middleman
5
- module Renderers
6
- module Haml
7
- class << self
8
- def registered(app)
9
- app.helpers Middleman::Renderers::Haml::Helpers
10
- end
11
- alias :included :registered
7
+ # Coffee-script filter for Haml
8
+ begin
9
+ require "coffee-filter"
10
+ rescue LoadError
12
11
  end
13
12
 
14
- module Helpers
15
- def haml_partial(name, options = {})
16
- partial(name, options)
17
- end
13
+ # Code-ray Syntax highlighting
14
+ begin
15
+ require 'haml-coderay'
16
+ rescue LoadError
18
17
  end
18
+
19
+ app.helpers Helpers
20
+
21
+ #app.set :haml, app.settings.haml.merge({ :ugly_haml => true })
22
+ end
23
+ alias :included :registered
24
+ end
19
25
 
20
- module Table
21
- include ::Haml::Filters::Base
22
-
23
- def render(text)
24
- output = '<div class="table"><table cellspacing="0" cellpadding="0">'
25
- line_num = 0
26
- text.each_line do |line|
27
- line_num += 1
28
- next if line.strip.empty?
29
- output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
30
-
31
- columns = line.split("|").map { |p| p.strip }
32
- columns.each_with_index do |col, i|
33
- output << %Q{<td class="col#{i+1}">#{col}</td>}
34
- end
35
-
36
- output << "</tr>"
37
- end
38
- output + "</table></div>"
39
- end
40
- end
26
+ module Helpers
27
+ def haml_partial(name, options = {})
28
+ render(name, options)
41
29
  end
42
30
  end
43
31
  end
@@ -1,12 +1,11 @@
1
- module Middleman
2
- module Renderers
3
- module Markdown
4
- class << self
5
- def registered(app)
6
- require "rdiscount"
7
- end
8
- alias :included :registered
1
+ module Middleman::Renderers::Markdown
2
+ class << self
3
+ def registered(app)
4
+ app.set :markdown, ::Tilt::RDiscountTemplate
5
+ app.after_feature_init do
6
+ ::Tilt.prefer(app.settings.markdown)
9
7
  end
10
8
  end
9
+ alias :included :registered
11
10
  end
12
11
  end
@@ -1,83 +1,61 @@
1
1
  require "sass"
2
2
  require "sass/plugin"
3
- require "compass"
4
- require "susy"
5
3
 
6
- module Middleman
7
- module Renderers
8
- module Sass
9
- class << self
10
- def registered(app)
11
- app.after_feature_init do
12
- views_root = File.basename(self.views)
13
- ::Compass.configuration do |config|
14
- config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
15
- config.project_path = self.root
16
- config.sass_dir = File.join(views_root, self.css_dir)
17
- config.output_style = :nested
18
- config.fonts_dir = File.join(views_root, self.fonts_dir)
19
- config.css_dir = File.join(views_root, self.css_dir)
20
- config.images_dir = File.join(views_root, self.images_dir)
21
- config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir)
22
- config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir)
23
- config.asset_cache_buster :none
24
-
25
- config.add_import_path(config.sass_dir)
26
- end
27
-
28
- configure :build do
29
- build_root = File.basename(self.build_dir)
30
- ::Compass.configuration do |config|
31
- config.css_dir = File.join(build_root, self.css_dir)
32
- config.images_dir = File.join(build_root, self.images_dir)
33
- end
34
- end
35
- end
36
- end
37
- alias :included :registered
38
- end
4
+ module Middleman::Renderers::Sass
5
+ class << self
6
+ def registered(app)
7
+ # Default sass options
8
+ app.set :sass, {}
39
9
  end
10
+ alias :included :registered
40
11
  end
41
- end
12
+
13
+ class SassPlusCSSFilenameTemplate < ::Tilt::SassTemplate
14
+ def sass_options
15
+ return super if basename.nil?
16
+
17
+ location_of_sass_file = if Middleman::Server.build?
18
+ File.join(Middleman::Server.root, Middleman::Server.build_dir)
19
+ else
20
+ Middleman::Server.views
21
+ end
42
22
 
43
- class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
44
- def sass_options
45
- return super if basename.nil?
46
-
47
- location_of_sass_file = Middleman::Server.environment == :build ?
48
- File.join(Middleman::Server.root, Middleman::Server.build_dir) :
49
- Middleman::Server.views
23
+ parts = basename.split('.')
24
+ parts.pop
25
+ css_filename = File.join(location_of_sass_file, Middleman::Server.css_dir, parts.join("."))
26
+ super.merge(Middleman::Server.settings.sass).merge(:css_filename => css_filename)
27
+ end
50
28
 
51
- parts = basename.split('.')
52
- parts.pop
53
- css_filename = File.join(location_of_sass_file, Middleman::Server.css_dir, parts.join("."))
54
- super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
55
- end
56
-
57
- def evaluate(scope, locals, &block)
58
- begin
59
- super
60
- rescue Sass::SyntaxError => e
61
- Sass::SyntaxError.exception_to_css(e, :full_exception => true)
29
+ def evaluate(scope, locals, &block)
30
+ begin
31
+ super
32
+ rescue Sass::SyntaxError => e
33
+ Sass::SyntaxError.exception_to_css(e, :full_exception => true)
34
+ end
62
35
  end
63
36
  end
64
- end
65
- Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
37
+ ::Tilt.register 'sass', SassPlusCSSFilenameTemplate
38
+ ::Tilt.prefer(SassPlusCSSFilenameTemplate)
66
39
 
67
- class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
68
- def sass_options
69
- super.merge(:syntax => :scss)
40
+ class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
41
+ def sass_options
42
+ super.merge(:syntax => :scss)
43
+ end
70
44
  end
45
+ ::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
46
+ ::Tilt.prefer(ScssPlusCSSFilenameTemplate)
71
47
  end
72
- Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
73
-
74
48
 
49
+ # Use sass settings in Haml filters
50
+ # Other, tilt-based filters (like those used in Slim) will
51
+ # work automatically.
75
52
  module Middleman::Renderers::Haml
76
53
  module Sass
77
54
  include ::Haml::Filters::Base
78
55
 
79
56
  def render(text)
80
- ::Sass::Engine.new(text, ::Compass.configuration.to_sass_engine_options).render
57
+ sass_options = Middleman::Server.settings.sass
58
+ ::Sass::Engine.new(text, sass_options).render
81
59
  end
82
60
  end
83
61
  end
@@ -1,12 +1,8 @@
1
- module Middleman
2
- module Renderers
3
- module Slim
4
- class << self
5
- def registered(app)
6
- require "slim"
7
- end
8
- alias :included :registered
9
- end
1
+ module Middleman::Renderers::Slim
2
+ class << self
3
+ def registered(app)
4
+ require "slim"
10
5
  end
6
+ alias :included :registered
11
7
  end
12
8
  end
@@ -3,6 +3,21 @@ require "sinatra/base"
3
3
 
4
4
  module Middleman
5
5
  class Server < Sinatra::Base
6
+ class << self
7
+ # Override Sinatra's set to accept a block
8
+ # Specifically for the asset_host feature
9
+ def set(option, value=self, &block)
10
+ if block_given?
11
+ value = Proc.new { block }
12
+ end
13
+
14
+ super(option, value, &nil)
15
+ end
16
+
17
+ # Convenience method to check if we're in build mode
18
+ def build?; environment == :build; end
19
+ end
20
+
6
21
  # Basic Sinatra config
7
22
  set :app_file, __FILE__
8
23
  set :root, ENV["MM_DIR"] || Dir.pwd
@@ -28,12 +43,21 @@ module Middleman
28
43
 
29
44
  set :views, "source"
30
45
 
46
+ # Add Rack::Builder.map to Sinatra
47
+ register Middleman::CoreExtensions::RackMap
48
+
31
49
  # Activate custom features
32
50
  register Middleman::CoreExtensions::Features
33
51
 
34
52
  # Setup custom rendering
35
53
  register Middleman::CoreExtensions::Rendering
36
54
 
55
+ # Compass framework
56
+ register Middleman::CoreExtensions::Compass
57
+
58
+ # Sprockets asset handling
59
+ register Middleman::CoreExtensions::Sprockets
60
+
37
61
  # Setup asset path pipeline
38
62
  register Middleman::CoreExtensions::Assets
39
63
 
@@ -49,22 +73,12 @@ module Middleman
49
73
  # Parse YAML from templates
50
74
  register Middleman::CoreExtensions::FrontMatter
51
75
 
52
- set :default_extensions, [
76
+ set :default_features, [
53
77
  :lorem
54
78
  ]
55
79
 
56
- # Override Sinatra's set to accept a block
57
- # Specifically for the asset_host feature
58
- def self.set(option, value=self, &block)
59
- if block_given?
60
- value = Proc.new { block }
61
- end
62
-
63
- super(option, value, &nil)
64
- end
65
-
66
80
  # Default layout name
67
- layout :layout
81
+ set :layout, :layout
68
82
 
69
83
  # This will match all requests not overridden in the project's config.rb
70
84
  not_found do
@@ -98,15 +112,23 @@ module Middleman
98
112
 
99
113
  options.merge!(request['custom_options'] || {})
100
114
 
101
- old_layout = settings.current_layout
102
- settings.layout(options[:layout]) if !options[:layout].nil?
103
- layout = settings.fetch_layout_path.to_sym
104
- layout = false if options[:layout] == false or request.path_info =~ /\.(css|js)$/
115
+ old_layout = settings.layout
116
+ settings.set :layout, options[:layout] if !options[:layout].nil?
117
+
118
+ layout = if settings.layout
119
+ if options[:layout] == false || request.path_info =~ /\.(css|js)$/
120
+ false
121
+ else
122
+ settings.fetch_layout_path(settings.layout).to_sym
123
+ end
124
+ else
125
+ false
126
+ end
105
127
 
106
128
  render_options = { :layout => layout }
107
129
  render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
108
130
  result = render(request.path_info, render_options)
109
- settings.layout(old_layout)
131
+ settings.set :layout, old_layout
110
132
 
111
133
  if result
112
134
  content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
@@ -1,7 +1,17 @@
1
+ # Susy grids in Compass
2
+ # First: gem install compass-susy-plugin
3
+ # require 'susy'
4
+
1
5
  # CodeRay syntax highlighting in Haml
2
- # activate :code_ray
6
+ # First: gem install haml-coderay
7
+ # require 'haml-coderay'
8
+
9
+ # CoffeeScript filters in Haml
10
+ # First: gem install coffee-filter
11
+ # require 'coffee-filter'
3
12
 
4
- # Automatic sitemaps (gem install middleman-slickmap)
13
+ # Automatic sitemaps
14
+ # First: gem install middleman-slickmap
5
15
  # require "middleman-slickmap"
6
16
  # activate :slickmap
7
17
 
@@ -15,11 +25,11 @@
15
25
  # page "/path/to/file.html", :layout => :otherlayout
16
26
 
17
27
  # Helpers
18
- helpers do
19
- def some_helper(*args)
20
- "Helping"
21
- end
22
- end
28
+ # helpers do
29
+ # def some_helper(*args)
30
+ # "Helping"
31
+ # end
32
+ # end
23
33
 
24
34
  <% if options[:css_dir] != "stylesheets" -%>
25
35
  set :css_dir, "<%= options[:css_dir] -%>"
@@ -56,12 +66,10 @@ configure :build do
56
66
  # Use relative URLs
57
67
  # activate :relative_assets
58
68
 
59
- # Compress PNGs after build (gem install middleman-smusher)
69
+ # Compress PNGs after build
70
+ # First: gem install middleman-smusher
60
71
  # require "middleman-smusher"
61
72
  # activate :smusher
62
-
63
- # Generate ugly/obfuscated HTML from Haml
64
- # activate :ugly_haml
65
73
 
66
74
  # Or use a different image path
67
75
  # set :http_path, "/Content/images/"
@@ -1,3 +1,3 @@
1
1
  module Middleman
2
- VERSION = "2.0.0.rc1"
2
+ VERSION = "2.0.0.rc2"
3
3
  end
data/middleman.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Thomas Reynolds"]
10
10
  s.email = ["tdreyno@gmail.com"]
11
- s.homepage = "http://wiki.github.com/tdreyno/middleman"
12
- s.summary = "A static site generator based on Sinatra. Providing Haml, Sass, Compass, Less, Coffee Script and including minification, compression and cache busting."
11
+ s.homepage = "http://middlemanapp.com"
12
+ s.summary = "A static site generator based on Sinatra. Providing Haml, Sass, Compass, CoffeeScript and including minification, compression and cache busting."
13
13
 
14
14
  s.rubyforge_project = "middleman"
15
15
 
@@ -29,11 +29,9 @@ Gem::Specification.new do |s|
29
29
  s.add_runtime_dependency("uglifier", ["~> 0.5.0"])
30
30
  s.add_runtime_dependency("slim", ["~> 0.9.4"])
31
31
  s.add_runtime_dependency("haml", ["~> 3.1.0"])
32
- s.add_runtime_dependency("coffee-filter", ["~> 0.1.0"])
33
32
  s.add_runtime_dependency("sass", ["~> 3.1.0"])
34
33
  s.add_runtime_dependency("compass", ["~> 0.11.3"])
35
- s.add_runtime_dependency("compass-susy-plugin", ["~> 0.9.0"])
36
- s.add_runtime_dependency("coffee-script", ["~> 2.2.0"])
34
+ s.add_runtime_dependency("sprockets", ["2.0.0.beta.10"])
37
35
  s.add_runtime_dependency("httparty", ["~> 0.7.0"])
38
36
  s.add_development_dependency("spork", ["~> 0.9.0.rc8"])
39
37
  s.add_development_dependency("cucumber", ["~> 0.10.0"])
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: middleman
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.0.0.rc1
5
+ version: 2.0.0.rc2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Thomas Reynolds
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-07 00:00:00 -07:00
13
+ date: 2011-07-11 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -135,126 +135,104 @@ dependencies:
135
135
  type: :runtime
136
136
  version_requirements: *id011
137
137
  - !ruby/object:Gem::Dependency
138
- name: coffee-filter
138
+ name: sass
139
139
  prerelease: false
140
140
  requirement: &id012 !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
143
143
  - - ~>
144
144
  - !ruby/object:Gem::Version
145
- version: 0.1.0
145
+ version: 3.1.0
146
146
  type: :runtime
147
147
  version_requirements: *id012
148
148
  - !ruby/object:Gem::Dependency
149
- name: sass
149
+ name: compass
150
150
  prerelease: false
151
151
  requirement: &id013 !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
154
154
  - - ~>
155
155
  - !ruby/object:Gem::Version
156
- version: 3.1.0
156
+ version: 0.11.3
157
157
  type: :runtime
158
158
  version_requirements: *id013
159
159
  - !ruby/object:Gem::Dependency
160
- name: compass
160
+ name: sprockets
161
161
  prerelease: false
162
162
  requirement: &id014 !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements:
165
- - - ~>
165
+ - - "="
166
166
  - !ruby/object:Gem::Version
167
- version: 0.11.3
167
+ version: 2.0.0.beta.10
168
168
  type: :runtime
169
169
  version_requirements: *id014
170
- - !ruby/object:Gem::Dependency
171
- name: compass-susy-plugin
172
- prerelease: false
173
- requirement: &id015 !ruby/object:Gem::Requirement
174
- none: false
175
- requirements:
176
- - - ~>
177
- - !ruby/object:Gem::Version
178
- version: 0.9.0
179
- type: :runtime
180
- version_requirements: *id015
181
- - !ruby/object:Gem::Dependency
182
- name: coffee-script
183
- prerelease: false
184
- requirement: &id016 !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ~>
188
- - !ruby/object:Gem::Version
189
- version: 2.2.0
190
- type: :runtime
191
- version_requirements: *id016
192
170
  - !ruby/object:Gem::Dependency
193
171
  name: httparty
194
172
  prerelease: false
195
- requirement: &id017 !ruby/object:Gem::Requirement
173
+ requirement: &id015 !ruby/object:Gem::Requirement
196
174
  none: false
197
175
  requirements:
198
176
  - - ~>
199
177
  - !ruby/object:Gem::Version
200
178
  version: 0.7.0
201
179
  type: :runtime
202
- version_requirements: *id017
180
+ version_requirements: *id015
203
181
  - !ruby/object:Gem::Dependency
204
182
  name: spork
205
183
  prerelease: false
206
- requirement: &id018 !ruby/object:Gem::Requirement
184
+ requirement: &id016 !ruby/object:Gem::Requirement
207
185
  none: false
208
186
  requirements:
209
187
  - - ~>
210
188
  - !ruby/object:Gem::Version
211
189
  version: 0.9.0.rc8
212
190
  type: :development
213
- version_requirements: *id018
191
+ version_requirements: *id016
214
192
  - !ruby/object:Gem::Dependency
215
193
  name: cucumber
216
194
  prerelease: false
217
- requirement: &id019 !ruby/object:Gem::Requirement
195
+ requirement: &id017 !ruby/object:Gem::Requirement
218
196
  none: false
219
197
  requirements:
220
198
  - - ~>
221
199
  - !ruby/object:Gem::Version
222
200
  version: 0.10.0
223
201
  type: :development
224
- version_requirements: *id019
202
+ version_requirements: *id017
225
203
  - !ruby/object:Gem::Dependency
226
204
  name: rake
227
205
  prerelease: false
228
- requirement: &id020 !ruby/object:Gem::Requirement
206
+ requirement: &id018 !ruby/object:Gem::Requirement
229
207
  none: false
230
208
  requirements:
231
209
  - - "="
232
210
  - !ruby/object:Gem::Version
233
211
  version: 0.8.7
234
212
  type: :development
235
- version_requirements: *id020
213
+ version_requirements: *id018
236
214
  - !ruby/object:Gem::Dependency
237
215
  name: rspec
238
216
  prerelease: false
239
- requirement: &id021 !ruby/object:Gem::Requirement
217
+ requirement: &id019 !ruby/object:Gem::Requirement
240
218
  none: false
241
219
  requirements:
242
220
  - - ">="
243
221
  - !ruby/object:Gem::Version
244
222
  version: "0"
245
223
  type: :development
246
- version_requirements: *id021
224
+ version_requirements: *id019
247
225
  - !ruby/object:Gem::Dependency
248
226
  name: rocco
249
227
  prerelease: false
250
- requirement: &id022 !ruby/object:Gem::Requirement
228
+ requirement: &id020 !ruby/object:Gem::Requirement
251
229
  none: false
252
230
  requirements:
253
231
  - - ">="
254
232
  - !ruby/object:Gem::Version
255
233
  version: "0"
256
234
  type: :development
257
- version_requirements: *id022
235
+ version_requirements: *id020
258
236
  description:
259
237
  email:
260
238
  - tdreyno@gmail.com
@@ -274,7 +252,7 @@ files:
274
252
  - CHANGELOG
275
253
  - Gemfile
276
254
  - LICENSE
277
- - README.rdoc
255
+ - README.md
278
256
  - Rakefile
279
257
  - bin/mm-build
280
258
  - bin/mm-init
@@ -293,6 +271,7 @@ files:
293
271
  - features/page_alias_and_layouts.feature
294
272
  - features/scss-support.feature
295
273
  - features/slim.feature
274
+ - features/sprockets.feature
296
275
  - features/step_definitions/asset_host_steps.rb
297
276
  - features/step_definitions/builder_steps.rb
298
277
  - features/step_definitions/generator_steps.rb
@@ -333,6 +312,8 @@ files:
333
312
  - fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js
334
313
  - fixtures/test-app/source/javascripts/coffee_test.js.coffee
335
314
  - fixtures/test-app/source/javascripts/jquery.plugin.with.dots.js
315
+ - fixtures/test-app/source/javascripts/sprockets_base.js
316
+ - fixtures/test-app/source/javascripts/sprockets_sub.js
336
317
  - fixtures/test-app/source/layout.haml
337
318
  - fixtures/test-app/source/layouts/custom.haml
338
319
  - fixtures/test-app/source/padrino_test.html.haml
@@ -357,27 +338,27 @@ files:
357
338
  - lib/middleman/builder.rb
358
339
  - lib/middleman/config.ru
359
340
  - lib/middleman/core_extensions/assets.rb
341
+ - lib/middleman/core_extensions/compass.rb
360
342
  - lib/middleman/core_extensions/data.rb
361
343
  - lib/middleman/core_extensions/default_helpers.rb
362
344
  - lib/middleman/core_extensions/features.rb
363
345
  - lib/middleman/core_extensions/front_matter.rb
346
+ - lib/middleman/core_extensions/rack_map.rb
364
347
  - lib/middleman/core_extensions/rendering.rb
365
348
  - lib/middleman/core_extensions/routing.rb
349
+ - lib/middleman/core_extensions/sprockets.rb
366
350
  - lib/middleman/features/asset_host.rb
367
351
  - lib/middleman/features/automatic_image_sizes.rb
368
352
  - lib/middleman/features/automatic_image_sizes/fastimage.rb
369
353
  - lib/middleman/features/blog.rb
370
354
  - lib/middleman/features/cache_buster.rb
371
- - lib/middleman/features/code_ray.rb
372
355
  - lib/middleman/features/live_reload.rb
373
356
  - lib/middleman/features/lorem.rb
374
357
  - lib/middleman/features/minify_css.rb
375
358
  - lib/middleman/features/minify_javascript.rb
376
- - lib/middleman/features/minify_javascript/rack.rb
377
359
  - lib/middleman/features/proxy.rb
378
360
  - lib/middleman/features/relative_assets.rb
379
361
  - lib/middleman/features/tiny_src.rb
380
- - lib/middleman/features/ugly_haml.rb
381
362
  - lib/middleman/renderers/coffee_script.rb
382
363
  - lib/middleman/renderers/haml.rb
383
364
  - lib/middleman/renderers/markdown.rb
@@ -422,7 +403,7 @@ files:
422
403
  - lib/middleman/version.rb
423
404
  - middleman.gemspec
424
405
  has_rdoc: true
425
- homepage: http://wiki.github.com/tdreyno/middleman
406
+ homepage: http://middlemanapp.com
426
407
  licenses: []
427
408
 
428
409
  post_install_message:
@@ -448,7 +429,7 @@ rubyforge_project: middleman
448
429
  rubygems_version: 1.3.9.2
449
430
  signing_key:
450
431
  specification_version: 3
451
- summary: A static site generator based on Sinatra. Providing Haml, Sass, Compass, Less, Coffee Script and including minification, compression and cache busting.
432
+ summary: A static site generator based on Sinatra. Providing Haml, Sass, Compass, CoffeeScript and including minification, compression and cache busting.
452
433
  test_files:
453
434
  - features/builder.feature
454
435
  - features/coffee-script.feature
@@ -464,6 +445,7 @@ test_files:
464
445
  - features/page_alias_and_layouts.feature
465
446
  - features/scss-support.feature
466
447
  - features/slim.feature
448
+ - features/sprockets.feature
467
449
  - features/step_definitions/asset_host_steps.rb
468
450
  - features/step_definitions/builder_steps.rb
469
451
  - features/step_definitions/generator_steps.rb
@@ -504,6 +486,8 @@ test_files:
504
486
  - fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js
505
487
  - fixtures/test-app/source/javascripts/coffee_test.js.coffee
506
488
  - fixtures/test-app/source/javascripts/jquery.plugin.with.dots.js
489
+ - fixtures/test-app/source/javascripts/sprockets_base.js
490
+ - fixtures/test-app/source/javascripts/sprockets_sub.js
507
491
  - fixtures/test-app/source/layout.haml
508
492
  - fixtures/test-app/source/layouts/custom.haml
509
493
  - fixtures/test-app/source/padrino_test.html.haml
data/README.rdoc DELETED
@@ -1,15 +0,0 @@
1
- = middleman
2
-
3
- The Middleman is ever-vigilant against tag-soup, unreadable CSS and repetition. He stands-watch over your Haml, Sass, Less and CoffeeScript producing only the cleanest and efficient markup.
4
-
5
- == Getting Started
6
-
7
- Everything you need to know is on the wiki: http://github.com/tdreyno/middleman/wiki
8
-
9
- == Mailing List
10
-
11
- If you have questions, answers can be found on community forum: https://convore.com/middleman/
12
-
13
- == Copyright
14
-
15
- Copyright (c) 2010 Thomas Reynolds. See LICENSE for details.
@@ -1,12 +0,0 @@
1
- module Middleman::Features::CodeRay
2
- class << self
3
- def registered(app)
4
- begin
5
- require 'haml-coderay'
6
- rescue LoadError
7
- puts "CodeRay not available. Install it with: gem install haml-coderay"
8
- end
9
- end
10
- alias :included :registered
11
- end
12
- end
@@ -1,57 +0,0 @@
1
- begin
2
- require 'uglifier'
3
- rescue LoadError
4
- puts "UglifyJS not available. Install it with: gem install uglifier"
5
- end
6
-
7
- module Middleman
8
- module Rack
9
-
10
- class MinifyJavascript
11
- def initialize(app, options={})
12
- @app = app
13
- end
14
-
15
- def call(env)
16
- status, headers, response = @app.call(env)
17
-
18
- if env["PATH_INFO"].match(/\.js$/)
19
- compressor = ::Uglifier.new
20
-
21
- if response.is_a?(::Rack::File) or response.is_a?(Sinatra::Helpers::StaticFile)
22
- uncompressed_source = File.read(response.path)
23
- else
24
- uncompressed_source = response.join
25
- end
26
- minified = compressor.compile(uncompressed_source)
27
- headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
28
- response = [minified]
29
- end
30
-
31
- if env["PATH_INFO"].match(/\.html$/)
32
- compressor = ::Uglifier.new
33
-
34
- if response.is_a?(::Rack::File) or response.is_a?(Sinatra::Helpers::StaticFile)
35
- uncompressed_source = File.read(response.path)
36
- else
37
- uncompressed_source = response.join
38
- end
39
-
40
- minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m|
41
- first = $1
42
- uncompressed_source = $2
43
- last = $3
44
- minified_js = compressor.compile(uncompressed_source)
45
-
46
- first << minified_js << "\n" << last
47
- end
48
- headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
49
- response = [minified]
50
- end
51
-
52
- [status, headers, response]
53
- end
54
- end
55
-
56
- end
57
- end
@@ -1,8 +0,0 @@
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
7
- end
8
- end