middleman 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -1,9 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
4
+
3
5
  # Require Middleman
4
6
  require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
5
7
 
6
- # Start Middleman
7
- Middleman::Base.set({ :server => %w[thin webrick],
8
- :root => Dir.pwd })
9
- Middleman::Base.run!
8
+ class Middleman::Base
9
+ set :root, Dir.pwd
10
+
11
+ OptionParser.new { |op|
12
+ op.on('-e env') { |val| set :environment, val.to_sym }
13
+ op.on('-s server') { |val| set :server, val }
14
+ op.on('-p port') { |val| set :port, val.to_i }
15
+ }.parse!(ARGV.dup)
16
+
17
+ # Start Middleman
18
+ run!
19
+ end
@@ -1,8 +1,10 @@
1
+ # Be nice to other library systems, like the wonderful Rip
1
2
  require 'rubygems' unless ENV['NO_RUBYGEMS']
2
- require 'haml'
3
+
4
+ # We're riding on Sinatra, so let's include it
3
5
  require 'sinatra/base'
4
- require 'middleman/helpers'
5
6
 
7
+ # Rack helper for adding mime-types during local preview
6
8
  def mime(ext, type)
7
9
  ext = ".#{ext}" unless ext.to_s[0] == ?.
8
10
  Rack::Mime::MIME_TYPES[ext.to_s] = type
@@ -15,14 +17,19 @@ module Middleman
15
17
  set :environment, ENV['MM_ENV'] || :development
16
18
  set :supported_formats, []
17
19
  set :index_file, 'index.html'
20
+ set :js_dir, "javascripts"
18
21
  set :css_dir, "stylesheets"
19
22
  set :images_dir, "images"
20
23
  set :build_dir, "build"
24
+ set :http_prefix, "/"
21
25
 
26
+ # Features enabled by default
22
27
  enable :compass
23
28
  enable :content_for
24
29
  enable :sprockets
25
- #enable :slickmap
30
+
31
+ # Features disabled by default
32
+ disable :slickmap
26
33
  disable :cache_buster
27
34
  disable :minify_css
28
35
  disable :minify_javascript
@@ -30,17 +37,14 @@ module Middleman
30
37
  disable :markaby
31
38
  disable :maruku
32
39
 
33
- # include helpers
34
- helpers Middleman::Helpers
35
-
36
40
  # Default build features
37
41
  configure :build do
38
42
  enable :minify_css
39
43
  enable :minify_javascript
40
44
  enable :cache_buster
41
- # disable :slickmap
42
45
  end
43
46
 
47
+ # Convenience function to discover if a tempalte exists for the requested renderer (haml, sass, etc)
44
48
  def template_exists?(path, renderer=nil)
45
49
  template_path = path.dup
46
50
  template_path << ".#{renderer}" if renderer
@@ -55,21 +59,25 @@ module Middleman
55
59
  end
56
60
  include StaticRender
57
61
 
58
- # All other files
62
+ # Disable static asset handling in Rack, so we can customize it here
59
63
  disable :static
64
+
65
+ # This will match all requests not overridden in the project's init.rb
60
66
  not_found do
67
+ # Normalize the path and add index if we're looking at a directory
61
68
  path = request.path
62
69
  path << options.index_file if path.match(%r{/$})
63
70
  path.gsub!(%r{^/}, '')
64
71
 
72
+ # If the enabled renderers succeed, return the content, mime-type and an HTTP 200
65
73
  if content = render_path(path)
66
74
  content_type media_type(File.extname(path)), :charset => 'utf-8'
67
75
  status 200
68
76
  content
69
77
  else
70
- # Otherwise, send the static file
78
+ # If no template handler renders the template, return the static file if it exists
71
79
  path = File.join(options.public, request.path)
72
- if File.exists?(path)
80
+ if !File.directory?(path) && File.exists?(path)
73
81
  status 200
74
82
  send_file(path)
75
83
  else
@@ -78,6 +86,8 @@ module Middleman
78
86
  end
79
87
  end
80
88
 
89
+ # Copy, pasted & edited version of the setup in Sinatra.
90
+ # Basically just changed the app's name and call out feature & configuration init.
81
91
  def self.run!(options={}, &block)
82
92
  init!
83
93
  set options
@@ -101,15 +111,21 @@ module Middleman
101
111
  puts "== The Middleman is already standing watch on port #{port}!"
