middleman 2.0.0.beta6 → 2.0.0.rc1

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.
Files changed (36) hide show
  1. data/CHANGELOG +2 -0
  2. data/features/data.feature +7 -0
  3. data/features/front-matter.feature +7 -0
  4. data/features/helpers_page_classes.feature +6 -6
  5. data/fixtures/test-app/config.rb +23 -36
  6. data/fixtures/test-app/data/test.yml +4 -0
  7. data/fixtures/test-app/source/auto-css/auto-css.html.haml +1 -0
  8. data/fixtures/test-app/source/auto-css/index.html.haml +1 -0
  9. data/fixtures/test-app/source/auto-css/sub/auto-css.html.haml +1 -0
  10. data/fixtures/test-app/source/auto-js/auto-js.html.haml +1 -0
  11. data/fixtures/test-app/source/auto-js/index.html.haml +1 -0
  12. data/fixtures/test-app/source/auto-js/sub/auto-js.html.haml +1 -0
  13. data/fixtures/test-app/source/data.html.erb +1 -0
  14. data/fixtures/test-app/source/front-matter.html.slim +6 -0
  15. data/fixtures/test-app/source/sub1/page-classes.html.haml +1 -0
  16. data/fixtures/test-app/source/sub1/sub2/page-classes.html.haml +1 -0
  17. data/lib/middleman.rb +72 -2
  18. data/lib/middleman/core_extensions/assets.rb +57 -0
  19. data/lib/middleman/{features → core_extensions}/data.rb +7 -6
  20. data/lib/middleman/{features → core_extensions}/default_helpers.rb +8 -6
  21. data/lib/middleman/core_extensions/features.rb +96 -0
  22. data/lib/middleman/core_extensions/front_matter.rb +83 -0
  23. data/lib/middleman/core_extensions/rendering.rb +18 -0
  24. data/lib/middleman/core_extensions/routing.rb +62 -0
  25. data/lib/middleman/features/asset_host.rb +5 -5
  26. data/lib/middleman/features/blog.rb +43 -56
  27. data/lib/middleman/features/cache_buster.rb +7 -7
  28. data/lib/middleman/features/relative_assets.rb +4 -4
  29. data/lib/middleman/features/tiny_src.rb +2 -2
  30. data/lib/middleman/server.rb +44 -142
  31. data/lib/middleman/version.rb +1 -1
  32. metadata +35 -9
  33. data/fixtures/test-app/source/front-matter.html.erb +0 -7
  34. data/lib/middleman/assets.rb +0 -33
  35. data/lib/middleman/features.rb +0 -126
  36. data/lib/middleman/features/front_matter.rb +0 -60
data/CHANGELOG CHANGED
@@ -1,6 +1,8 @@
1
1
  2.0.0
2
2
  =====
3
3
 
4
+ - Use sinatra before/after hooks for Blog and FrontMatter
5
+ - Converted a lot of Middleman::Server in CoreExtensions
4
6
  - Combine views/ and public/ into a single source/ folder.
5
7
  - Support YAML front-matter
6
8
  - Blog-aware
@@ -0,0 +1,7 @@
1
+ Feature: Local Data API
2
+ In order to abstract content from structure
3
+
4
+ Scenario: Rendering html
5
+ Given the Server is running
6
+ When I go to "/data.html"
7
+ Then I should see "One:Two"
@@ -0,0 +1,7 @@
1
+ Feature: YAML Front Matter
2
+ In order to specific options and data inline
3
+
4
+ Scenario: Rendering html
5
+ Given the Server is running
6
+ When I go to "/front-matter.html"
7
+ Then I should see "<h1>This is the title</h1>"
@@ -3,15 +3,15 @@ Feature: Built-in page_classes view helper
3
3
 
4
4
  Scenario: Viewing the root path
5
5
  Given the Server is running
6
- When I go to "/page-class.html"
7
- Then I should see "page-class"
6
+ When I go to "/page-classes.html"
7
+ Then I should see "page-classes"
8
8
 
9
9
  Scenario: Viewing a tier-1 path
10
10
  Given the Server is running
11
- When I go to "/sub1/page-class.html"
12
- Then I should see "sub1 sub1_page-class"
11
+ When I go to "/sub1/page-classes.html"
12
+ Then I should see "sub1 sub1_page-classes"
13
13
 
14
14
  Scenario: Viewing a tier-2 path
15
15
  Given the Server is running
16
- When I go to "/sub1/sub2/page-class.html"
17
- Then I should see "sub1 sub1_sub2 sub1_sub2_page-class"
16
+ When I go to "/sub1/sub2/page-classes.html"
17
+ Then I should see "sub1 sub1_sub2 sub1_sub2_page-classes"
@@ -3,41 +3,28 @@ with_layout false do
3
3
  page "/inline-js.html"
4
4
  page "/inline-coffeescript.html"
5
5
  page "/slim.html"
6
- end
6
+ page "/data.html"
7
+ page "/page-classes.html"
8
+ page "/sub1/page-classes.html"
9
+ page "/sub1/sub2/page-classes.html"
7
10
 
