middleman 3.0.0.alpha.2 → 3.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/.gitignore +2 -0
  2. data/.yardopts +5 -0
  3. data/CHANGELOG +5 -0
  4. data/README.md +3 -0
  5. data/Rakefile +0 -2
  6. data/bin/middleman +36 -33
  7. data/features/auto_layout.feature +37 -0
  8. data/features/builder.feature +1 -0
  9. data/features/chained_templates.feature +15 -0
  10. data/features/content_for.feature +16 -0
  11. data/features/directory_index.feature +1 -0
  12. data/features/front-matter.feature +2 -1
  13. data/features/partials.feature +35 -0
  14. data/features/support/env.rb +3 -3
  15. data/fixtures/chained-app/config.rb +0 -0
  16. data/fixtures/chained-app/data/article.yml +2 -0
  17. data/fixtures/chained-app/source/index.html.markdown.erb +8 -0
  18. data/fixtures/different-engine-layout/config.rb +0 -0
  19. data/fixtures/different-engine-layout/source/index.html.haml +1 -0
  20. data/fixtures/different-engine-layout/source/layout.erb +9 -0
  21. data/fixtures/engine-matching-layout/config.rb +0 -0
  22. data/fixtures/engine-matching-layout/source/index.html.erb +1 -0
  23. data/fixtures/engine-matching-layout/source/layout.erb +9 -0
  24. data/fixtures/indexable-app/source/.htaccess +1 -0
  25. data/fixtures/manual-layout-missing/config.rb +1 -0
  26. data/fixtures/manual-layout-missing/source/index.html.erb +1 -0
  27. data/fixtures/manual-layout-override/config.rb +3 -0
  28. data/fixtures/manual-layout-override/source/index.html.erb +1 -0
  29. data/fixtures/manual-layout-override/source/layouts/another.erb +9 -0
  30. data/fixtures/manual-layout-override/source/layouts/custom.erb +9 -0
  31. data/fixtures/manual-layout/config.rb +1 -0
  32. data/fixtures/manual-layout/source/index.html.erb +1 -0
  33. data/fixtures/manual-layout/source/layouts/custom.erb +9 -0
  34. data/fixtures/multiple-layouts/config.rb +0 -0
  35. data/fixtures/multiple-layouts/source/index.html.erb +1 -0
  36. data/fixtures/multiple-layouts/source/layout.erb +9 -0
  37. data/fixtures/multiple-layouts/source/layout.haml +6 -0
  38. data/fixtures/no-layout/config.rb +0 -0
  39. data/fixtures/no-layout/source/index.html.erb +1 -0
  40. data/fixtures/partials-app/config.rb +0 -0
  41. data/fixtures/partials-app/source/_locals.erb +1 -0
  42. data/fixtures/partials-app/source/_main.erb +1 -0
  43. data/fixtures/partials-app/source/_main.haml +1 -0
  44. data/fixtures/partials-app/source/index.html.erb +3 -0
  45. data/fixtures/partials-app/source/locals.html.erb +1 -0
  46. data/fixtures/partials-app/source/second.html.haml +3 -0
  47. data/fixtures/partials-app/source/shared/_footer.erb +1 -0
  48. data/fixtures/partials-app/source/shared/_header.erb +1 -0
  49. data/fixtures/partials-app/source/sub/_local.erb +1 -0
  50. data/fixtures/partials-app/source/sub/index.html.erb +3 -0
  51. data/fixtures/test-app/config.rb +6 -0
  52. data/fixtures/test-app/source/.htaccess +1 -0
  53. data/fixtures/test-app/source/content_for_erb.html.erb +5 -0
  54. data/fixtures/test-app/source/content_for_haml.html.haml +4 -0
  55. data/fixtures/test-app/source/content_for_slim.html.slim +4 -0
  56. data/fixtures/test-app/source/images/Chrome_Logo.svg +231 -0
  57. data/fixtures/test-app/source/images/cfb_tomb-perennial-energy.svgz +0 -0
  58. data/fixtures/test-app/source/index.html.haml +3 -0
  59. data/fixtures/test-app/source/layouts/content_for.erb +4 -0
  60. data/lib/middleman.rb +90 -105
  61. data/lib/middleman/base.rb +254 -239
  62. data/lib/middleman/builder.rb +51 -46
  63. data/lib/middleman/cache.rb +57 -0
  64. data/lib/middleman/cli.rb +7 -10
  65. data/lib/middleman/core_extensions/assets.rb +3 -3
  66. data/lib/middleman/core_extensions/compass.rb +25 -45
  67. data/lib/middleman/core_extensions/data.rb +14 -12
  68. data/lib/middleman/core_extensions/default_helpers.rb +11 -10
  69. data/lib/middleman/core_extensions/{features.rb → extensions.rb} +66 -20
  70. data/lib/middleman/core_extensions/front_matter.rb +16 -13
  71. data/lib/middleman/core_extensions/rendering.rb +224 -4
  72. data/lib/middleman/core_extensions/routing.rb +15 -12
  73. data/lib/middleman/core_extensions/sitemap.rb +6 -191
  74. data/lib/middleman/core_extensions/sprockets.rb +3 -2
  75. data/lib/middleman/extensions/asset_host.rb +34 -0
  76. data/lib/middleman/extensions/automatic_image_sizes.rb +38 -0
  77. data/lib/middleman/{features → extensions}/automatic_image_sizes/fastimage.rb +0 -0
  78. data/lib/middleman/extensions/cache_buster.rb +59 -0
  79. data/lib/middleman/extensions/directory_indexes.rb +62 -0
  80. data/lib/middleman/extensions/lorem.rb +130 -0
  81. data/lib/middleman/extensions/minify_css.rb +15 -0
  82. data/lib/middleman/{features → extensions}/minify_css/cssmin.rb +0 -0
  83. data/lib/middleman/extensions/minify_javascript.rb +54 -0
  84. data/lib/middleman/extensions/relative_assets.rb +46 -0
  85. data/lib/middleman/extensions/sitemap_tree.rb +38 -0
  86. data/lib/middleman/guard.rb +48 -35
  87. data/lib/middleman/renderers/erb.rb +3 -13
  88. data/lib/middleman/renderers/haml.rb +13 -0
  89. data/lib/middleman/renderers/liquid.rb +3 -3
  90. data/lib/middleman/renderers/markdown.rb +10 -12
  91. data/lib/middleman/renderers/sass.rb +3 -9
  92. data/lib/middleman/sitemap/page.rb +106 -0
  93. data/lib/middleman/sitemap/store.rb +141 -0
  94. data/lib/middleman/sitemap/template.rb +57 -0
  95. data/lib/middleman/step_definitions.rb +6 -0
  96. data/lib/middleman/step_definitions/builder_steps.rb +45 -0
  97. data/{features → lib/middleman}/step_definitions/generator_steps.rb +6 -6
  98. data/{features/step_definitions/middleman_steps.rb → lib/middleman/step_definitions/server_steps.rb} +3 -3
  99. data/lib/middleman/templates/default/source/index.html.erb +1 -1
  100. data/lib/middleman/version.rb +7 -1
  101. data/middleman-x86-mingw32.gemspec +1 -1
  102. data/middleman.gemspec +5 -3
  103. metadata +359 -381
  104. data/bin/mm-build +0 -9
  105. data/bin/mm-init +0 -9
  106. data/bin/mm-server +0 -9
  107. data/features/step_definitions/builder_steps.rb +0 -52
  108. data/features/tiny_src.feature +0 -15
  109. data/lib/middleman/features/asset_host.rb +0 -32
  110. data/lib/middleman/features/automatic_image_sizes.rb +0 -34
  111. data/lib/middleman/features/cache_buster.rb +0 -55
  112. data/lib/middleman/features/directory_indexes.rb +0 -59
  113. data/lib/middleman/features/lorem.rb +0 -126
  114. data/lib/middleman/features/minify_css.rb +0 -11
  115. data/lib/middleman/features/minify_javascript.rb +0 -50
  116. data/lib/middleman/features/relative_assets.rb +0 -42
  117. data/lib/middleman/features/sitemap_tree.rb +0 -34