102
112
  end
103
113
 
114
+ # Require the features for this project
104
115
  def self.init!
105
- # Check for local config
116
+ # Built-in helpers
117
+ require 'middleman/helpers'
118
+ helpers Middleman::Helpers
119
+
120
+ # Haml is required & includes helpers
121
+ require "middleman/features/haml"
122
+
123
+ # Check for and evaluate local configuration
106
124
  local_config = File.join(self.root, "init.rb")
107
125
  if File.exists? local_config
108
126
  puts "== Local config at: #{local_config}"
109
127
  class_eval File.read(local_config)
110
128
  end
111
-
112
- require "middleman/features/haml"
113
129
 
114
130
  # loop over enabled feature
115
131
  features_path = File.expand_path("features/*.rb", File.dirname(__FILE__))
@@ -1,7 +1,10 @@
1
+ # Use Rack::Test to access Sinatra without starting up a full server
1
2
  require 'rack/test'
2
3
 
4
+ # Placeholder for any methods the builder needs to abstract to allow feature integration
3
5
  module Middleman
4
6
  class Builder
7
+ # The default render just requests the page over Rack and writes the response
5
8
  def self.render_file(source, destination)
6
9
  request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
7
10
  browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
@@ -1,9 +1,18 @@
1
-
2
-
3
- # def cache_buster
4
- # if File.readable?(real_path)
5
- # File.mtime(real_path).strftime("%s")
6
- # else
7
- # $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
8
- # end
9
- # end
1
+ class Middleman::Base
2
+ helpers do
3
+ alias_method :pre_cache_buster_asset_url, :asset_url
4
+ def asset_url(path, prefix="")
5
+ path = pre_cache_buster_asset_url(path, prefix)
6
+ if path.include?("://")
7
+ path
8
+ else
9
+ real_path = File.join(options.public, path)
10
+ if File.readable?(real_path)
11
+ path << "?" + File.mtime(real_path).strftime("%s")
12
+ else
13
+ $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -17,9 +17,9 @@ class Middleman::Base
17
17
  false
18
18
  end
19
19
  end
20
-
21
- config.http_images_path = "/#{self.images_dir}"
22
- config.http_stylesheets_path = "/#{self.css_dir}"
20
+
21
+ config.http_images_path = File.join(self.http_prefix, self.images_dir)
22
+ config.http_stylesheets_path = File.join(self.http_prefix, self.css_dir)
23
23
  config.add_import_path(config.sass_dir)
24
24
  end
25
25
 
@@ -1,3 +1,5 @@
1
+ require 'haml'
2
+
1
3
  module Middleman
2
4
  module Haml
3
5
  def self.included(base)
@@ -70,7 +72,7 @@ module Middleman
70
72
  static_version = options.public + request.path_info
71
73
  send_file(static_version) if File.exists? static_version
72
74
 
73
- location_of_sass_file = options.environment == "build" ? "build" : "views"
75
+ location_of_sass_file = options.environment == "build" ? "build" : "public"
74
76
  css_filename = File.join(Dir.pwd, location_of_sass_file) + request.path_info
75
77
  sass(path.to_sym, Compass.sass_engine_options.merge({ :css_filename => css_filename }))
76
78
  rescue Exception => e
@@ -8,12 +8,15 @@ class Middleman::Base
8
8
  end
9
9
 
10
10
  helpers do
11
- def asset_url(path)
11
+ alias_method :pre_relative_asset_url, :asset_url
12
+ def asset_url(path, prefix="")
13
+ path = pre_relative_asset_url(path, prefix)
12
14
  if path.include?("://")
13
15
  path
14
16
  else
17
+ path = path[1,path.length-1] if path[0,1] == '/'
15
18
  request_path = request.path_info.dup
16
- request_path << "index.html" if path.match(%r{/$})
19
+ request_path << options.index_file if path.match(%r{/$})
17
20
  request_path.gsub!(%r{^/}, '')
18
21
  parts = request_path.split('/')
19
22
 
@@ -1,5 +1,24 @@
1
1
  require 'slickmap'
2
2
 