8
- get "/page-class.html" do
9
- haml :"page-classes.html", :layout => false
10
- end
11
-
12
- get "/sub1/page-class.html" do
13
- haml :"page-classes.html", :layout => false
14
- end
15
-
16
- get "/sub1/sub2/page-class.html" do
17
- haml :"page-classes.html", :layout => false
18
- end
19
-
20
- %w{
21
- /auto-css.html
22
- /auto-css
23
- /auto-css/
24
- /auto-css/auto-css.html
25
- /auto-css/sub/auto-css.html
26
- }.each do |path|
27
- get path do
28
- haml :"auto-css.html", :layout => false
29
- end
30
- end
31
-
32
- %w{
33
- /auto-js.html
34
- /auto-js
35
- /auto-js/
36
- /auto-js/auto-js.html
37
- /auto-js/sub/auto-js.html
38
- }.each do |path|
39
- get path do
40
- haml :"auto-js.html", :layout => false
41
- end
42
- end
11
+ %w{
12
+ /auto-css.html
13
+ /auto-css
14
+ /auto-css/
15
+ /auto-css/auto-css.html
16
+ /auto-css/sub/auto-css.html
17
+ }.each do |path|
18
+ page path
19
+ end
43
20
 
21
+ %w{
22
+ /auto-js.html
23
+ /auto-js
24
+ /auto-js/
25
+ /auto-js/auto-js.html
26
+ /auto-js/sub/auto-js.html
27
+ }.each do |path|
28
+ page path
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ -
2
+ title: "One"
3
+ -
4
+ title: "Two"
@@ -0,0 +1 @@
1
+ = auto_stylesheet_link_tag
@@ -0,0 +1 @@
1
+ = auto_stylesheet_link_tag
@@ -0,0 +1 @@
1
+ = auto_stylesheet_link_tag
@@ -0,0 +1 @@
1
+ = auto_javascript_include_tag
@@ -0,0 +1 @@
1
+ = auto_javascript_include_tag
@@ -0,0 +1 @@
1
+ = auto_javascript_include_tag
@@ -0,0 +1 @@
1
+ <%= data.test.map { |r| r.title }.join(":") %>
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: false
3
+ title: This is the title
4
+ ---
5
+
6
+ h1= data.page.title
@@ -0,0 +1 @@
1
+ = page_classes
@@ -0,0 +1 @@
1
+ = page_classes
data/lib/middleman.rb CHANGED
@@ -71,7 +71,77 @@ module Middleman
71
71
  autoload :Markdown, "middleman/renderers/markdown"
72
72
  autoload :CoffeeScript, "middleman/renderers/coffee_script"
73
73
  end
74
+
75
+ module CoreExtensions
76
+ # Custom Feature API
77
+ autoload :Features, "middleman/core_extensions/features"
78
+
79
+ # Asset Path Pipeline
80
+ autoload :Assets, "middleman/core_extensions/assets"
81
+
82
+ # DefaultHelpers are the built-in dynamic template helpers.
83
+ autoload :DefaultHelpers, "middleman/core_extensions/default_helpers"
84
+
85
+ # Data looks at the data/ folder for YAML files and makes them available
86
+ # to dynamic requests.
87
+ autoload :Data, "middleman/core_extensions/data"
88
+
89
+ # Parse YAML from templates
90
+ autoload :FrontMatter, "middleman/core_extensions/front_matter"
91
+
92
+ # Extended version of Padrino's rendering
93
+ autoload :Rendering, "middleman/core_extensions/rendering"
94
+
95
+ # Pass custom options to views
96
+ autoload :Routing, "middleman/core_extensions/routing"
97
+ end
98
+
99
+ module Features
100
+ # RelativeAssets allow any asset path in dynamic templates to be either
101
+ # relative to the root of the project or use an absolute URL.
102
+ autoload :RelativeAssets, "middleman/features/relative_assets"
103
+
104
+ # AssetHost allows you to setup multiple domains to host your static assets.
105
+ # Calls to asset paths in dynamic templates will then rotate through each of
106
+ # the asset servers to better spread the load.
107
+ autoload :AssetHost, "middleman/features/asset_host"
108
+
109
+ # CacheBuster adds a query string to assets in dynamic templates to avoid
110
+ # browser caches failing to update to your new content.
111
+ autoload :CacheBuster, "middleman/features/cache_buster"
112
+
113
+ # AutomaticImageSizes inspects the images used in your dynamic templates and
114
+ # automatically adds width and height attributes to their HTML elements.
115
+ autoload :AutomaticImageSizes, "middleman/features/automatic_image_sizes"
74
116
 
