middleman 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -47,15 +47,33 @@ task :spec => :check_dependencies
47
47
  task :default => :spec
48
48
 
49
49
  require 'rake/rdoctask'
50
+ require 'sdoc'
51
+
50
52
  Rake::RDocTask.new do |rdoc|
51
53
  if File.exist?('VERSION')
52
54
  version = File.read('VERSION')
53
55
  else
54
56
  version = ""
55
57
  end
58
+
59
+ # rdoc.template = 'direct'
56
60
 
57
61
  rdoc.rdoc_dir = 'rdoc'
58
62
  rdoc.title = "middleman #{version}"
59
63
  rdoc.rdoc_files.include('README*')
60
64
  rdoc.rdoc_files.include('lib/**/*.rb')
65
+ rdoc.rdoc_files.exclude('lib/middleman/features/sprockets+ruby19.rb')
66
+ end
67
+
68
+ desc "Build and publish documentation using GitHub Pages."
69
+ task :pages do
70
+ if !`git status`.include?('nothing to commit')
71
+ abort "dirty index - not publishing!"
72
+ end
73
+
74
+ Rake::Task[:rerdoc].invoke
75
+ `git checkout gh-pages`
76
+ `ls -1 | grep -v rdoc | xargs rm -rf; mv rdoc/* .; rm -rf rdoc`
77
+ `git commit -a -m "update docs"; git push origin gh-pages`
78
+ `git checkout master`
61
79
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.7
1
+ 0.9.8
@@ -48,16 +48,40 @@ module Generators
48
48
 
49
49
  glob! File.basename(Middleman::Base.public), Middleman::Base.supported_formats
50
50
  glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats
51
+
52
+ if Middleman::Base.slickmap?
53
+ template :slickmap, "sitemap.html", "sitemap.html"
54
+ end
51
55
  end
52
56
 
53
57
  add :build, Builder
54
58
  end
55
59
 
56
60
  # Monkey-patch to use a dynamic renderer
61
+ class Templater::Actions::File
62
+ def identical?
63
+ if exists?
64
+ return true if File.mtime(source) < File.mtime(destination)
65
+ ::FileUtils.identical?(source, destination)
66
+ else
67
+ false
68
+ end
69
+ end
70
+ end
71
+
57
72
  class Templater::Actions::Template
58
73
  def render
59
74
  ::Middleman::Builder.render_file(source, destination)
60
75
  end
76
+
77
+ def identical?
78
+ if ::File.exists?(destination)
79
+ return true if File.exists?(source) && File.mtime(source) < File.mtime(destination)
80
+ ::File.read(destination) == render
81
+ else
82
+ false
83
+ end
84
+ end
61
85
  end
62
86
 
63
87
  Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV))
@@ -8,9 +8,10 @@ module Generators
8
8
  class NewSite < Templater::Generator
9
9
  desc "Creates a new staticmatic scaffold."
10
10
  first_argument :location, :required => true, :desc => "Project location"
11
-
12
- # css_dir
13
- # images_dir
11
+
12
+ option :css_dir, :desc => 'The path to the css files'
13
+ option :js_dir, :desc => 'The path to the javascript files'
14
+ option :images_dir, :desc => 'The path to the image files'
14
15
 
15
16
  def destination_root
16
17
  File.expand_path(location)
@@ -20,12 +21,13 @@ module Generators
20
21
  File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'template')
21
22
  end
22
23
 
23
- file :init, "init.rb"
24
+ template :init, "init.rb"
24
25
  glob! :views
25
26
  glob! :public
26
- empty_directory :stylesheets, "public/stylesheets"
27
- empty_directory :javascripts, "public/javascripts"
28
- empty_directory :images, "public/images"
27
+
28
+ empty_directory :stylesheets, "public/stylesheets"#, File.join("public", css_dir)
29
+ empty_directory :javascripts, "public/javascripts"#, File.join("public", js_dir)
30
+ empty_directory :images, "public/images"#, File.join("public", images_dir)
29
31
  end
30
32
 
31
33
  add :setup, NewSite
@@ -4,19 +4,13 @@ require 'rubygems' unless ENV['NO_RUBYGEMS']
4
4
  # We're riding on Sinatra, so let's include it
5
5
  require 'sinatra/base'
