middleman 2.0.9.pre-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG +47 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +20 -0
  7. data/README.md +19 -0
  8. data/Rakefile +15 -0
  9. data/bin/middleman +73 -0
  10. data/bin/mm-build +9 -0
  11. data/bin/mm-init +9 -0
  12. data/bin/mm-server +9 -0
  13. data/features/asset_host.feature +14 -0
  14. data/features/automatic_image_sizes.feature +16 -0
  15. data/features/builder.feature +23 -0
  16. data/features/cache_buster.feature +26 -0
  17. data/features/coffee-script.feature +17 -0
  18. data/features/data.feature +12 -0
  19. data/features/directory_index.feature +29 -0
  20. data/features/dynamic_pages.feature +33 -0
  21. data/features/front-matter.feature +7 -0
  22. data/features/generator.feature +8 -0
  23. data/features/helpers_auto_javascript_include_tag.feature +27 -0
  24. data/features/helpers_auto_stylesheet_link_tag.feature +27 -0
  25. data/features/helpers_page_classes.feature +17 -0
  26. data/features/liquid.feature +6 -0
  27. data/features/markdown.feature +7 -0
  28. data/features/minify_css.feature +24 -0
  29. data/features/minify_javascript.feature +23 -0
  30. data/features/padrino_helpers.feature +10 -0
  31. data/features/page_alias_and_layouts.feature +44 -0
  32. data/features/relative_assets.feature +44 -0
  33. data/features/scss-support.feature +12 -0
  34. data/features/sinatra.feature +6 -0
  35. data/features/slim.feature +7 -0
  36. data/features/sprockets.feature +21 -0
  37. data/features/sprockets_gems.feature +7 -0
  38. data/features/step_definitions/asset_host_steps.rb +8 -0
  39. data/features/step_definitions/builder_steps.rb +40 -0
  40. data/features/step_definitions/generator_steps.rb +30 -0
  41. data/features/step_definitions/middleman_steps.rb +46 -0
  42. data/features/step_definitions/page_layout_steps.rb +13 -0
  43. data/features/support/env.rb +3 -0
  44. data/features/tiny_src.feature +15 -0
  45. data/fixtures/indexable-app/config.rb +2 -0
  46. data/fixtures/indexable-app/source/a_folder/needs_index.html +1 -0
  47. data/fixtures/indexable-app/source/leave_me_alone.html +1 -0
  48. data/fixtures/indexable-app/source/needs_index.html +1 -0
  49. data/fixtures/indexable-app/source/regular/index.html +1 -0
  50. data/fixtures/relative-app/config.rb +0 -0
  51. data/fixtures/relative-app/source/images/blank.gif +0 -0
  52. data/fixtures/relative-app/source/stylesheets/relative_assets.css.sass +3 -0
  53. data/fixtures/sprockets-app/config.rb +1 -0
  54. data/fixtures/sprockets-app/source/jquery_include.js +1 -0
  55. data/fixtures/sprockets-app/source/library/javascripts/sprockets_base.js +5 -0
  56. data/fixtures/sprockets-app/source/library/javascripts/sprockets_sub.js +3 -0
  57. data/fixtures/test-app/config.rb +51 -0
  58. data/fixtures/test-app/data/test.yml +4 -0
  59. data/fixtures/test-app/source/_liquid_partial.liquid +1 -0
  60. data/fixtures/test-app/source/_partial.haml +1 -0
  61. data/fixtures/test-app/source/a_folder/needs_index.html +1 -0
  62. data/fixtures/test-app/source/asset_host.html.haml +1 -0
  63. data/fixtures/test-app/source/auto-css.html.haml +1 -0
  64. data/fixtures/test-app/source/auto-css/auto-css.html.haml +1 -0
  65. data/fixtures/test-app/source/auto-css/index.html.haml +1 -0
  66. data/fixtures/test-app/source/auto-css/sub/auto-css.html.haml +1 -0
  67. data/fixtures/test-app/source/auto-image-sizes.html.haml +1 -0
  68. data/fixtures/test-app/source/auto-js.html.haml +1 -0
  69. data/fixtures/test-app/source/auto-js/auto-js.html.haml +1 -0
  70. data/fixtures/test-app/source/auto-js/index.html.haml +1 -0
  71. data/fixtures/test-app/source/auto-js/sub/auto-js.html.haml +1 -0
  72. data/fixtures/test-app/source/cache-buster.html.haml +2 -0
  73. data/fixtures/test-app/source/custom-layout-dir/index.html.haml +1 -0
  74. data/fixtures/test-app/source/custom-layout.html.haml +1 -0
  75. data/fixtures/test-app/source/data.html.erb +1 -0
  76. data/fixtures/test-app/source/data2.html.liquid +2 -0
  77. data/fixtures/test-app/source/front-matter.html.erb +6 -0
  78. data/fixtures/test-app/source/images/Child folder/regular_file(example).txt +1 -0
  79. data/fixtures/test-app/source/images/Read me (example).txt +1 -0
  80. data/fixtures/test-app/source/images/blank.gif +0 -0
  81. data/fixtures/test-app/source/img/blank.gif +0 -0
  82. data/fixtures/test-app/source/index.html.haml +6 -0
  83. data/fixtures/test-app/source/inline-coffeescript.html.haml +3 -0
  84. data/fixtures/test-app/source/inline-css.html.haml +4 -0
  85. data/fixtures/test-app/source/inline-js.html.haml +7 -0
  86. data/fixtures/test-app/source/javascripts/auto-js.js +1 -0
  87. data/fixtures/test-app/source/javascripts/auto-js/auto-js.js +1 -0
  88. data/fixtures/test-app/source/javascripts/auto-js/index.js +1 -0
  89. data/fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js +1 -0
  90. data/fixtures/test-app/source/javascripts/broken-coffee.js.coffee +3 -0
  91. data/fixtures/test-app/source/javascripts/coffee_test.js.coffee +3 -0
  92. data/fixtures/test-app/source/javascripts/jquery.plugin.with.dots.js +1 -0
  93. data/fixtures/test-app/source/javascripts/jquery_base.js +5 -0
  94. data/fixtures/test-app/source/javascripts/multiple_engines.js.coffee.erb +1 -0
  95. data/fixtures/test-app/source/javascripts/sprockets_base.js +5 -0
  96. data/fixtures/test-app/source/javascripts/sprockets_sub.js +3 -0
  97. data/fixtures/test-app/source/layout.haml +6 -0
  98. data/fixtures/test-app/source/layouts/custom.haml +5 -0
  99. data/fixtures/test-app/source/liquid_master.html.liquid +1 -0
  100. data/fixtures/test-app/source/markdown.html.markdown +1 -0
  101. data/fixtures/test-app/source/needs_index.html +1 -0
  102. data/fixtures/test-app/source/padrino_test.html.haml +5 -0
  103. data/fixtures/test-app/source/page-classes.html.haml +1 -0
  104. data/fixtures/test-app/source/real.html +1 -0
  105. data/fixtures/test-app/source/real/index.html.erb +5 -0
  106. data/fixtures/test-app/source/relative_image.html.erb +1 -0
  107. data/fixtures/test-app/source/services/index.html.haml +1 -0
  108. data/fixtures/test-app/source/should_be_ignored.html +1 -0
  109. data/fixtures/test-app/source/should_be_ignored2.html +1 -0
  110. data/fixtures/test-app/source/should_be_ignored3.html +1 -0
  111. data/fixtures/test-app/source/slim.html.slim +7 -0
  112. data/fixtures/test-app/source/spaces in file.html.erb +1 -0
  113. data/fixtures/test-app/source/static.html +1 -0
  114. data/fixtures/test-app/source/stylesheets/asset_host.css.sass +3 -0
  115. data/fixtures/test-app/source/stylesheets/auto-css.css +3 -0
  116. data/fixtures/test-app/source/stylesheets/auto-css/auto-css.css +3 -0
  117. data/fixtures/test-app/source/stylesheets/auto-css/index.css +0 -0
  118. data/fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css +3 -0
  119. data/fixtures/test-app/source/stylesheets/layout.css.sass +2 -0
  120. data/fixtures/test-app/source/stylesheets/relative_assets.css.sass +3 -0
  121. data/fixtures/test-app/source/stylesheets/site.css.sass +1 -0
  122. data/fixtures/test-app/source/stylesheets/site_scss.css.scss +1 -0
  123. data/fixtures/test-app/source/stylesheets/static.css +2 -0
  124. data/fixtures/test-app/source/sub1/page-classes.html.haml +1 -0
  125. data/fixtures/test-app/source/sub1/sub2/page-classes.html.haml +1 -0
  126. data/fixtures/test-app/source/tiny_src.html.haml +1 -0
  127. data/lib/middleman.rb +202 -0
  128. data/lib/middleman/base.rb +198 -0
  129. data/lib/middleman/builder.rb +163 -0
  130. data/lib/middleman/cli.rb +87 -0
  131. data/lib/middleman/config.ru +2 -0
  132. data/lib/middleman/core_extensions/assets.rb +57 -0
  133. data/lib/middleman/core_extensions/builder.rb +41 -0
  134. data/lib/middleman/core_extensions/compass.rb +102 -0
  135. data/lib/middleman/core_extensions/data.rb +120 -0
  136. data/lib/middleman/core_extensions/default_helpers.rb +77 -0
  137. data/lib/middleman/core_extensions/features.rb +102 -0
  138. data/lib/middleman/core_extensions/front_matter.rb +116 -0
  139. data/lib/middleman/core_extensions/rack_map.rb +35 -0
  140. data/lib/middleman/core_extensions/rendering.rb +19 -0
  141. data/lib/middleman/core_extensions/routing.rb +87 -0
  142. data/lib/middleman/core_extensions/sprockets.rb +102 -0
  143. data/lib/middleman/features/asset_host.rb +22 -0
  144. data/lib/middleman/features/automatic_image_sizes.rb +31 -0
  145. data/lib/middleman/features/automatic_image_sizes/fastimage.rb +287 -0
  146. data/lib/middleman/features/cache_buster.rb +42 -0
  147. data/lib/middleman/features/directory_indexes.rb +56 -0
  148. data/lib/middleman/features/lorem.rb +126 -0
  149. data/lib/middleman/features/minify_css.rb +10 -0
  150. data/lib/middleman/features/minify_javascript.rb +43 -0
  151. data/lib/middleman/features/relative_assets.rb +38 -0
  152. data/lib/middleman/features/tiny_src.rb +11 -0
  153. data/lib/middleman/guard.rb +71 -0
  154. data/lib/middleman/renderers/coffee_script.rb +8 -0
  155. data/lib/middleman/renderers/haml.rb +31 -0
  156. data/lib/middleman/renderers/liquid.rb +29 -0
  157. data/lib/middleman/renderers/markdown.rb +34 -0
  158. data/lib/middleman/renderers/sass.rb +63 -0
  159. data/lib/middleman/renderers/slim.rb +8 -0
  160. data/lib/middleman/templates.rb +53 -0
  161. data/lib/middleman/templates/default.rb +17 -0
  162. data/lib/middleman/templates/default/source/index.html.erb +5 -0
  163. data/lib/middleman/templates/default/source/layout.erb +19 -0
  164. data/lib/middleman/templates/default/source/stylesheets/site.css.scss +32 -0
  165. data/lib/middleman/templates/html5.rb +16 -0
  166. data/lib/middleman/templates/html5/source/404.html +38 -0
  167. data/lib/middleman/templates/html5/source/README.md +388 -0
  168. data/lib/middleman/templates/html5/source/apple-touch-icon-114x114-precomposed.png +0 -0
  169. data/lib/middleman/templates/html5/source/apple-touch-icon-57x57-precomposed.png +0 -0
  170. data/lib/middleman/templates/html5/source/apple-touch-icon-72x72-precomposed.png +0 -0
  171. data/lib/middleman/templates/html5/source/apple-touch-icon-precomposed.png +0 -0
  172. data/lib/middleman/templates/html5/source/apple-touch-icon.png +0 -0
  173. data/lib/middleman/templates/html5/source/crossdomain.xml +25 -0
  174. data/lib/middleman/templates/html5/source/css/style.css +293 -0
  175. data/lib/middleman/templates/html5/source/favicon.ico +0 -0
  176. data/lib/middleman/templates/html5/source/humans.txt +43 -0
  177. data/lib/middleman/templates/html5/source/img/.gitignore +2 -0
  178. data/lib/middleman/templates/html5/source/index.html +79 -0
  179. data/lib/middleman/templates/html5/source/js/libs/jquery-1.6.2.js +8981 -0
  180. data/lib/middleman/templates/html5/source/js/libs/jquery-1.6.2.min.js +18 -0
  181. data/lib/middleman/templates/html5/source/js/libs/modernizr-2.0.6.min.js +4 -0
  182. data/lib/middleman/templates/html5/source/js/mylibs/.gitignore +2 -0
  183. data/lib/middleman/templates/html5/source/js/plugins.js +20 -0
  184. data/lib/middleman/templates/html5/source/js/script.js +8 -0
  185. data/lib/middleman/templates/html5/source/robots.txt +5 -0
  186. data/lib/middleman/templates/html5/source/test/index.html +31 -0
  187. data/lib/middleman/templates/html5/source/test/qunit/qunit.css +148 -0
  188. data/lib/middleman/templates/html5/source/test/qunit/qunit.js +1265 -0
  189. data/lib/middleman/templates/html5/source/test/tests.js +24 -0
  190. data/lib/middleman/templates/local.rb +20 -0
  191. data/lib/middleman/templates/shared/Gemfile.tt +3 -0
  192. data/lib/middleman/templates/shared/config.ru +4 -0
  193. data/lib/middleman/templates/shared/config.tt +104 -0
  194. data/lib/middleman/version.rb +3 -0
  195. data/middleman.gemspec +79 -0
  196. metadata +826 -0