@@ -0,0 +1,130 @@
1
+ module Middleman::Extensions
2
+ module Lorem
3
+ class << self
4
+ def registered(app)
5
+ app.send :include, InstanceMethods
6
+ end
7
+ alias :included :registered
8
+ end
9
+
10
+ module InstanceMethods
11
+ def lorem
12
+ @_lorem ||= LoremObject.new
13
+ end
14
+ end
15
+
16
+ # Adapted from Frank:
17
+ # https://github.com/blahed/frank/
18
+ # Copyright (c) 2010 Travis Dunn
19
+ #
20
+ # Permission is hereby granted, free of charge, to any person
21
+ # obtaining a copy of this software and associated documentation
22
+ # files (the "Software"), to deal in the Software without
23
+ # restriction, including without limitation the rights to use,
24
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ # copies of the Software, and to permit persons to whom the
26
+ # Software is furnished to do so, subject to the following
27
+ # conditions:
28
+ #
29
+ # The above copyright notice and this permission notice shall be
30
+ # included in all copies or substantial portions of the Software.
31
+ #
32
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
34
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
36
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
38
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
39
+ # OTHER DEALINGS IN THE SOFTWARE.
40
+ class LoremObject
41
+ WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
42
+
43
+ def word
44
+ words(1)
45
+ end
46
+
47
+ def words(total)
48
+ (1..total).map do
49
+ randm(WORDS)
50
+ end.join(' ')
51
+ end
52
+
53
+ def sentence
54
+ sentences(1)
55
+ end
56
+
57
+ def sentences(total)
58
+ (1..total).map do
59
+ words(randm(4..15)).capitalize
60
+ end.join('. ')
61
+ end
62
+
63
+ def paragraph
64
+ paragraphs(1)
65
+ end
66
+
67
+ def paragraphs(total)
68
+ (1..total).map do
69
+ sentences(randm(3..7)).capitalize
70
+ end.join("\n\n")
71
+ end
72
+
73
+ def date(fmt = '%a %b %d, %Y')
74
+ y = rand(20) + 1990
75
+ m = rand(12) + 1
76
+ d = rand(31) + 1
77
+ Time.local(y,m,d).strftime(fmt)
78
+ end
79
+
80
+ def name
81
+ "#{first_name} #{last_name}"
82
+ end
83
+
84
+ def first_name
85
+ names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ")
86
+ names[rand(names.size)]
87
+ end
88
+
89
+ def last_name
90
+ names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ")
91
+ names[rand(names.size)]
92
+ end
93
+
94
+ def email
95
+ delimiters = [ '_', '-', '' ]
96
+ domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
97
+ username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
98
+ "#{username}@#{domains[rand(domains.size)]}".downcase
99
+ end
100
+
101
+ def image(size, options={})
102
+ src = "http://placehold.it/#{size}"
103
+ hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
104
+ background_color = options[:background_color]
105
+ color = options[:color]
106
+
107
+ if options[:random_color]
108
+ background_color = hex.shuffle[0...6].join
109
+ color = hex.shuffle[0...6].join
110
+ end
111
+
112
+ src << "/#{background_color.sub(/^#/, '')}" if background_color
113
+ src << "/ccc" if background_color.nil? && color
114
+ src << "/#{color.sub(/^#/, '')}" if color
115
+ src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
116
+
117
+ src
118
+ end
119
+
120
+ private
121
+
122
+ def randm(range)
123
+ a = range.to_a
124
+ a[rand(a.length)]
125
+ end
126
+ end
127
+ end
128
+
129
+ register :lorem, Lorem
130
+ end
@@ -0,0 +1,15 @@
1
+ module Middleman::Extensions
2
+ module MinifyCss
3
+ class << self
4
+ def registered(app)
5
+ require "middleman/extensions/minify_css/cssmin"
6
+ app.after_configuration do
7
+ set :css_compressor, ::CSSMin
8
+ end
9
+ end
10
+ alias :included :registered
11
+ end
12
+ end
13
+
14
+ register :minify_css, MinifyCss
15
+ end
@@ -0,0 +1,54 @@
1
+ module Middleman::Extensions
2
+ module MinifyJavascript
3
+ class << self
4
+ def registered(app)
5
+ require 'uglifier'
6
+ app.after_configuration do
7
+ set :js_compressor, ::Uglifier.new
8
+ end
9
+ app.use InlineJavascriptRack
10
+ end
11
+ alias :included :registered
12
+ end
13
+
14
+ class InlineJavascriptRack
15
+ def initialize(app, options={})
16
+ @app = app
17
+ end
18
+
19
+ def call(env)
20
+ status, headers, response = @app.call(env)
21
+
22
+ if env["PATH_INFO"].match(/\.html$/)
23
+ compressor = ::Uglifier.new
24
+
25
+ uncompressed_source = case(response)
26
+ when String
27
+ response
28
+ when Array
29
+ response.join
30
+ when Rack::Response
31
+ response.body.join
32
+ when Rack::File
33
+ File.read(response.path)
34
+ end
35
+
36
+ minified = uncompressed_source.gsub(/(<scri.*?\/\/<!\[CDATA\[\n)(.*?)(\/\/\]\].*?<\/script>)/m) do |m|
37
+ first = $1
38
+ uncompressed_source = $2
39
+ last = $3
40
+ minified_js = compressor.compile(uncompressed_source)
41
+
42
+ first << minified_js << "\n" << last
43
+ end
44
+ headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
45
+ response = [minified]
46
+ end
47
+
48
+ [status, headers, response]
49
+ end
50
+ end
51
+ end
52
+
53
+ register :minify_javascript, MinifyJavascript
54
+ end
@@ -0,0 +1,46 @@
1
+ module Middleman::Extensions
2
+ module RelativeAssets
3
+ class << self
4
+ def registered(app)
5
+ app.compass_config do |config|
6
+ config.relative_assets = true
7
+ end
8
+
9
+ app.send :include, InstanceMethods
10
+ end
11
+ alias :included :registered
12
+ end
13
+
14
+ module InstanceMethods
15
+ def asset_url(path, prefix="")
16
+ begin
17
+ prefix = images_dir if prefix == http_images_path
18
+ rescue
19
+ end
20
+
21
+ if path.include?("://")
22
+ super(path, prefix)
23
+ elsif path[0,1] == "/"
24
+ path
25
+ else
26
+ path = File.join(prefix, path) if prefix.length > 0
27
+ request_path = @request_path.dup
28
+ request_path << index_file if path.match(%r{/$})
29
+ request_path.gsub!(%r{^/}, '')
30
+ parts = request_path.split('/')
31
+
32
+ if parts.length > 1
33
+ arry = []
34
+ (parts.length - 1).times { arry << ".." }
35
+ arry << path
36
+ File.join(*arry)
37
+ else
38
+ path
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ register :relative_assets, RelativeAssets
46
+ end
@@ -0,0 +1,38 @@
1
+ module Middleman::Extensions
2
+ module SitemapTree
3
+ class << self
4
+ def registered(app)
5
+ app.helpers Helpers
6
+ end
7
+ alias :included :registered
8
+ end
9
+
10
+ module Helpers
11
+ def sitemap_tree(regex=nil)
12
+ @sitemap_tree_cache = {}
13
+
14
+ key = regex.nil? ? "all" : regex
15
+
16
+ if !@sitemap_tree_cache.has_key?(key)
17
+ auto_hash = Hash.new{ |h,k| h[k] = Hash.new &h.default_proc }
18
+
19
+ app.sitemap.all_paths.each do |path|
20
+ next if !regex.nil? && !path.match(regex)
21
+ sub = auto_hash
22
+ path.split( "/" ).each{ |dir| sub[dir]; sub = sub[dir] }
23
+ end
24
+
25
+ @sitemap_tree_cache[key] = auto_hash
26
+ end
27
+
28
+ @sitemap_tree_cache[key]
29
+ end
30
+
31
+ def html_sitemap
32
+ sitemap_tree(/\.html$/)
33
+ end
34
+ end
35
+ end
36
+
37
+ register :sitemap_tree, SitemapTree
38
+ end
@@ -1,35 +1,39 @@
1
1
  require "guard"