75
- # Features API
76
- autoload :Features, "middleman/features"
117
+ # UglyHaml enables the non-indented output format from Haml templates. Useful
118
+ # for somewhat obfuscating the output and hiding the fact that you're using Haml.
119
+ autoload :UglyHaml, "middleman/features/ugly_haml"
120
+
121
+ # MinifyCss uses the YUI compressor to shrink CSS files
122
+ autoload :MinifyCss, "middleman/features/minify_css"
123
+
124
+ # MinifyJavascript uses the YUI compressor to shrink JS files
125
+ autoload :MinifyJavascript, "middleman/features/minify_javascript"
126
+
127
+ # CodeRay is a syntax highlighter.
128
+ autoload :CodeRay, "middleman/features/code_ray"
129
+
130
+ # Lorem provides a handful of helpful prototyping methods to generate words,
131
+ # paragraphs, fake images, names and email addresses.
132
+ autoload :Lorem, "middleman/features/lorem"
133
+
134
+ # Treat project as a blog
135
+ autoload :Blog, "middleman/features/blog"
136
+
137
+ # Proxy web services requests in dev mode only
138
+ autoload :Proxy, "middleman/features/proxy"
139
+
140
+ # Automatically resize images for mobile devises
141
+ # autoload :TinySrc, "middleman/features/tiny_src"
142
+
143
+ # LiveReload will auto-reload browsers with the live reload extension installed after changes
144
+ # Currently disabled and untested.
145
+ # autoload :LiveReload, "middleman/features/live_reload"
146
+ end
77
147
  end
@@ -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
@@ -2,18 +2,19 @@ require "yaml"
2
2
  require "httparty"
3
3
  require "thor"
4
4
 
5
- module Middleman::Features::Data
5
+ module Middleman::CoreExtensions::Data
6
6
  class << self
7
7
  def registered(app)
8
+ app.set :data_dir, "data"
8
9
  app.extend ClassMethods
9
- app.helpers Middleman::Features::Data::Helpers
10
+ app.helpers Helpers
10
11
  end
11
12
  alias :included :registered
12
13
  end
13
14
 
14
15
  module Helpers
15
16
  def data
16
- @@data ||= Middleman::Features::Data::DataObject.new(self)
17
+ @@data ||= DataObject.new(self)
17
18
  end
18
19
  end
19
20
 
@@ -33,7 +34,7 @@ module Middleman::Features::Data
33
34
  elsif @@remote_sources.has_key?(path.to_s)
34
35
  response = HTTParty.get(@@remote_sources[path.to_s]).parsed_response
35
36
  else
36
- file_path = File.join(@app.class.root, "data", "#{path}.yml")
37
+ file_path = File.join(@app.class.root, @app.class.data_dir, "#{path}.yml")
37
38
  if File.exists? file_path
38
39
  response = YAML.load_file(file_path)
39
40
  end
@@ -82,11 +83,11 @@ module Middleman::Features::Data
82
83
  #
83
84
  # data.my_json
84
85
  def data_source(name, url)
85
- Middleman::Features::Data::DataObject.add_source(name, url)
86
+ DataObject.add_source(name, url)
86
87
  end
87
88
 
88
89
  def data_content(name, content)
89
- Middleman::Features::Data::DataObject.data_content(name, content)
90
+ DataObject.data_content(name, content)
90
91
  end
91
92
  end
92
93
  end
@@ -1,7 +1,13 @@
1
- module Middleman::Features::DefaultHelpers
1
+ require "padrino-helpers"
2
+
3
+ module Middleman::CoreExtensions::DefaultHelpers
2
4
  class << self
3
5
  def registered(app)
4
- app.helpers Middleman::Features::DefaultHelpers::Helpers
6
+ # Use Padrino Helpers
7
+ app.register Padrino::Helpers
8
+
9
+ # Middleman Helpers
10
+ app.helpers Helpers
5
11
  end
6
12
  alias :included :registered
7
13
  end
@@ -50,10 +56,6 @@ module Middleman::Features::DefaultHelpers
50
56
  classes.join(' ')
51
57
  end
52
58
 
53
- def asset_url(path, prefix="")
54
- Middleman::Assets.get_url(path, prefix, request)
55
- end
56
-
57
59
  # Padrino's asset handling needs to pass through ours
58
60
  def asset_path(kind, source)
59
61
  return source if source =~ /^http/
@@ -0,0 +1,96 @@
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_extensions, []
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
+ feature = feature.to_s if feature.is_a? Symbol
54
+
55
+ if feature.is_a? String
56
+ feature = feature.camelize
57
+ feature = Middleman::Features.const_get(feature)
58
+ end
59
+
60
+ register feature
61
+ end
62
+
63
+ # Deprecated API. Please use `activate` instead.
64
+ def enable(feature_name)
65
+ $stderr.puts "Warning: Feature activation has been renamed from enable to activate"
66
+ activate(feature_name)
67
+ super(feature_name)
68
+ end
69
+
70
+ # Add a block/proc to be run after features have been setup
71
+ def after_feature_init(&block)
72
+ @run_after_features ||= []
73
+ @run_after_features << block
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_extensions.each do |ext|
88
+ activate ext
89
+ end
90
+
91
+ @run_after_features.each { |block| class_eval(&block) }
92
+
93
+ super
94
+ end
95
+ end
96
+ end