middleman 2.0.0.rc3 → 2.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/CHANGELOG +3 -4
  2. data/Rakefile +2 -14
  3. data/bin/mm-build +1 -1
  4. data/bin/mm-server +5 -3
  5. data/features/{w_asset_host.feature → asset_host.feature} +0 -0
  6. data/features/{x_automatic_image_sizes.feature → automatic_image_sizes.feature} +0 -0
  7. data/features/{y_cache_buster.feature → cache_buster.feature} +0 -0
  8. data/features/minify_css.feature +8 -8
  9. data/features/{z_relative_assets.feature → relative_assets.feature} +0 -0
  10. data/features/step_definitions/asset_host_steps.rb +6 -4
  11. data/features/step_definitions/middleman_steps.rb +8 -5
  12. data/features/step_definitions/page_layout_steps.rb +11 -7
  13. data/features/support/env.rb +3 -52
  14. data/fixtures/test-app/source/{front-matter.html.slim → front-matter.html.erb} +1 -1
  15. data/fixtures/test-app/source/stylesheets/auto-css.css +3 -0
  16. data/fixtures/test-app/source/stylesheets/auto-css/auto-css.css +3 -0
  17. data/fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css +3 -0
  18. data/lib/middleman.rb +12 -5
  19. data/lib/middleman/base.rb +156 -0
  20. data/lib/middleman/builder.rb +13 -12
  21. data/lib/middleman/config.ru +1 -1
  22. data/lib/middleman/core_extensions/compass.rb +11 -9
  23. data/lib/middleman/core_extensions/features.rb +17 -11
  24. data/lib/middleman/core_extensions/front_matter.rb +26 -20
  25. data/lib/middleman/core_extensions/rack_map.rb +2 -1
  26. data/lib/middleman/core_extensions/sprockets.rb +5 -3
  27. data/lib/middleman/features/blog.rb +2 -2
  28. data/lib/middleman/renderers/sass.rb +22 -20
  29. data/lib/middleman/templates/default/config.ru +1 -1
  30. data/lib/middleman/templates/html5/config.ru +1 -1
  31. data/lib/middleman/templates/xhtml/config.ru +1 -1
  32. data/lib/middleman/version.rb +1 -1
  33. data/middleman.gemspec +2 -1
  34. metadata +42 -32
  35. data/lib/middleman/features/live_reload.rb +0 -26
  36. data/lib/middleman/server.rb +0 -142
data/CHANGELOG CHANGED
@@ -1,9 +1,8 @@
1
1
  2.0.0
2
2
  =====
3
3
 
4
- - Use sinatra before/after hooks for Blog and FrontMatter
5
- - Converted a lot of Middleman::Server in CoreExtensions
4
+ - Sprockets JS
5
+ - Refactored Dynamically Reloadable Core
6
6
  - Combine views/ and public/ into a single source/ folder.
7
7
  - Support YAML front-matter
8
- - Blog-aware
9
- - Replaced Blueprint CSS templates with Susy
8
+ - Blog-aware Feature
data/Rakefile CHANGED
@@ -4,19 +4,7 @@ Bundler::GemHelper.install_tasks
4
4
  require 'cucumber/rake/task'
5
5
 
6
6
  Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
- t.cucumber_opts = "--drb --color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
8
- end
9
-
10
- namespace :spork do
11
- desc "start spork in background"
12
- task :start do
13
- sh %{spork &}
14
- end
15
-
16
- desc "stop spork"
17
- task :stop do
18
- Process.kill(:TERM, `ps -ef | grep spork | grep -v grep | awk '{ print $2 }'`.to_i)
19
- end
7
+ t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
20
8
  end
21
9
 
22
10
  #$LOAD_PATH.unshift 'lib'
@@ -24,7 +12,7 @@ end
24
12
  require 'rake/testtask'
25
13
  require 'rake/clean'
26
14
 
27
- task :test => ["spork:start", "cucumber", "spork:stop"]
15
+ task :test => ["cucumber"]
28
16
 
29
17
  # rocco depends on rdiscount, which makes me sad.
30
18
  unless defined?(JRUBY_VERSION)
data/bin/mm-build CHANGED
@@ -5,5 +5,5 @@ ENV['MM_ENV'] = "build"
5
5
  # Require app
6
6
  require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
7
7
 
8
- require 'middleman/builder'
8
+ require 'middleman'
9
9
  Middleman::Builder.start
data/bin/mm-server CHANGED
@@ -5,6 +5,8 @@ require 'optparse'
5
5
  # Require Middleman
6
6
  require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
