middleman 2.0.9.pre.2-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/.gitignore +13 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +47 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +19 -0
- data/Rakefile +15 -0
- data/bin/middleman +73 -0
- data/bin/mm-build +9 -0
- data/bin/mm-init +9 -0
- data/bin/mm-server +9 -0
- data/features/asset_host.feature +14 -0
- data/features/automatic_image_sizes.feature +16 -0
- data/features/builder.feature +23 -0
- data/features/cache_buster.feature +26 -0
- data/features/coffee-script.feature +17 -0
- data/features/data.feature +12 -0
- data/features/directory_index.feature +29 -0
- data/features/dynamic_pages.feature +33 -0
- data/features/front-matter.feature +7 -0
- data/features/generator.feature +8 -0
- data/features/helpers_auto_javascript_include_tag.feature +27 -0
- data/features/helpers_auto_stylesheet_link_tag.feature +27 -0
- data/features/helpers_page_classes.feature +17 -0
- data/features/liquid.feature +6 -0
- data/features/markdown.feature +7 -0
- data/features/minify_css.feature +24 -0
- data/features/minify_javascript.feature +23 -0
- data/features/padrino_helpers.feature +10 -0
- data/features/page_alias_and_layouts.feature +44 -0
- data/features/relative_assets.feature +44 -0
- data/features/scss-support.feature +12 -0
- data/features/sinatra.feature +6 -0
- data/features/slim.feature +7 -0
- data/features/sprockets.feature +21 -0
- data/features/sprockets_gems.feature +7 -0
- data/features/step_definitions/asset_host_steps.rb +8 -0
- data/features/step_definitions/builder_steps.rb +40 -0
- data/features/step_definitions/generator_steps.rb +30 -0
- data/features/step_definitions/middleman_steps.rb +46 -0
- data/features/step_definitions/page_layout_steps.rb +13 -0
- data/features/support/env.rb +3 -0
- data/features/tiny_src.feature +15 -0
- data/fixtures/indexable-app/config.rb +2 -0
- data/fixtures/indexable-app/source/a_folder/needs_index.html +1 -0
- data/fixtures/indexable-app/source/leave_me_alone.html +1 -0
- data/fixtures/indexable-app/source/needs_index.html +1 -0
- data/fixtures/indexable-app/source/regular/index.html +1 -0
- data/fixtures/relative-app/config.rb +0 -0
- data/fixtures/relative-app/source/images/blank.gif +0 -0
- data/fixtures/relative-app/source/stylesheets/relative_assets.css.sass +3 -0
- data/fixtures/sprockets-app/config.rb +1 -0
- data/fixtures/sprockets-app/source/jquery_include.js +1 -0
- data/fixtures/sprockets-app/source/library/javascripts/sprockets_base.js +5 -0
- data/fixtures/sprockets-app/source/library/javascripts/sprockets_sub.js +3 -0
- data/fixtures/test-app/config.rb +51 -0
- data/fixtures/test-app/data/test.yml +4 -0
- data/fixtures/test-app/source/_liquid_partial.liquid +1 -0
- data/fixtures/test-app/source/_partial.haml +1 -0
- data/fixtures/test-app/source/a_folder/needs_index.html +1 -0
- data/fixtures/test-app/source/asset_host.html.haml +1 -0
- data/fixtures/test-app/source/auto-css.html.haml +1 -0
- data/fixtures/test-app/source/auto-css/auto-css.html.haml +1 -0
- data/fixtures/test-app/source/auto-css/index.html.haml +1 -0
- data/fixtures/test-app/source/auto-css/sub/auto-css.html.haml +1 -0
- data/fixtures/test-app/source/auto-image-sizes.html.haml +1 -0
- data/fixtures/test-app/source/auto-js.html.haml +1 -0
- data/fixtures/test-app/source/auto-js/auto-js.html.haml +1 -0
- data/fixtures/test-app/source/auto-js/index.html.haml +1 -0
- data/fixtures/test-app/source/auto-js/sub/auto-js.html.haml +1 -0
- data/fixtures/test-app/source/cache-buster.html.haml +2 -0
- data/fixtures/test-app/source/custom-layout-dir/index.html.haml +1 -0
- data/fixtures/test-app/source/custom-layout.html.haml +1 -0
- data/fixtures/test-app/source/data.html.erb +1 -0
- data/fixtures/test-app/source/data2.html.liquid +2 -0
- data/fixtures/test-app/source/front-matter.html.erb +6 -0
- data/fixtures/test-app/source/images/Child folder/regular_file(example).txt +1 -0
- data/fixtures/test-app/source/images/Read me (example).txt +1 -0
- data/fixtures/test-app/source/images/blank.gif +0 -0
- data/fixtures/test-app/source/img/blank.gif +0 -0
- data/fixtures/test-app/source/index.html.haml +6 -0
- data/fixtures/test-app/source/inline-coffeescript.html.haml +3 -0
- data/fixtures/test-app/source/inline-css.html.haml +4 -0
- data/fixtures/test-app/source/inline-js.html.haml +7 -0
- data/fixtures/test-app/source/javascripts/auto-js.js +1 -0
- data/fixtures/test-app/source/javascripts/auto-js/auto-js.js +1 -0
- data/fixtures/test-app/source/javascripts/auto-js/index.js +1 -0
- data/fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js +1 -0
- data/fixtures/test-app/source/javascripts/broken-coffee.js.coffee +3 -0
- data/fixtures/test-app/source/javascripts/coffee_test.js.coffee +3 -0
- data/fixtures/test-app/source/javascripts/jquery.plugin.with.dots.js +1 -0
- data/fixtures/test-app/source/javascripts/jquery_base.js +5 -0
- data/fixtures/test-app/source/javascripts/multiple_engines.js.coffee.erb +1 -0
- data/fixtures/test-app/source/javascripts/sprockets_base.js +5 -0
- data/fixtures/test-app/source/javascripts/sprockets_sub.js +3 -0
- data/fixtures/test-app/source/layout.haml +6 -0
- data/fixtures/test-app/source/layouts/custom.haml +5 -0
- data/fixtures/test-app/source/liquid_master.html.liquid +1 -0
- data/fixtures/test-app/source/markdown.html.markdown +1 -0
- data/fixtures/test-app/source/needs_index.html +1 -0
- data/fixtures/test-app/source/padrino_test.html.haml +5 -0
- data/fixtures/test-app/source/page-classes.html.haml +1 -0
- data/fixtures/test-app/source/real.html +1 -0
- data/fixtures/test-app/source/real/index.html.erb +5 -0
- data/fixtures/test-app/source/relative_image.html.erb +1 -0
- data/fixtures/test-app/source/services/index.html.haml +1 -0
- data/fixtures/test-app/source/should_be_ignored.html +1 -0
- data/fixtures/test-app/source/should_be_ignored2.html +1 -0
- data/fixtures/test-app/source/should_be_ignored3.html +1 -0
- data/fixtures/test-app/source/slim.html.slim +7 -0
- data/fixtures/test-app/source/spaces in file.html.erb +1 -0
- data/fixtures/test-app/source/static.html +1 -0
- data/fixtures/test-app/source/stylesheets/asset_host.css.sass +3 -0
- data/fixtures/test-app/source/stylesheets/auto-css.css +3 -0
- data/fixtures/test-app/source/stylesheets/auto-css/auto-css.css +3 -0
- data/fixtures/test-app/source/stylesheets/auto-css/index.css +0 -0
- data/fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css +3 -0
- data/fixtures/test-app/source/stylesheets/layout.css.sass +2 -0
- data/fixtures/test-app/source/stylesheets/relative_assets.css.sass +3 -0
- data/fixtures/test-app/source/stylesheets/site.css.sass +1 -0
- data/fixtures/test-app/source/stylesheets/site_scss.css.scss +1 -0
- data/fixtures/test-app/source/stylesheets/static.css +2 -0
- data/fixtures/test-app/source/sub1/page-classes.html.haml +1 -0
- data/fixtures/test-app/source/sub1/sub2/page-classes.html.haml +1 -0
- data/fixtures/test-app/source/tiny_src.html.haml +1 -0
- data/lib/middleman.rb +202 -0
- data/lib/middleman/base.rb +198 -0
- data/lib/middleman/builder.rb +163 -0
- data/lib/middleman/cli.rb +87 -0
- data/lib/middleman/config.ru +2 -0
- data/lib/middleman/core_extensions/assets.rb +57 -0
- data/lib/middleman/core_extensions/builder.rb +41 -0
- data/lib/middleman/core_extensions/compass.rb +102 -0
- data/lib/middleman/core_extensions/data.rb +120 -0
- data/lib/middleman/core_extensions/default_helpers.rb +77 -0
- data/lib/middleman/core_extensions/features.rb +102 -0
- data/lib/middleman/core_extensions/front_matter.rb +116 -0
- data/lib/middleman/core_extensions/rack_map.rb +35 -0
- data/lib/middleman/core_extensions/rendering.rb +19 -0
- data/lib/middleman/core_extensions/routing.rb +87 -0
- data/lib/middleman/core_extensions/sprockets.rb +102 -0
- data/lib/middleman/features/asset_host.rb +22 -0
- data/lib/middleman/features/automatic_image_sizes.rb +31 -0
- data/lib/middleman/features/automatic_image_sizes/fastimage.rb +287 -0
- data/lib/middleman/features/cache_buster.rb +42 -0
- data/lib/middleman/features/directory_indexes.rb +56 -0
- data/lib/middleman/features/lorem.rb +126 -0
- data/lib/middleman/features/minify_css.rb +10 -0
- data/lib/middleman/features/minify_javascript.rb +43 -0
- data/lib/middleman/features/relative_assets.rb +38 -0
- data/lib/middleman/features/tiny_src.rb +11 -0
- data/lib/middleman/guard.rb +70 -0
- data/lib/middleman/renderers/coffee_script.rb +8 -0
- data/lib/middleman/renderers/haml.rb +31 -0
- data/lib/middleman/renderers/liquid.rb +29 -0
- data/lib/middleman/renderers/markdown.rb +34 -0
- data/lib/middleman/renderers/sass.rb +63 -0
- data/lib/middleman/renderers/slim.rb +8 -0
- data/lib/middleman/templates.rb +53 -0
- data/lib/middleman/templates/default.rb +17 -0
- data/lib/middleman/templates/default/source/index.html.erb +5 -0
- data/lib/middleman/templates/default/source/layout.erb +19 -0
- data/lib/middleman/templates/default/source/stylesheets/site.css.scss +32 -0
- data/lib/middleman/templates/html5.rb +16 -0
- data/lib/middleman/templates/html5/source/404.html +38 -0
- data/lib/middleman/templates/html5/source/README.md +388 -0
- data/lib/middleman/templates/html5/source/apple-touch-icon-114x114-precomposed.png +0 -0
- data/lib/middleman/templates/html5/source/apple-touch-icon-57x57-precomposed.png +0 -0
- data/lib/middleman/templates/html5/source/apple-touch-icon-72x72-precomposed.png +0 -0
- data/lib/middleman/templates/html5/source/apple-touch-icon-precomposed.png +0 -0
- data/lib/middleman/templates/html5/source/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/html5/source/crossdomain.xml +25 -0
- data/lib/middleman/templates/html5/source/css/style.css +293 -0
- data/lib/middleman/templates/html5/source/favicon.ico +0 -0
- data/lib/middleman/templates/html5/source/humans.txt +43 -0
- data/lib/middleman/templates/html5/source/img/.gitignore +2 -0
- data/lib/middleman/templates/html5/source/index.html +79 -0
- data/lib/middleman/templates/html5/source/js/libs/jquery-1.6.2.js +8981 -0
- data/lib/middleman/templates/html5/source/js/libs/jquery-1.6.2.min.js +18 -0
- data/lib/middleman/templates/html5/source/js/libs/modernizr-2.0.6.min.js +4 -0
- data/lib/middleman/templates/html5/source/js/mylibs/.gitignore +2 -0
- data/lib/middleman/templates/html5/source/js/plugins.js +20 -0
- data/lib/middleman/templates/html5/source/js/script.js +8 -0
- data/lib/middleman/templates/html5/source/robots.txt +5 -0
- data/lib/middleman/templates/html5/source/test/index.html +31 -0
- data/lib/middleman/templates/html5/source/test/qunit/qunit.css +148 -0
- data/lib/middleman/templates/html5/source/test/qunit/qunit.js +1265 -0
- data/lib/middleman/templates/html5/source/test/tests.js +24 -0
- data/lib/middleman/templates/local.rb +20 -0
- data/lib/middleman/templates/shared/Gemfile.tt +3 -0
- data/lib/middleman/templates/shared/config.ru +4 -0
- data/lib/middleman/templates/shared/config.tt +104 -0
- data/lib/middleman/version.rb +3 -0
- data/middleman-x86-mingw32.gemspec +78 -0
- data/middleman.gemspec +78 -0
- metadata +812 -0
@@ -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
|