middleman 2.0.9.pre.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) 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 +70 -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-x86-mingw32.gemspec +78 -0
  196. data/middleman.gemspec +78 -0
  197. metadata +812 -0
@@ -0,0 +1,2 @@
1
+ require 'middleman'
2
+ run Middleman.server
@@ -0,0 +1,57 @@
1
+ module Middleman::CoreExtensions::Assets
2
+ class << self
3
+ def registered(app)
4
+ # Disable Padrino cache buster until explicitly enabled
5
+ app.set :asset_stamp, false
6
+
7
+ app.extend ClassMethods
8
+
9
+ app.helpers Helpers
10
+
11
+ app.register_asset_handler :base do |path, prefix, request|
12
+ path.include?("://") ? path : File.join(app.http_prefix || "/", prefix, path)
13
+ end
14
+ end
15
+ alias :included :registered
16
+ end
17
+
18
+ module ClassMethods
19
+ def register_asset_handler(handler_name, &block)
20
+ @asset_handler_map ||= []
21
+ @asset_handler_stack ||= []
22
+
23
+ if block_given?
24
+ @asset_handler_stack << block
25
+ @asset_handler_map << handler_name
26
+ end
27
+ end
28
+
29
+ def asset_handler_get_url(path, prefix="", request=nil)
30
+ @asset_handler_map ||= []
31
+ @asset_handler_stack ||= []
32
+
33
+ @asset_handler_stack.last.call(path, prefix, request)
34
+ end
35
+
36
+ def before_asset_handler(position, *args)
37
+ @asset_handler_map ||= []
38
+ @asset_handler_stack ||= []
39
+
40
+ current_index = @asset_handler_map.index(position)
41
+ return nil unless current_index
42
+
43
+ previous = current_index - 1
44
+ if (previous >= 0) && (previous < @asset_handler_map.length)
45
+ @asset_handler_stack[previous].call(*args)
46
+ else
47
+ nil
48
+ end
49
+ end
50
+ end
51
+
52
+ module Helpers
53
+ def asset_url(path, prefix="")
54
+ self.class.asset_handler_get_url(path, prefix, request)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ module Middleman::CoreExtensions::Builder
2
+ class << self
3
+ def registered(app)
4
+ app.extend ClassMethods
5
+ end
6
+ end
7
+
8
+ module ClassMethods
9
+ # Add a block/proc to be run after features have been setup
10
+ def after_build(&block)
11
+ @run_after_build ||= []
12
+ @run_after_build << block
13
+ end
14
+
15
+ def after_build_callbacks
16
+ @run_after_build ||= []
17
+ @run_after_build
18
+ end
19
+
20
+ def build_reroute(&block)
21
+ @build_rerouters ||= []
22
+ @build_rerouters << block
23
+ end
24
+
25
+ def reroute_builder(desination, request_path)
26
+ @build_rerouters ||= []
27
+
28
+ result = [desination, request_path]
29
+
30
+ @build_rerouters.each do |block|
31
+ output = block.call(desination, request_path)
32
+ if output
33
+ result = output
34
+ break
35
+ end
36
+ end
37
+
38
+ result
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,102 @@
1
+ module Middleman::CoreExtensions::Compass
2
+ class << self
3
+ def registered(app)
4
+ app.extend ClassMethods
5
+
6
+ require "compass"
7
+
8
+ # Susy grids
9
+ begin
10
+ require "susy"
11
+ rescue LoadError
12
+ end
13
+
14
+ app.after_configuration do
15
+ # Support a stand-alone compass config file
16
+ # Many options are overwritten by Middleman, but the config is a good
17
+ # place to add:
18
+ # * output_style
19
+ # * disable_warnings
20
+ # * sass_options
21
+ # * line_comments
22
+ # * sprite_engine
23
+ # * chunky_png_options
24
+ compass_config_file = File.join(app.root, "compass.config")
25
+ if File.exists?(compass_config_file)
26
+ ::Compass.add_project_configuration(compass_config_file)
27
+ end
28
+
29
+ ::Compass.configuration do |config|
30
+ config.project_path = app.root
31
+ config.environment = :development
32
+ config.cache_path = File.join(app.root, ".sass-cache")
33
+
34
+ views_root = File.basename(app.views)
35
+ config.sass_dir = File.join(views_root, app.css_dir)
36
+ config.css_dir = File.join(views_root, app.css_dir)
37
+ config.javascripts_dir = File.join(views_root, app.js_dir)
38
+ config.fonts_dir = File.join(views_root, app.fonts_dir)
39
+ config.images_dir = File.join(views_root, app.images_dir)
40
+
41
+ config.http_images_path = if app.respond_to? :http_images_path
42
+ app.http_images_path
43
+ else
44
+ File.join(app.http_prefix || "/", app.images_dir)
45
+ end
46
+
47
+ config.http_stylesheets_path = if app.respond_to? :http_css_path
48
+ app.http_css_path
49
+ else
50
+ File.join(app.http_prefix || "/", app.css_dir)
51
+ end
52
+
53
+ config.http_javascripts_path = if app.respond_to? :http_js_path
54
+ app.http_js_path
55
+ else
56
+ File.join(app.http_prefix || "/", app.js_dir)
57
+ end
58
+
59
+ config.http_javascripts_path = if app.respond_to? :http_fonts_path
60
+ app.http_js_path
61
+ else
62
+ File.join(app.http_prefix || "/", app.fonts_dir)
63
+ end
64
+
65
+ config.asset_cache_buster :none
66
+ config.output_style = :nested
67
+
68
+ config.add_import_path(config.sass_dir)
69
+ end
70
+
71
+ # Required for relative paths
72
+ configure :build do
73
+ ::Compass.configuration do |config|
74
+ config.environment = :production
75
+
76
+ build_root = File.basename(self.build_dir)
77
+ config.css_dir = File.join(build_root, self.css_dir)
78
+ config.images_dir = File.join(build_root, self.images_dir)
79
+ end
80
+ end
81
+
82
+ app.execute_after_compass_init!
83
+
84
+ app.set :sass, ::Compass.configuration.to_sass_engine_options
85
+ end
86
+ end
87
+ alias :included :registered
88
+ end
89
+
90
+ module ClassMethods
91
+ # Add a block/proc to be run after features have been setup
92
+ def compass_config(&block)
93
+ @run_after_compass ||= []
94
+ @run_after_compass << block
95
+ end
96
+
97
+ def execute_after_compass_init!
98
+ @run_after_compass ||= []
99
+ @run_after_compass.each { |block| block.call(::Compass.configuration) }
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,120 @@
1
+ require "yaml"
2
+ require "thor"
3
+
4
+ module Middleman::CoreExtensions::Data
5
+ class << self
6
+ def registered(app)
7
+ app.set :data_dir, "data"
8
+ app.extend ClassMethods
9
+ app.helpers Helpers
10
+ end
11
+ alias :included :registered
12
+ end
13
+
14
+ module Helpers
15
+ def data
16
+ self.class.data
17
+ end
18
+ end
19
+
20
+ class DataObject
21
+ def initialize(app)
22
+ @app = app
23
+ end
24
+
25
+ def data_for_path(path)
26
+ response = nil
27
+
28
+ @@local_sources ||= {}
29
+ @@callback_sources ||= {}
30
+
31
+ if @@local_sources.has_key?(path.to_s)
32
+ response = @@local_sources[path.to_s]
33
+ elsif @@callback_sources.has_key?(path.to_s)
34
+ response = @@callback_sources[path.to_s].call()
35
+ else
36
+ file_path = File.join(@app.root, @app.data_dir, "#{path}.yml")
37
+ if File.exists? file_path
38
+ response = YAML.load_file(file_path)
39
+ end
40
+ end
41
+ end
42
+
43
+ def method_missing(path)
44
+ result = data_for_path(path)
45
+
46
+ if result
47
+ recursively_enhance(result)
48
+ else
49
+ super
50
+ end
51
+ end
52
+
53
+ def to_h
54
+ data = {}
55
+
56
+ @@local_sources ||= {}
57
+ @@callback_sources ||= {}
58
+
59
+ (@@local_sources || {}).each do |k, v|
60
+ data[k] = data_for_path(k)
61
+ end
62
+
63
+ (@@callback_sources || {}).each do |k, v|
64
+ data[k] = data_for_path(k)
65
+ end
66
+
67
+ yaml_path = File.join(@app.root, @app.data_dir, "*.yml")
68
+ Dir[yaml_path].each do |f|
69
+ p = f.split("/").last.gsub(".yml", "")
70
+ data[p] = data_for_path(p)
71
+ end
72
+
73
+ data
74
+ end
75
+
76
+ def self.data_content(name, content)
77
+ @@local_sources ||= {}
78
+ @@local_sources[name.to_s] = content
79
+ end
80
+
81
+ def self.data_callback(name, proc)
82
+ @@callback_sources ||= {}
83
+ @@callback_sources[name.to_s] = proc
84
+ end
85
+
86
+ private
87
+ def recursively_enhance(data)
88
+ if data.is_a? Hash
89
+ data = Thor::CoreExt::HashWithIndifferentAccess.new(data)
90
+ data.each do |key, val|
91
+ data[key] = recursively_enhance(val)
92
+ end
93
+ data
94
+ elsif data.is_a? Array
95
+ data.each_with_index do |val, i|
96
+ data[i] = recursively_enhance(val)
97
+ end
98
+ data
99
+ else
100
+ data
101
+ end
102
+ end
103
+ end
104
+
105
+ module ClassMethods
106
+ def data
107
+ @data ||= DataObject.new(self)
108
+ end
109
+
110
+ # Makes a hash available on the data var with a given name
111
+ def data_content(name, content)
112
+ DataObject.data_content(name, content)
113
+ end
114
+
115
+ # Makes a hash available on the data var with a given name
116
+ def data_callback(name, &block)
117
+ DataObject.data_callback(name, block)
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,77 @@
1
+ require "padrino-helpers"
2
+
3
+ module Middleman::CoreExtensions::DefaultHelpers
4
+ class << self
5
+ def registered(app)
6
+ # Use Padrino Helpers
7
+ app.register Padrino::Helpers
8
+
9
+ # Middleman Helpers
10
+ app.helpers Helpers
11
+ end
12
+ alias :included :registered
13
+ end
14
+
15
+ module Helpers
16
+ def auto_stylesheet_link_tag(separator="/")
17
+ auto_tag(:css, separator) do |path|
18
+ stylesheet_link_tag path
19
+ end
20
+ end
21
+
22
+ def auto_javascript_include_tag(separator="/")
23
+ auto_tag(:js, separator) do |path|
24
+ javascript_include_tag path
25
+ end
26
+ end
27
+
28
+ def auto_tag(asset_ext, separator="/", asset_dir=nil)
29
+ if asset_dir.nil?
30
+ asset_dir = case asset_ext
31
+ when :js then self.class.js_dir
32
+ when :css then self.class.css_dir
33
+ end
34
+ end
35
+ path = request.path_info.dup
36
+ # If the basename of the request as no extension, assume we are serving a
37
+ # directory and join index_file to the path.
38
+ path = File.join(path, self.class.index_file) if File.extname(path).empty?
39
+ path = path.gsub(%r{^/}, '')
40
+ path = path.gsub(File.extname(path), ".#{asset_ext}")
41
+ path = path.gsub("/", separator)
42
+
43
+ view = File.join(self.class.views, asset_dir, path)
44
+ yield path if File.exists?(view) or Dir["#{view}.*"].any?
45
+ end
46
+
47
+ def page_classes
48
+ path = request.path_info.dup
49
+ path << settings.index_file if path.match(%r{/$})
50
+ path = path.gsub(%r{^/}, '')
51
+
52
+ classes = []
53
+ parts = path.split('.')[0].split('/')
54
+ parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
55
+
56
+ classes.join(' ')
57
+ end
58
+
59
+ # Padrino's asset handling needs to pass through ours
60
+ def asset_path(kind, source)
61
+ return source if source =~ /^http/
62
+ asset_folder = case kind
63
+ when :css then settings.css_dir
64
+ when :js then settings.js_dir
65
+ when :images then settings.images_dir
66
+ else kind.to_s
67
+ end
68
+ source = source.to_s.gsub(/\s/, '')
69
+ ignore_extension = (kind == :images) # don't append extension
70
+ source << ".#{kind}" unless ignore_extension or source =~ /\.#{kind}/
71
+ result_path = source if source =~ %r{^/} # absolute path
72
+ result_path ||= asset_url(source, asset_folder)
73
+ timestamp = asset_timestamp(result_path)
74
+ "#{result_path}#{timestamp}"
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,102 @@
1
+ # Middleman provides an extension API which allows you to hook into the
2
+ # lifecycle of a page request, or static build, and manipulate the output.
3
+ # Internal to Middleman, these extensions are called "features," but we use
4
+ # the exact same API as is made available to the public.
5
+ #
6
+ # A Middleman extension looks like this:
7
+ #
8
+ # module MyExtension
9
+ # class << self
10
+ # def registered(app)
11
+ # # My Code
12
+ # end
13
+ # end
14
+ # end
15
+ #
16
+ # In your `config.rb`, you must load your extension (if it is not defined in
17
+ # that file) and call `activate`.
18
+ #
19
+ # require "my_extension"
20
+ # activate MyExtension
21
+ #
22
+ # This will call the `registered` method in your extension and provide you
23
+ # with the `app` parameter which is a Middleman::Server context. From here
24
+ # you can choose to respond to requests for certain paths or simply attach
25
+ # Rack middleware to the stack.
26
+ #
27
+ # The built-in features cover a wide range of functions. Some provide helper
28
+ # methods to use in your views. Some modify the output on-the-fly. And some
29
+ # apply computationally-intensive changes to your final build files.
30
+
31
+ module Middleman::CoreExtensions::Features
32
+
33
+ # The Feature API is itself a Feature. Mind blowing!
34
+ class << self
35
+ def registered(app)
36
+ app.set :default_features, []
37
+ app.extend ClassMethods
38
+ end
39
+ alias :included :registered
40
+ end
41
+
42
+ module ClassMethods
43
+ # This method is available in the project's `config.rb`.
44
+ # It takes a underscore-separated symbol, finds the appropriate
45
+ # feature module and includes it.
46
+ #
47
+ # activate :lorem
48
+ #
49
+ # Alternatively, you can pass in a Middleman feature module directly.
50
+ #
51
+ # activate MyFeatureModule
52
+ def activate(feature)
53
+ if feature.is_a? Symbol
54
+ feature = feature.to_s
55
+ end
56
+
57
+ if feature.is_a? String
58
+ feature = feature.camelize
59
+ feature = Middleman::Features.const_get(feature)
60
+ end
61
+
62
+ $stderr.puts "== Activating: #{feature}" if logging?
63
+ register feature
64
+ end
65
+
66
+ # Add a block/proc to be run after features have been setup
67
+ def after_configuration(&block)
68
+ @run_after_features ||= []
69
+ @run_after_features << block
70
+ end
71
+
72
+ def run_after_features
73
+ @run_after_features || []
74
+ end
75
+
76
+ # Load features before starting server
77
+ def new
78
+ # Check for and evaluate local configuration
79
+ local_config = File.join(self.root, "config.rb")
80
+ if File.exists? local_config
81
+ $stderr.puts "== Reading: Local config" if logging?
82
+ class_eval File.read(local_config)
83
+ set :app_file, File.expand_path(local_config)
84
+ end
85
+
86
+ # Add in defaults
87
+ default_features.each do |ext|
88
+ activate ext
89
+ end
90
+
91
+ run_after_features.each { |block| class_eval(&block) }
92
+
93
+ if logging?
94
+ extensions.each do |ext|
95
+ $stderr.puts "== Extension: #{ext}"
96
+ end
97
+ end
98
+
99
+ super
100
+ end
101
+ end
102
+ end