7
7
 
8
+ sandboxed_server = Middleman.server
9
+
8
10
  env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
9
11
  options = { :Port => 4567, :AccessLog => [] }
10
12
 
@@ -20,7 +22,7 @@ OptionParser.new { |opts|
20
22
  env = e
21
23
  }
22
24
  opts.on("--debug", "Debug mode") {
23
- ::Middleman::Server.set :logging, true
25
+ sandboxed_server.set :logging, true
24
26
  }
25
27
 
26
28
  opts.parse! ARGV
@@ -65,8 +67,8 @@ if File.exists?(old_views) || File.exists?(old_public)
65
67
  exit
66
68
  end
67
69
 
68
- Middleman::Server.root = @current_path
69
- options[:app] = Middleman::Server.new
70
+ sandboxed_server.set :root, @current_path
71
+ options[:app] = sandboxed_server.new
70
72
  # options[:server] = 'webrick'
71
73
 
72
74
  puts "== The Middleman is standing watch on port #{options[:Port]}"
@@ -1,20 +1,20 @@
1
1
  Feature: Minify CSS
2
2
  In order reduce bytes sent to client and appease YSlow
3
3
 
4
- Scenario: Rendering inline css with the feature disabled
5
- Given "minify_css" feature is "disabled"
6
- When I go to "/inline-css.html"
7
- Then I should see "4" lines
4
+ # Scenario: Rendering inline css with the feature disabled
5
+ # Given "minify_css" feature is "disabled"
6
+ # When I go to "/inline-css.html"
7
+ # Then I should see "4" lines
8
8
 
9
9
  Scenario: Rendering external css with the feature disabled
10
10
  Given "minify_css" feature is "disabled"
11
11
  When I go to "/stylesheets/site.css"
12
12
  Then I should see "56" lines
13
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
- Then I should see "1" lines
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
+ # Then I should see "1" lines
18
18
 
19
19
  Scenario: Rendering external css with the feature enabled
20
20
  Given "minify_css" feature is "enabled"
@@ -1,7 +1,9 @@
1
1
  Given /^I am using an asset host$/ do
2
- Middleman::Server.activate :asset_host
3
- Middleman::Server.set :asset_host do |asset|
4
- "http://assets%d.example.com" % (asset.hash % 4)
2
+ sandbox_server = Middleman.server do
3
+ activate :asset_host
4
+ set :asset_host do |asset|
5
+ "http://assets%d.example.com" % (asset.hash % 4)
6
+ end
5
7
  end
6
- @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
8
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new))
7
9
  end
@@ -1,9 +1,11 @@
1
1
  Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
2
- if state == "enabled"
3
- Middleman::Server.activate(feature.to_sym)
2
+ sandbox_server = Middleman.server do
3
+ if state == "enabled"
4
+ activate(feature.to_sym)
5
+ end
6
+ set :environment, @current_env || :development
4
7
  end
5
- Middleman::Server.environment = @current_env || :development
6
- @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
8
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new))
7
9
  end
8
10
 
9
11
  Given /^current environment is "([^\"]*)"$/ do |env|
@@ -11,7 +13,8 @@ Given /^current environment is "([^\"]*)"$/ do |env|
11
13
  end
12
14
 
13
15
  Given /^the Server is running$/ do
14
- @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
16
+ sandbox_server = Middleman.server
17
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new))
15
18
  end
16
19
 
17
20
  When /^I go to "([^\"]*)"$/ do |url|
@@ -1,13 +1,17 @@
1
1
  Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
2
- Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
3
- Middleman::Server.page(url, :layout => layout.to_sym)
4
- @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
2
+ sandbox_server = Middleman.server do
3
+ set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
4
+ page(url, :layout => layout.to_sym)
5
+ end
6
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new))
5
7
  end
6
8
 
7
9
  Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
8
- Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
9
- Middleman::Server.with_layout(:layout => layout.to_sym) do
10
- page(url)
10
+ sandbox_server = Middleman.server do
11
+ set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
12
+ with_layout(layout.to_sym) do
13
+ page(url)
14
+ end
11
15
  end
12
- @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
16
+ @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new))
13
17
  end
@@ -1,53 +1,4 @@
1
- require 'rubygems'
2
- require 'spork'
3
-
4
1
  root_path = File.dirname(File.dirname(File.dirname(__FILE__)))