2
2
  require "guard/guard"
3
3
  require "rbconfig"
4
+ require "net/http"
4
5
 
5
- if Config::CONFIG['host_os'].downcase =~ %r{mingw}
6
+ if RbConfig::CONFIG['host_os'].downcase =~ %r{mingw}
6
7
  require "win32/process"
7
8
  end
8
9
 
9
10
  module Middleman
10
11
  module Guard
11
- def self.add_guard(&block)
12
- # Deprecation Warning
13
- puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
14
- end
15
-
16
- def self.start(options={})
17
- options_hash = ""
18
- options.each do |k,v|
19
- options_hash << ", :#{k} => '#{v}'"
12
+ class << self
13
+ def add_guard(&block)
14
+ # Deprecation Warning
15
+ puts "== Middleman::Guard.add_guard has been removed. Update your extensions to versions which support this change."
20
16
  end
21
-
22
- guardfile_contents = %Q{
23
- guard 'middleman'#{options_hash} do
24
- watch(%r{(.*)})
17
+
18
+ def start(options={})
19
+ options_hash = ""
20
+ options.each do |k,v|
21
+ options_hash << ", :#{k} => '#{v}'"
25
22
  end
26
- }
23
+
24
+ guardfile_contents = %Q{
25
+ guard 'middleman'#{options_hash} do
26
+ watch(%r{(.*)})
27
+ end
28
+ }
27
29
 