6
6
 
7
- # Rack helper for adding mime-types during local preview
8
- def mime(ext, type)
9
- ext = ".#{ext}" unless ext.to_s[0] == ?.
10
- Rack::Mime::MIME_TYPES[ext.to_s] = type
11
- end
12
-
13
7
  module Middleman
14
8
  class Base < Sinatra::Base
15
9
  set :app_file, __FILE__
16
10
  set :root, Dir.pwd
17
11
  set :environment, ENV['MM_ENV'] || :development
18
- set :supported_formats, []
19
- set :index_file, 'index.html'
12
+ set :supported_formats, ["erb"]
13
+ set :index_file, "index.html"
20
14
  set :js_dir, "javascripts"
21
15
  set :css_dir, "stylesheets"
22
16
  set :images_dir, "images"
@@ -36,6 +30,7 @@ module Middleman
36
30
  disable :relative_assets
37
31
  disable :markaby
38
32
  disable :maruku
33
+ disable :smush_pngs
39
34
 
40
35
  # Default build features
41
36
  configure :build do
@@ -44,6 +39,12 @@ module Middleman
44
39
  enable :cache_buster
45
40
  end
46
41
 
42
+ # Rack helper for adding mime-types during local preview
43
+ def mime(ext, type)
44
+ ext = ".#{ext}" unless ext.to_s[0] == ?.
45
+ Rack::Mime::MIME_TYPES[ext.to_s] = type
46
+ end
47
+
47
48
  # Convenience function to discover if a tempalte exists for the requested renderer (haml, sass, etc)
48
49
  def template_exists?(path, renderer=nil)
49
50
  template_path = path.dup
@@ -5,7 +5,7 @@ require 'rack/test'
5
5
  module Middleman
6
6
  class Builder
7
7
  # The default render just requests the page over Rack and writes the response
8
- def self.render_file(source, destination)
8
+ def self.render_file(source, destination)
9
9
  request_path = destination.gsub(File.join(Dir.pwd, Middleman::Base.build_dir), "")
10
10
  browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base))
11
11
  browser.get(request_path)
@@ -1,17 +1,14 @@
1
1
  class Middleman::Base
2
+ alias_method :pre_cache_buster_asset_url, :asset_url
2
3
  helpers do
3
- alias_method :pre_cache_buster_asset_url, :asset_url
4
4
  def asset_url(path, prefix="")
5
- path = pre_cache_buster_asset_url(path, prefix)
6
- if path.include?("://")
7
- path
5
+ http_path = pre_cache_buster_asset_url(path, prefix)
6
+ if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
7
+ http_path
8
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
9
+ real_path = File.join(self.class.environment == "build" ? options.build_dir : options.public, prefix, path)
10
+ http_path << "?" + File.mtime(real_path).strftime("%s") if File.readable?(real_path)
11
+ http_path
15
12
  end
16
13
  end
17
14
  end
@@ -2,62 +2,64 @@ require 'haml'
2
2
 
3
3
  module Middleman
4
4
  module Haml
5
- def self.included(base)
6
- base.supported_formats << "haml"
7
- base.helpers Middleman::HamlHelpers
8
- end
5
+ module Renderer
6
+ def self.included(base)
7
+ base.supported_formats << "haml"
8
+ base.helpers Middleman::Haml::Helpers
9
+ end
9
10
 
10
- def render_path(path)
11
- if template_exists?(path, :haml)
12
- result = nil
13
- begin
14
- result = haml(path.to_sym, :layout => File.extname(path) != ".xml")
15
- rescue ::Haml::Error => e
16
- result = "Haml Error: #{e}"
17
- result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
11
+ def render_path(path)
12
+ if template_exists?(path, :haml)
13
+ result = nil
14
+ begin
15
+ result = haml(path.to_sym, :layout => File.extname(path) != ".xml")
16
+ rescue ::Haml::Error => e
17
+ result = "Haml Error: #{e}"
18
+ result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
19
+ end
20
+ result
21
+ else
22
+ super
18
23
  end
19
- result
20
- else
21
- super
22
24
  end
23
25
  end
24
- end
25
26
 