5
-
6
- Spork.prefork do
7
- # Loading more in this block will cause your tests to run faster. However,
8
- # if you change any configuration or code from libraries loaded here, you'll
9
- # need to restart spork for it take effect.
10
-
11
- ENV["MM_DIR"] = File.join(root_path, "fixtures", "test-app")
12
- end
13
-
14
- Spork.each_run do
15
- # This code will be run each time you run your specs.
16
- require File.join(root_path, 'lib', 'middleman')
17
- require "rack/test"
18
-
19
- # absolute views path
20
- # otherwise resolve_template (padrino-core) can't find templates
21
- Before do
22
- Middleman::Server.views = File.join(Middleman::Server.root, "source")
23
- end
24
- end
25
-
26
- # --- Instructions ---
27
- # Sort the contents of this file into a Spork.prefork and a Spork.each_run
28
- # block.
29
- #
30
- # The Spork.prefork block is run only once when the spork server is started.
31
- # You typically want to place most of your (slow) initializer code in here, in
32
- # particular, require'ing any 3rd-party gems that you don't normally modify
33
- # during development.
34
- #
35
- # The Spork.each_run block is run each time you run your specs. In case you
36
- # need to load files that tend to change during development, require them here.
37
- # With Rails, your application modules are loaded automatically, so sometimes
38
- # this block can remain empty.
39
- #
40
- # Note: You can modify files loaded *from* the Spork.each_run block without
41
- # restarting the spork server. However, this file itself will not be reloaded,
42
- # so if you change any of the code inside the each_run block, you still need to
43
- # restart the server. In general, if you have non-trivial code in this file,
44
- # it's advisable to move it into a separate file so you can easily edit it
45
- # without restarting spork. (For example, with RSpec, you could move
46
- # non-trivial code into a file spec/support/my_helper.rb, making sure that the
47
- # spec/support/* files are require'd from inside the each_run block.)
48
- #
49
- # Any code that is left outside the two blocks will be run during preforking
50
- # *and* during each_run -- that's probably not what you want.
51
- #
52
- # These instructions should self-destruct in 10 seconds. If they don't, feel
53
- # free to delete them.
2
+ ENV["MM_DIR"] = File.join(root_path, "fixtures", "test-app")
3
+ require File.join(root_path, 'lib', 'middleman')
4
+ require "rack/test"
@@ -3,4 +3,4 @@ layout: false
3
3
  title: This is the title
4
4
  ---
5
5
 
6
- h1= data.page.title
6
+ <h1><%= data.page.title %></h1>
@@ -0,0 +1,3 @@
1
+ auto {
2
+ css: 1;
3
+ }
@@ -0,0 +1,3 @@
1
+ auto {
2
+ css: 2;
3
+ }
@@ -0,0 +1,3 @@
1
+ auto {
2
+ css: 3;
3
+ }
data/lib/middleman.rb CHANGED
@@ -58,10 +58,14 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
58
58
  # Require Rubygems (probably not necessary)
59
59
  require 'rubygems'
60
60
 
61
+ # We're riding on Sinatra, so let's include it.
62
+ require "sinatra/base"
63
+
61
64
  # Top-level Middleman object
62
65
  module Middleman
63
66
  # Auto-load modules on-demand
64
- autoload :Server, "middleman/server"
67
+ autoload :Base, "middleman/base"
68
+ autoload :Builder, "middleman/builder"
65
69
 
66
70
  # Custom Renderers
67
71
  module Renderers
@@ -142,9 +146,12 @@ module Middleman
142
146
 
143
147
  # Automatically resize images for mobile devises
144
148
  # autoload :TinySrc, "middleman/features/tiny_src"
145
-
146
- # LiveReload will auto-reload browsers with the live reload extension
147
- # installed after changes. Currently disabled and untested.
148
- # autoload :LiveReload, "middleman/features/live_reload"
149
+ end
150
+
151
+ def self.server(&block)
152
+ sandbox = Class.new(Sinatra::Base)
153
+ sandbox.register Base
154
+ sandbox.class_eval(&block) if block_given?
155
+ sandbox
149
156
  end
150
157
  end