28
- ::Guard.start({ :guardfile_contents => guardfile_contents })
30
+ ::Guard.start({ :guardfile_contents => guardfile_contents })
31
+ end
29
32
  end
30
33
  end
31
34
  end
32
35
 
36
+ # @private
33
37
  module Guard
34
38
  class Middleman < Guard
35
39
  def initialize(watchers = [], options = {})
@@ -58,20 +62,16 @@ module Guard
58
62
 
59
63
  if needs_to_restart
60
64
  reload
61
- elsif !@app.nil?
65
+ else
62
66
  paths.each do |path|
63
- @app.logger.debug :file_change, Time.now, path if @app.settings.logging?
64
- @app.file_did_change(path)
67
+ file_did_change(path)
65
68
  end
66
69
  end
67
70
  end
68
71
 
69
72
  def run_on_deletion(paths)
70
- if !@app.nil?
71
- paths.each do |path|
72
- @app.logger.debug :file_remove, Time.now, path if @app.settings.logging?
73
- @app.file_did_delete(path)
74
- end
73
+ paths.each do |path|
74
+ file_did_delete(path)
75
75
  end
76
76
  end
77
77
 
@@ -80,19 +80,19 @@ module Guard
80
80
  # Quiet down Guard
81
81
  # ENV['GUARD_ENV'] = 'test' if @options[:debug] == "true"