@@ -0,0 +1,198 @@
1
+ require "i18n"
2
+
3
+ require "active_support"
4
+ require "active_support/json"
5
+ require "active_support/core_ext/class/attribute_accessors"
6
+
7
+ module Middleman::Base
8
+ class << self
9
+ def registered(app)
10
+ app.extend ClassMethods
11
+ app.send :include, InstanceMethods
12
+
13
+ # Basic Sinatra config
14
+ app.set :app_file, __FILE__
15
+ app.set :root, Dir.pwd
16
+ app.set :sessions, false
17
+ app.set :logging, false
18
+ app.set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
19
+
20
+ # Middleman-specific options
21
+ app.set :index_file, "index.html" # What file responds to folder requests
22
+ # Such as the homepage (/) or subfolders (/about/)
23
+
24
+ # These directories are passed directly to Compass
25
+ app.set :js_dir, "javascripts" # Where to look for javascript files
26
+ app.set :css_dir, "stylesheets" # Where to look for CSS files
27
+ app.set :images_dir, "images" # Where to look for images
28
+ app.set :fonts_dir, "fonts" # Where to look for fonts
29
+
30
+ app.set :build_dir, "build" # Which folder are builds output to
31
+ app.set :http_prefix, nil # During build, add a prefix for absolute paths
32
+
33
+ # Pass all request to Middleman, even "static" files
34
+ app.set :static, false
35
+
36
+ app.set :views, "source"
37
+
38
+ # Add Builder Callbacks
39
+ app.register Middleman::CoreExtensions::Builder
40
+
41
+ # Add Rack::Builder.map to Sinatra
42
+ app.register Middleman::CoreExtensions::RackMap
43
+
44
+ # Activate custom features
45
+ app.register Middleman::CoreExtensions::Features
46
+
47
+ # Activate Yaml Data package
48
+ app.register Middleman::CoreExtensions::Data
49
+
50
+ # Setup custom rendering
51
+ app.register Middleman::CoreExtensions::Rendering
52
+
53
+ # Compass framework
54
+ app.register Middleman::CoreExtensions::Compass
55
+
56
+ # Sprockets asset handling
57
+ app.register Middleman::CoreExtensions::Sprockets
58
+
59
+ # Setup asset path pipeline
60
+ app.register Middleman::CoreExtensions::Assets
61
+
62
+ # Activate built-in helpers
63
+ app.register Middleman::CoreExtensions::DefaultHelpers
64
+
65
+ # with_layout and page routing
66
+ app.register Middleman::CoreExtensions::Routing
67
+
68
+ # Parse YAML from templates
69
+ app.register Middleman::CoreExtensions::FrontMatter
70
+
71
+ app.set :default_features, [
72
+ :lorem
73
+ ]
74
+
75
+ # Default layout name
76
+ app.set :layout, :layout
77
+
78
+ # This will match all requests not overridden in the project's config.rb
79
+ app.not_found do
80
+ process_request
81
+ end
82
+
83
+ # Custom 404 handler (to be styled)
84
+ app.error Sinatra::NotFound do
85
+ content_type 'text/html'
86
+ "<html><body><h1>File Not Found</h1><p>#{request.path_info}</p></body>"
87
+ end
88
+
89
+ # See if Tilt cannot handle this file
90
+ app.before_processing(:base) do |result|
91
+ request_path = request.path_info.gsub("%20", " ")
92
+ should_be_ignored = !(request["is_proxy"]) && settings.excluded_paths.include?("/#{request_path}")
93
+
94
+ if result && !should_be_ignored
95
+ extensionless_path, template_engine = result
96
+
97
+ # Return static files
98
+ if !::Tilt.mappings.has_key?(template_engine.to_s)
99
+ content_type mime_type(File.extname(request_path)), :charset => 'utf-8'
100
+ status 200
101
+ send_file File.join(settings.views, request_path)
102
+ false
103
+ else
104
+ true
105
+ end
106
+ else
107
+ if !%w(favicon.ico).include?(request_path)
108
+ $stderr.puts "File not found: #{request_path}"
109
+ end
110
+
111
+ status 404
112
+ false
113
+ end
114
+ end
115
+ end
116
+ alias :included :registered
117
+ end
118
+
119
+ module ClassMethods
120
+ # Override Sinatra's set to accept a block
121
+ # Specifically for the asset_host feature
122
+ def set(option, value=self, &block)
123
+ if block_given?
124
+ value = Proc.new { block }
125
+ end
126
+
127
+ super(option, value, &nil)
128
+ end
129
+
130
+ def before_processing(name=:unnamed, idx=-1, &block)
131
+ @before_processes ||= []
132
+ @before_processes.insert(idx, [name, block])
133
+ end
134
+
135
+ def execute_before_processing!(inst, resolved_template)
136
+ @before_processes ||= []
137
+
138
+ @before_processes.all? do |name, block|
139
+ inst.instance_exec(resolved_template, &block)
140
+ end
141
+ end
142
+
143
+ # Convenience method to check if we're in build mode
144
+ def build?; environment == :build; end
145
+ end
146
+
147
+ module InstanceMethods
148
+ # Internal method to look for templates and evaluate them if found
149
+ def process_request(options={})
150
+ if !settings.views.include?(settings.root)
151
+ settings.set :views, File.join(settings.root, settings.views)
152
+ end
153
+
154
+ # Normalize the path and add index if we're looking at a directory
155
+ request.path_info = self.class.path_to_index(request.path)
156
+
157
+ request_path = request.path_info.gsub("%20", " ")
158
+ found_template = resolve_template(request_path, :raise_exceptions => false)
159
+ return status(404) unless found_template
160
+ return unless settings.execute_before_processing!(self, found_template)
161
+
162
+ options.merge!(request['custom_options'] || {})
163
+
164
+ old_layout = settings.layout
165
+ settings.set :layout, options[:layout] if !options[:layout].nil?
166
+
167
+ local_layout = if settings.layout
168
+ if options[:layout] == false || request.path_info =~ /\.(css|js)$/
169
+ false
170
+ else
171
+ settings.fetch_layout_path(settings.layout).to_sym
172
+ end
173
+ else
174
+ false
175
+ end
176
+
177
+ render_options = { :layout => local_layout }
178
+ render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
179
+
180
+ path, engine = found_template
181
+ locals = request['custom_locals'] || {}
182
+
183
+ begin
184
+ result = render(engine, path, render_options, locals)
185
+
186
+ if result
187
+ content_type mime_type(File.extname(request_path)), :charset => 'utf-8'
188
+ status 200
189
+ body result
190
+ end
191
+ # rescue
192
+ # status(404)
193
+ ensure
194
+ settings.set :layout, old_layout
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,163 @@
1
+ require "thor"
2
+ require "thor/group"
3
+ require 'rack/test'
4
+
5
+ SHARED_SERVER = Middleman.server
6
+ SHARED_SERVER.set :environment, :build
7
+
8
+ module Middleman
9
+ module ThorActions
10
+ def tilt_template(source, *args, &block)
11
+ config = args.last.is_a?(Hash) ? args.pop : {}
12
+ destination = args.first || source
13
+
14
+ # source = File.expand_path(find_in_source_paths(source.to_s))
15
+ context = instance_eval('binding')
16
+
17
+ request_path = destination.sub(/^#{SHARED_SERVER.build_dir}/, "")
18
+
19
+ begin
20
+ destination, request_path = SHARED_SERVER.reroute_builder(destination, request_path)
21
+
22
+ request_path.gsub!(/\s/, "%20")
23
+ response = Middleman::Builder.shared_rack.get(request_path)
24
+
25
+ create_file destination, nil, config do
26
+ response.body
27
+ end if response.status == 200
28
+ rescue
29
+ end
30
+ end
31
+ end
32
+
33
+ class Builder < Thor::Group
34
+ include Thor::Actions
35
+ include Middleman::ThorActions
36
+
37
+ def self.shared_rack
38
+ @shared_rack ||= begin
39
+ mock = ::Rack::MockSession.new(SHARED_SERVER)
40
+ sess = ::Rack::Test::Session.new(mock)
41
+ sess.get("/")
42
+ sess
43
+ end
44
+ end
45
+
46
+ class_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
47
+
48
+ def initialize(*args)
49
+ super
50
+
51
+ if options.has_key?("relative") && options["relative"]
52
+ SHARED_SERVER.activate :relative_assets
53
+ end
54
+ end
55
+
56
+ def source_paths
57
+ @source_paths ||= [
58
+ SHARED_SERVER.root
59
+ ]
60
+ end
61
+
62
+ def build_all_files
63
+ self.class.shared_rack
64
+
65
+ action Directory.new(self, SHARED_SERVER.views, SHARED_SERVER.build_dir, { :force => true })
66
+
67
+ SHARED_SERVER.proxied_paths.each do |url, proxy|
68
+ tilt_template(url.gsub(/^\//, "#{SHARED_SERVER.build_dir}/"), { :force => true })
69
+ end
70
+ end
71
+
72
+ @@hooks = {}
73
+ def self.after_run(name, &block)
74
+ @@hooks[name] = block
75
+ end
76
+
77
+ def run_hooks
78
+ @@hooks.each do |name, proc|
79
+ instance_eval(&proc)
80
+ end
81
+
82
+ SHARED_SERVER.after_build_callbacks.each do |proc|
83
+ instance_eval(&proc)
84
+ end
85
+ end
86
+ end
87
+
88
+ class Directory < ::Thor::Actions::EmptyDirectory
89
+ attr_reader :source
90
+
91
+ def initialize(base, source, destination=nil, config={}, &block)
92
+ @source = File.expand_path(base.find_in_source_paths(source.to_s))
93
+ @block = block
94
+ super(base, destination, { :recursive => true }.merge(config))
95
+ end
96
+
97
+ def invoke!
98
+ base.empty_directory given_destination, config
99
+ execute!
100
+ end
101
+
102
+ def revoke!
103
+ execute!
104
+ end
105
+
106
+ protected
107
+ def handle_directory(lookup, &block)
108
+ lookup = File.join(lookup, '*')
109
+
110
+ results = Dir[lookup].sort do |a, b|
111
+ simple_a = a.gsub(SHARED_SERVER.root + "/", '').gsub(SHARED_SERVER.views + "/", '')
112
+ simple_b = b.gsub(SHARED_SERVER.root + "/", '').gsub(SHARED_SERVER.views + "/", '')
113
+
114
+ a_dir = simple_a.split("/").first
115
+ b_dir = simple_b.split("/").first
116
+
117
+ if a_dir == SHARED_SERVER.images_dir
118
+ -1
119
+ elsif b_dir == SHARED_SERVER.images_dir
120
+ 1
121
+ else
122
+ 0
123
+ end
124
+ end
125
+
126
+ results = results.select(&block) if block_given?
127
+
128
+ results.each do |file_source|
129
+ if File.directory?(file_source)
130
+ handle_directory(file_source)
131
+ next
132
+ end
133
+
134
+ # Skip partials prefixed with an underscore
135
+ next unless file_source.gsub(SHARED_SERVER.root, '').split('/').select { |p| p[0,1] == '_' }.empty?
136
+
137
+ file_extension = File.extname(file_source)
138
+ file_destination = File.join(given_destination, file_source.gsub(source, '.'))
139
+ file_destination.gsub!('/./', '/')
140
+
141
+ handled_by_tilt = ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
142
+ if handled_by_tilt
143
+ file_destination.gsub!(file_extension, "")
144
+ end
145
+
146
+ destination = base.tilt_template(file_source, file_destination, config, &@block)
147
+ end
148
+ end
149
+
150
+ def execute!
151
+ handle_directory(source) do |path|
152
+ file_name = path.gsub(SHARED_SERVER.views + "/", "")
153
+ if file_name == "layouts"
154
+ false
155
+ elsif file_name.include?("layout.") && file_name.split(".").length == 2
156
+ false
157
+ else
158
+ true
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,87 @@
1
+ require 'thor'
2
+
3
+ module Middleman
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+ check_unknown_options!
7
+ default_task :server
8
+
9
+ class_option "help", :type => :boolean, :default => false, :aliases => "-h"
10
+ def initialize(*)
11
+ super
12
+ help_check if options[:help]
13
+ end
14
+
15
+ desc "init NAME", "Create new Middleman project directory NAME"
16
+ available_templates = Middleman::Templates.registered_names.join(", ")
17
+ method_option "template", :aliases => "-T", :default => "default", :desc => "Optionally use a pre-defined project template: #{available_templates}"
18
+ method_option "css_dir", :default => "stylesheets", :desc => 'The path to the css files'
19
+ method_option "js_dir", :default => "javascripts", :desc => 'The path to the javascript files'
20
+ method_option "images_dir", :default => "images", :desc => 'The path to the image files'
21
+ method_option "rack", :type => :boolean, :default => false, :desc => 'Include a config.ru file'
22
+ method_option "bundler", :type => :boolean, :default => false, :desc => 'Create a Gemfile and use Bundler to manage gems'
23
+ def init(name)
24
+ key = options[:template].to_sym
25
+ unless Middleman::Templates.registered_templates.has_key?(key)
26
+ key = :default
27
+ end
28
+
29
+ thor_group = Middleman::Templates.registered_templates[key]
30
+ thor_group.new([name], options).invoke_all
31
+ end
32
+
33
+ desc "server [-p 4567] [-e development]", "Starts the Middleman preview server"
34
+ method_option "environment", :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development', :desc => "The environment Middleman will run under"
35
+ method_option "port", :aliases => "-p", :default => "4567", :desc => "The port Middleman will listen on"
36
+ method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
37
+ method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
38
+ def server
39
+ v1_check
40
+
41
+ if options["livereload"]
42
+ livereload_options = {:port => options["livereload-port"]}
43
+ end
44
+
45
+ Middleman::Guard.start({
46
+ :port => options[:port],
47
+ :environment => options[:environment]
48
+ }, livereload_options)
49
+ end
50
+
51
+ desc "build", "Builds the static site for deployment"
52
+ method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
53
+ def build
54
+ v1_check
55
+ thor_group = Middleman::Builder.new([], options).invoke_all
56
+ end
57
+
58
+ desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
59
+ def migrate
60
+ return if File.exists?("source")
61
+ `mv public source`
62
+ `cp -R views/* source/`
63
+ `rm -rf views`
64
+ end
65
+
66
+ desc "version", "Show Middleman version"
67
+ def version
68
+ require 'middleman/version'
69
+ say "Middleman #{Middleman::VERSION}"
70
+ end
71
+
72
+ private
73
+
74
+ def v1_check
75
+ if File.exists?("views") || File.exists?("public")
76
+ $stderr.puts "== Error: The views and public folders are have been combined. Use the 'middleman migrate' command to merge your folders automatically."
77
+ exit 1
78
+ end
79
+ end
80
+
81
+ def help_check
82
+ help self.class.send(:retrieve_task_name, ARGV.dup)
83
+ exit 0
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,2 @@
1
+ require 'middleman'
2
+ run Middleman.server