3
- get '/sitemap.html' do
4
- haml :sitemap, :layout => false
5
- end
3
+ class Middleman::Base
4
+ def build_sitemap(&block)
5
+ # views - stylesheets
6
+ # public
7
+ # .select
8
+ # block.call(this)
9
+ end
10
+
11
+ get '/sitemap.html' do
12
+ @tree = build_sitemap do |file_name|
13
+ true
14
+ end
15
+ haml :sitemap, :layout => false
16
+ end
17
+
18
+ use_in_file_templates!
19
+ end
20
+
21
+ __END__
22
+
23
+ @@ sitemap
24
+ %div.title Hello world!!!!!
@@ -2,7 +2,7 @@ module Middleman
2
2
  module Helpers
3
3
  def page_classes(*additional)
4
4
  path = request.path_info
5
- path << "index.html" if path.match(%r{/$})
5
+ path << options.index_file if path.match(%r{/$})
6
6
  path.gsub!(%r{^/}, '')
7
7
 
8
8
  classes = []
@@ -20,26 +20,27 @@ module Middleman
20
20
  %Q{<a #{params}>#{title}</a>}
21
21
  end
22
22
 
23
- def asset_url(path)
24
- path.include?("://") ? path : "/#{path}"
23
+ def asset_url(path, prefix="")
24
+ base_url = File.join(options.http_prefix, prefix)
25
+ path.include?("://") ? path : File.join(base_url, path)
25
26
  end
26
27
 
27
- def image_tag(path, options={})
28
- options[:alt] ||= ""
29
- params = options.merge(:src => asset_url(path))
28
+ def image_tag(path, params={})
29
+ params[:alt] ||= ""
30
+ params = params.merge(:src => asset_url(path, options.images_dir))
30
31
  params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
31
32
  "<img #{params} />"
32
33
  end
33
34
 
34
- def javascript_include_tag(path, options={})
35
- params = options.merge(:src => asset_url(path), :type => "text/javascript")
35
+ def javascript_include_tag(path, params={})
36
+ params = params.merge(:src => asset_url(path, options.js_dir), :type => "text/javascript")
36
37
  params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
37
38
  "<script #{params}></script>"
38
39
  end
39
40
 
40
- def stylesheet_link_tag(path, options={})
41
- options[:rel] ||= "stylesheet"
42
- params = options.merge(:href => asset_url(path), :type => "text/css")
41
+ def stylesheet_link_tag(path, params={})
42
+ params[:rel] ||= "stylesheet"
43
+ params = params.merge(:href => asset_url(path, options.css_dir), :type => "text/css")
43
44
  params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
44
45
  "<link #{params} />"
45
46
  end
@@ -2,21 +2,17 @@
2
2
  helpers do
3
3
  end
4
4
 
5
- # Or inject more templating languages
6
- # helpers Sinatra::Markdown
5
+ # Generic configuration
6
+ # enable :slickmap
7
7
 
8
8
  # Build-specific configuration
9
9
  configure :build do
10
- Compass.configuration do |config|
11
- # For example, change the Compass output style for deployment
12
- # config.output_style = :compressed
13
-
14
- # Or use a different image path
15
- # config.http_images_path = "/Content/images/"
16
-
17
- # Disable cache buster
18
- # config.asset_cache_buster do
19
- # false
20
- # end
21
- end
10
+ # For example, change the Compass output style for deployment
11
+ # enable :minified_css
12
+
13
+ # Or use a different image path
14
+ # set :http_path, "/Content/images/"
15
+
16
+ # Disable cache buster
17
+ # disable :cache_buster
22
18
  end
@@ -1 +1,4 @@
1
+ - content_for :head do
2
+ %title Custom head title
3
+
1
4
  %h1 The Middleman is watching.
@@ -1,6 +1,7 @@
1
1
  %html
2
2
  %head
3
3
  %title The Middleman!
4
+ = yield_content :head
4
5
 
5
6
  %body
6
7
  = yield
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{middleman}
8
- s.version = "0.9.4"
8
+ s.version = "0.9.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Thomas Reynolds"]
12
- s.date = %q{2009-09-30}
12
+ s.date = %q{2009-10-01}
13
13
  s.email = %q{tdreyno@gmail.com}
14
14
  s.executables = ["mm-init", "mm-build", "mm-server"]