82
82
 
83
- env = (@options[:environment] || "development").to_sym
84
- is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
85
- @app = ::Middleman.server.inst do
86
- set :environment, env
87
- set :logging, is_logging
88
- end
89
-
90
- app_rack = @app.class.to_rack_app
91
-
92
83
  @server_job = fork do
84
+ env = (@options[:environment] || "development").to_sym
85
+ is_logging = @options.has_key?(:debug) && (@options[:debug] == "true")
86
+ app = ::Middleman.server.inst do
87
+ set :environment, env
88
+ set :logging, is_logging
89
+ end
90
+
91
+ app_rack = app.class.to_rack_app
92
+
93
93
  opts = @options.dup
94
94
  opts[:app] = app_rack
95
- puts "== The Middleman is standing watch on port #{opts[:Port]||4567}"
95
+ puts "== The Middleman is standing watch on port #{opts[:port]||4567}"
96
96
  ::Middleman.start_server(opts)
97
97
  end
98
98
  end
@@ -102,7 +102,20 @@ module Guard
102
102
  Process.kill("KILL", @server_job)
103
103
  Process.wait @server_job
104
104
  @server_job = nil
105
- @app = nil
105
+ # @app = nil
106
+ end
107
+
108
+ def talk_to_server(params={})
109
+ uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
110
+ Net::HTTP.post_form(uri, {}.merge(params))
111
+ end
112
+
113
+ def file_did_change(path)
114
+ talk_to_server :change => path
115
+ end
116
+
117
+ def file_did_delete(path)
118
+ talk_to_server :delete => path
106
119
  end
107
120
  end
108
121
  end
@@ -1,16 +1,14 @@
1
- require "tilt"
2
-
3
1
  module Middleman::Renderers::ERb
4
2
  class << self
5
3
  def registered(app)
6
- app.send :include, InstanceMethods
7
-
8
4
  app.set :erb_engine, :erb
9
5
  app.set :erb_engine_prefix, ::Tilt
10
6
 
11
7
  app.after_configuration do
12
8
  if erb_engine.is_a? Symbol
13
- erb_engine = erb_tilt_template_from_symbol(erb_engine)
9
+ engine = engine.to_s
10
+ engine = engine == "erb" ? "ERB" : engine.camelize
11
+ erb_engine = erb_engine_prefix.const_get("#{engine}Template")
14
12
  end
15
13
 
16
14
  ::Tilt.prefer(erb_engine)
@@ -18,12 +16,4 @@ module Middleman::Renderers::ERb
18
16
  end
19
17
  alias :included :registered
20
18
  end
21
-
22
- module InstanceMethods
23
- def erb_tilt_template_from_symbol(engine)
24
- engine = engine.to_s
25
- engine = engine == "erb" ? "ERB" : engine.camelize
26
- erb_engine_prefix.const_get("#{engine}Template")
27
- end
28
- end
29
19
  end