26
- module HamlHelpers
27
- def haml_partial(name, options = {})
28
- item_name = name.to_sym
29
- counter_name = "#{name}_counter".to_sym
30
- if collection = options.delete(:collection)
31
- collection.enum_for(:each_with_index).collect do |item,index|
32
- haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
33
- end.join
34
- elsif object = options.delete(:object)
35
- haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
36
- else
37
- haml "_#{name}".to_sym, options.merge(:layout => false)
27
+ module Helpers
28
+ def haml_partial(name, options = {})
29
+ item_name = name.to_sym
30
+ counter_name = "#{name}_counter".to_sym
31
+ if collection = options.delete(:collection)
32
+ collection.enum_for(:each_with_index).collect do |item,index|
33
+ haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
34
+ end.join
35
+ elsif object = options.delete(:object)
36
+ haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
37
+ else
38
+ haml "_#{name}".to_sym, options.merge(:layout => false)
39
+ end
38
40
  end
39
41
  end
40
- end
41
42
 
42
- module Table
43
- include ::Haml::Filters::Base
43
+ module Table
44
+ include ::Haml::Filters::Base
44
45
 
45
- def render(text)
46
- output = '<div class="table"><table cellspacing="0" cellpadding="0">'
47
- line_num = 0
48
- text.each_line do |line|
49
- line_num += 1
50
- next if line.strip.empty?
51
- output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
46
+ def render(text)
47
+ output = '<div class="table"><table cellspacing="0" cellpadding="0">'
48
+ line_num = 0
49
+ text.each_line do |line|
50
+ line_num += 1
51
+ next if line.strip.empty?
52
+ output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
52
53
 