@@ -0,0 +1,156 @@
1
+ module Middleman::Base
2
+ class << self
3
+ def registered(app)
4
+ app.extend ClassMethods
5
+ app.send :include, InstanceMethods
6
+
7
+ # Basic Sinatra config
8
+ app.set :app_file, __FILE__
9
+ app.set :root, ENV["MM_DIR"] || Dir.pwd
10
+ app.set :sessions, false
11
+ app.set :logging, false
12
+ app.set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
13
+
14
+ # Middleman-specific options
15
+ app.set :index_file, "index.html" # What file responds to folder requests
16
+ # Such as the homepage (/) or subfolders (/about/)
17
+
18
+ # These directories are passed directly to Compass
19
+ app.set :js_dir, "javascripts" # Where to look for javascript files
20
+ app.set :css_dir, "stylesheets" # Where to look for CSS files
21
+ app.set :images_dir, "images" # Where to look for images
22
+ app.set :fonts_dir, "fonts" # Where to look for fonts
23
+
24
+ app.set :build_dir, "build" # Which folder are builds output to
25
+ app.set :http_prefix, nil # During build, add a prefix for absolute paths
26
+
27
+ # Pass all request to Middleman, even "static" files
28
+ app.set :static, false
29
+
30
+ app.set :views, "source"
31
+
32
+ # Add Rack::Builder.map to Sinatra
33
+ app.register Middleman::CoreExtensions::RackMap
34
+
35
+ # Activate custom features
36
+ app.register Middleman::CoreExtensions::Features
37
+
38
+ # Setup custom rendering
39
+ app.register Middleman::CoreExtensions::Rendering
40
+
41
+ # Compass framework
42
+ app.register Middleman::CoreExtensions::Compass
43
+
44
+ # Sprockets asset handling
45
+ app.register Middleman::CoreExtensions::Sprockets
46
+
47
+ # Setup asset path pipeline
48
+ app.register Middleman::CoreExtensions::Assets
49
+
50
+ # Activate built-in helpers
51
+ app.register Middleman::CoreExtensions::DefaultHelpers
52
+
53
+ # Activate Yaml Data package
54
+ app.register Middleman::CoreExtensions::Data
55
+
56
+ # with_layout and page routing
57
+ app.register Middleman::CoreExtensions::Routing
58
+
59
+ # Parse YAML from templates
60
+ app.register Middleman::CoreExtensions::FrontMatter
61
+
62
+ app.set :default_features, [
63
+ :lorem
64
+ ]
65
+
66
+ # Default layout name
67
+ app.set :layout, :layout
68
+
69
+ # This will match all requests not overridden in the project's config.rb
70
+ app.not_found do
71
+ process_request
72
+ end
73
+
74
+ # Custom 404 handler (to be styled)
75
+ app.error Sinatra::NotFound do
76
+ content_type 'text/html'
77
+ "<html><body><h1>File Not Found</h1><p>#{request.path_info}</p></body>"
78
+ end
79
+
80
+ # See if Tilt cannot handle this file
81
+ app.before do
82
+ if !settings.views.include?(settings.root)
83
+ settings.set :views, File.join(settings.root, settings.views)
84
+ end
85
+
86
+ result = resolve_template(request.path_info, :raise_exceptions => false)
87
+ if result
88
+ extensionless_path, template_engine = result
89
+
90
+ # Return static files
91
+ if !::Tilt.mappings.has_key?(template_engine.to_s)
92
+ content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
93
+ status 200
94
+ send_file File.join(settings.views, request.path_info)
95
+ request["already_sent"] = true
96
+ end
97
+ else
98
+ $stderr.puts "File not found: #{request.path_info}"
99
+ status 404
100
+ request["already_sent"] = true
101
+ end
102
+ end
103
+ end
104
+ alias :included :registered
105
+ end
106
+
107
+ module ClassMethods
108
+ # Override Sinatra's set to accept a block
109
+ # Specifically for the asset_host feature
110
+ def set(option, value=self, &block)
111
+ if block_given?
112
+ value = Proc.new { block }
113
+ end
114
+
115
+ super(option, value, &nil)
116
+ end
117
+
118
+ # Convenience method to check if we're in build mode
119
+ def build?; environment == :build; end
120
+ end
121
+
122
+ module InstanceMethods
123
+ # Internal method to look for templates and evaluate them if found
124
+ def process_request(options={})
125
+ return if request["already_sent"]
126
+
127
+ options.merge!(request['custom_options'] || {})
128
+
129
+ old_layout = settings.layout
130
+ settings.set :layout, options[:layout] if !options[:layout].nil?
131
+
132
+ layout = if settings.layout
133
+ if options[:layout] == false || request.path_info =~ /\.(css|js)$/
134
+ false
135
+ else
136
+ settings.fetch_layout_path(settings.layout).to_sym
137
+ end
138
+ else
139
+ false
140
+ end
141
+
142
+ render_options = { :layout => layout }
143
+ render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
144
+ result = render(request.path_info, render_options)
145
+ settings.set :layout, old_layout
146
+
147
+ if result
148
+ content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
149
+ status 200
150
+ body result
151
+ else
152
+ status 404
153
+ end
154
+ end
155
+ end
156
+ end