15
15
  s.extra_rdoc_files = [
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
50
50
  "lib/middleman/template/views/stylesheets/site.sass",
51
51
  "middleman.gemspec",
52
52
  "spec/builder_spec.rb",
53
+ "spec/cache_buster_spec.rb",
53
54
  "spec/fixtures/sample/init.rb",
54
55
  "spec/fixtures/sample/public/javascripts/empty-with-include.js",
55
56
  "spec/fixtures/sample/public/javascripts/to-be-included.js",
@@ -64,6 +65,7 @@ Gem::Specification.new do |s|
64
65
  "spec/fixtures/sample/views/services/index.html.haml",
65
66
  "spec/fixtures/sample/views/stylesheets/site.css.sass",
66
67
  "spec/generator_spec.rb",
68
+ "spec/relative_assets_spec.rb",
67
69
  "spec/spec_helper.rb"
68
70
  ]
69
71
  s.has_rdoc = true
@@ -75,8 +77,10 @@ Gem::Specification.new do |s|
75
77
  s.summary = %q{A static site generator utilizing Haml, Sass and providing YUI compression and cache busting}
76
78
  s.test_files = [
77
79
  "spec/builder_spec.rb",
80
+ "spec/cache_buster_spec.rb",
78
81
  "spec/fixtures/sample/init.rb",
79
82
  "spec/generator_spec.rb",
83
+ "spec/relative_assets_spec.rb",
80
84
  "spec/spec_helper.rb"
81
85
  ]
82
86
 
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ base = ::Middleman::Base
4
+ base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
5
+
6
+ describe "Cache Buster Feature" do
7
+ before do
8
+ base.disable :cache_buster
9
+ base.init!
10
+ @app = base.new
11
+ end
12
+
13
+ it "should not append query string if off" do
14
+ @app.asset_url("stylesheets/static.css").should_not include("?")
15
+ end
16
+ end
17
+
18
+ describe "Cache Buster Feature" do
19
+ before do
20
+ base.enable :cache_buster
21
+ base.init!
22
+ @app = base.new
23
+ end
24
+
25
+ it "should append query string if on" do
26
+ @app.asset_url("stylesheets/static.css").should include("?")
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # require File.join(File.dirname(__FILE__), "spec_helper")
2
+ #
3
+ # base = ::Middleman::Base
4
+ # base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
5
+ #
6
+ # describe "Relative Assets Feature" do
7
+ # before do
8
+ # base.disable :relative_assets
9
+ # base.init!
10
+ # @app = base.new
11
+ # end
12
+ #
13
+ # it "should not contain ../ if off" do
14
+ # @app.asset_url("stylesheets/static.css").should_not include("?")
15
+ # end
16
+ # end
17
+ #
18
+ # describe "Relative Assets Feature" do
19
+ # before do
20
+ # base.enable :relative_assets
21
+ # base.init!
22
+ # @app = base.new
23
+ # end
24
+ #
25
+ # it "should contain ../ if on" do
26
+ # @app.asset_url("stylesheets/static.css").should include("?")
27
+ # end
28
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-30 00:00:00 -07:00
12
+ date: 2009-10-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,7 @@ files:
137
137
  - lib/middleman/template/views/stylesheets/site.sass
138
138
  - middleman.gemspec
139
139
  - spec/builder_spec.rb
140
+ - spec/cache_buster_spec.rb
140
141
  - spec/fixtures/sample/init.rb
141
142
  - spec/fixtures/sample/public/javascripts/empty-with-include.js
142
143
  - spec/fixtures/sample/public/javascripts/to-be-included.js
@@ -151,6 +152,7 @@ files:
151
152
  - spec/fixtures/sample/views/services/index.html.haml
152
153
  - spec/fixtures/sample/views/stylesheets/site.css.sass
153
154
  - spec/generator_spec.rb
155
+ - spec/relative_assets_spec.rb
154
156
  - spec/spec_helper.rb
155
157
  has_rdoc: true
156
158
  homepage: http://wiki.github.com/tdreyno/middleman
@@ -180,6 +182,8 @@ specification_version: 2
180
182
  summary: A static site generator utilizing Haml, Sass and providing YUI compression and cache busting
181
183
  test_files:
182
184
  - spec/builder_spec.rb
185
+ - spec/cache_buster_spec.rb
183
186
  - spec/fixtures/sample/init.rb
184
187
  - spec/generator_spec.rb
188
+ - spec/relative_assets_spec.rb
185
189
  - spec/spec_helper.rb