53
- columns = line.split("|").map { |p| p.strip }
54
- columns.each_with_index do |col, i|
55
- output << %Q{<td class="col#{i+1}">#{col}</td>}
56
- end
54
+ columns = line.split("|").map { |p| p.strip }
55
+ columns.each_with_index do |col, i|
56
+ output << %Q{<td class="col#{i+1}">#{col}</td>}
57
+ end
57
58
 
58
- output << "</tr>"
59
+ output << "</tr>"
60
+ end
61
+ output + "</table></div>"
59
62
  end
60
- output + "</table></div>"
61
63
  end
62
64
  end
63
65
 
@@ -72,7 +74,7 @@ module Middleman
72
74
  static_version = options.public + request.path_info
73
75
  send_file(static_version) if File.exists? static_version
74
76
 
75
- location_of_sass_file = options.environment == "build" ? "build" : "public"
77
+ location_of_sass_file = options.environment == "build" ? File.join(options.build_dir, options.css_dir) : "public"
76
78
  css_filename = File.join(Dir.pwd, location_of_sass_file) + request.path_info
77
79
  sass(path.to_sym, Compass.sass_engine_options.merge({ :css_filename => css_filename }))
78
80
  rescue Exception => e
@@ -125,6 +127,6 @@ END
125
127
  end
126
128
 
127
129
  class Middleman::Base
128
- include Middleman::Haml
130
+ include Middleman::Haml::Renderer
129
131
  include Middleman::Sass
130
132
  end
@@ -12,20 +12,20 @@ module Middleman
12
12
  END
13
13
  end
14
14
  end
15
- end
16
15
 
17
- module Compressor
18
- def render_path(path)
19
- if template_exists?(path, :js)
20
- compressor = YUI::JavaScriptCompressor.new(:munge => true)
21
- compressor.compress(super)
22
- else
23
- super
16
+ module StaticJavascript
17
+ def render_path(path)
18
+ if template_exists?(path, :js)
19
+ compressor = YUI::JavaScriptCompressor.new(:munge => true)
20
+ compressor.compress(super)
21
+ else
22
+ super
23
+ end
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
28
  class Base
29
- include Middleman::Compressor
29
+ include Middleman::Minified::StaticJavascript
30
30
  end
31
31
  end
@@ -1,16 +1,83 @@
1
- require 'slickmap'
1
+ begin
2
+ require 'slickmap'
3
+ ::Compass.configure_sass_plugin!
4
+ rescue LoadError
5
+ puts "Slickmap not available. Install it with: gem install compass-slickmap"
6
+ end
7
+
8
+ Entry = Struct.new(:dir, :children)
2
9
 
3
10
  class Middleman::Base
4
11
  def build_sitemap(&block)
5
- # views - stylesheets
6
- # public
7
- # .select
8
- # block.call(this)
12
+ html_files = Dir[File.join(File.dirname(Middleman::Base.views), "**", "*.html*")]
13
+
14
+ @@utility = []
15
+ [recurse_sitemap(Middleman::Base.views, &block), @@utility]
16
+ end
17
+
18
+ def recurse_sitemap(path, &block)
19
+ bad_ext = path.split('.html')[1]
20
+ path = path.gsub(bad_ext, '') if bad_ext
21
+ entry = Entry.new(path, [])
22
+
23
+ #no "." or ".." dirs
24
+ Dir[File.join(path, "*")].each do |e|
25
+ next if !File.directory?(e) && !e.include?(".html")
26
+ if File.directory?(e)
27
+ entry.children << recurse_sitemap(e, &block)
28
+ elsif block_given?
29
+ how_to_handle = block.call(e)
30
+ if how_to_handle == :valid
31
+ entry.children << recurse_sitemap(e, &block)
32
+ elsif how_to_handle == :utility
33
+ bad_ext = e.split('.html')[1]
34
+ e = e.gsub(bad_ext, '') if bad_ext
35
+ @@utility << e.gsub(Middleman::Base.views + "/", '')
36
+ end
37
+ end
38
+ end
39
+
40
+ entry
41
+ end
42
+
43
+ helpers do
44
+ def sitemap_node(n, first=false)
45
+ if n.children.length < 1
46
+ if !first && File.extname(n.dir).length > 0
47
+ haml_tag :li do
48
+ path = n.dir.gsub(self.class.views, '')
49
+ haml_concat link_to(File.basename(path), path)
50
+ end
51
+ end
52
+ else
53
+ haml_tag(:li, :id => first ? "home" : nil) do
54
+ if first
55
+ haml_concat link_to("Homepage", "/" + self.class.index_file)
56
+ else
57
+ # we are a dir
58
+ index = n.children.find { |c| c.dir.include?(self.class.index_file) }
59
+ haml_concat link_to(index.dir.gsub(self.class.views + "/", '').gsub("/" + File.basename(index.dir), '').capitalize, index.dir.gsub(self.class.views, ''))
60
+ end
61
+
62
+ other_children = n.children.select { |c| !c.dir.include?(self.class.index_file) }
63
+ if other_children.length > 0
64
+ if first
65
+ other_children.each { |i| sitemap_node(i) }
66
+ else
67
+ haml_tag :ul do
68
+ other_children.each { |i| sitemap_node(i) }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
9
75
  end
10
76
 
11
77
  get '/sitemap.html' do
12
- @tree = build_sitemap do |file_name|
13
- true
78
+ # Return :utility to put it util top menu. False to ignore
79
+ @tree, @utility = build_sitemap do |file_name|
80
+ :valid
14
81
  end
15
82
  haml :sitemap, :layout => false
16
83
  end
@@ -21,4 +88,30 @@ end
21
88
  __END__
22
89
 
23
90
  @@ sitemap
24
- %div.title Hello world!!!!!
91
+ !!!
92
+ %html{ :xmlns => "http://www.w3.org/1999/xhtml" }
93
+ %head
94
+ %meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-type" }
95
+ %title Sitemap
96
+ %style{ :type => "text/css" }
97
+ :sass
98
+ @import slickmap.sass
99
+ +slickmap
100
+ :javascript
101
+ window.onload = function() {
102
+ document.getElementById('primaryNav').className = "col" + document.querySelectorAll("#primaryNav > li:not(#home)").length;
103
+ };
104
+
105
+ %body
106
+ .logo
107
+ %h1= @project_name || "Sitemap"
108
+ - if @project_subtitle
109
+ %h2= @project_subtitle
110
+
111
+ - if @utility.length > 0
112
+ %ul#utilityNav
113
+ - @utility.each do |u|
114
+ %li= link_to u, u
115
+
116
+ %ul#primaryNav
117
+ - sitemap_node(@tree, true)
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ begin
5
+ require 'httpclient'
6
+ rescue LoadError
7
+ puts "httpclient not available. Install it with: gem install httpclient"
8
+ end
9
+
10
+ module Middleman
11
+ module SmushPngs
12
+ def self.included(base)
13
+ base.supported_formats << "png"
14
+ end
15
+
16
+ def render_path(file)
17
+ if File.extname(file) == ".png"
18
+ file = File.join(options.public, file)
19
+ optimized = optimized_image_data_for(file)
20
+
21
+ begin
22
+ raise "Error: got larger" if size(file) < optimized.size
23
+ raise "Error: empty file downloaded" if optimized.size < 20
24
+
25
+ optimized
26
+ rescue
27
+ File.read(file)
28
+ end
29
+ else
30
+ super
31
+ end
32
+ end
33
+
34
+ protected
35
+ def size(file)
36
+ File.exist?(file) ? File.size(file) : 0
37
+ end
38
+
39
+ def optimized_image_data_for(file)
40
+ # I leave these urls here, just in case it stops working again...
41
+ # url = "http://smush.it/ws.php" # original, redirects to somewhere else..
42
+ url = 'http://ws1.adq.ac4.yahoo.com/ysmush.it/ws.php'
43
+ # url = "http://developer.yahoo.com/yslow/smushit/ws.php" # official but does not work
44
+ # url = "http://smushit.com/ysmush.it/ws.php" # used at the new page but does not hande uploads
45
+ # url = "http://smushit.eperf.vip.ac4.yahoo.com/ysmush.it/ws.php" # used at the new page but does not hande uploads
46
+ response = HTTPClient.post url, { 'files[]' => File.new(file) }
47
+ response = JSON.parse(response.body.content)
48
+ raise "smush.it: #{response['error']}" if response['error']
49
+ image_url = response['dest']
50
+ raise "no dest path found" unless image_url
51
+ open(image_url) { |source| source.read() }
52
+ end
53
+ end
54
+
55
+ class Base
56
+ include Middleman::SmushPngs
57
+ end
58
+ end
@@ -1,3 +1,7 @@
1
+ <% if css_dir %>set :css_dir, "<%= css_dir -%>"<% end %>
2
+ <% if js_dir %>set :js_dir, "<%= js_dir -%>"<% end %>
3
+ <% if images_dir %>set :images_dir, "<%= images_dir -%>"<% end %>
4
+
1
5
  # Helpers
2
6
  helpers do
3
7
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{middleman}
8
- s.version = "0.9.7"
8
+ s.version = "0.9.8"
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-10-01}
12
+ s.date = %q{2009-10-06}
13
13
  s.email = %q{tdreyno@gmail.com}
14
14
  s.executables = ["mm-init", "mm-build", "mm-server"]
15
15
  s.extra_rdoc_files = [
@@ -41,10 +41,11 @@ Gem::Specification.new do |s|
41
41
  "lib/middleman/features/minify_javascript.rb",
42
42
  "lib/middleman/features/relative_assets.rb",
43
43
  "lib/middleman/features/slickmap.rb",
44
+ "lib/middleman/features/smush_pngs.rb",
44
45
  "lib/middleman/features/sprockets+ruby19.rb",
45
46
  "lib/middleman/features/sprockets.rb",
46
47
  "lib/middleman/helpers.rb",
47
- "lib/middleman/template/init.rb",
48
+ "lib/middleman/template/init.rbt",
48
49
  "lib/middleman/template/views/index.html.haml",
49
50
  "lib/middleman/template/views/layout.html.haml",
50
51
  "lib/middleman/template/views/stylesheets/site.css.sass",
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.7
4
+ version: 0.9.8
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-10-01 00:00:00 -07:00
12
+ date: 2009-10-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -128,10 +128,11 @@ files:
128
128
  - lib/middleman/features/minify_javascript.rb
129
129
  - lib/middleman/features/relative_assets.rb
130
130
  - lib/middleman/features/slickmap.rb
131
+ - lib/middleman/features/smush_pngs.rb
131
132
  - lib/middleman/features/sprockets+ruby19.rb
132
133
  - lib/middleman/features/sprockets.rb
133
134
  - lib/middleman/helpers.rb
134
- - lib/middleman/template/init.rb
135
+ - lib/middleman/template/init.rbt
135
136
  - lib/middleman/template/views/index.html.haml
136
137
  - lib/middleman/template/views/layout.html.haml
137
138
  - lib/middleman/template/views/stylesheets/site.css.sass