middleman-more 3.0.0.alpha.7 → 3.0.0.alpha.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,6 +53,7 @@ module Middleman
53
53
  # Sprockets asset handling
54
54
  Base.register Middleman::CoreExtensions::Sprockets
55
55
 
56
+ # Register the optional extensions
56
57
  Extensions.register(:cache_buster) {
57
58
  ::Middleman::Extensions::CacheBuster }
58
59
  Extensions.register(:minify_css) {
@@ -4,7 +4,8 @@ module Middleman::CoreExtensions::Compass
4
4
 
5
5
  # Extension registered
6
6
  class << self
7
- # @private
7
+
8
+ # Once registered
8
9
  def registered(app)
9
10
  require "compass"
10
11
 
@@ -1,9 +1,15 @@
1
- require 'pathname'
1
+ # Require gem
2
2
  require "sprockets"
3
3
 
4
+ # Sprockets extension
4
5
  module Middleman::CoreExtensions::Sprockets
6
+
7
+ # Setup extension
5
8
  class << self
9
+
10
+ # Once registered
6
11
  def registered(app)
12
+ # Default compression to off
7
13
  app.set :js_compressor, false
8
14
  app.set :css_compressor, false
9
15
 
@@ -19,9 +25,12 @@ module Middleman::CoreExtensions::Sprockets
19
25
  end
20
26
  end
21
27
 
28
+ # Once Middleman is setup
22
29
  app.ready do
30
+ # Create sprockets env for JS
23
31
  js_env = Middleman::CoreExtensions::Sprockets::JavascriptEnvironment.new(self)
24
32
 
33
+ # Add any gems with vendor/assets/javascripts to paths
25
34
  vendor_dir = File.join("vendor", "assets", "javascripts")
26
35
  gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
27
36
  ::Middleman.spec_has_file?(spec, vendor_dir)
@@ -29,6 +38,7 @@ module Middleman::CoreExtensions::Sprockets
29
38
  js_env.append_path File.join(spec.full_gem_path, vendor_dir)
30
39
  end
31
40
 
41
+ # Add any gems with app/assets/javascripts to paths
32
42
  app_dir = File.join("app", "assets", "javascripts")
33
43
  gems_with_js = ::Middleman.rubygems_latest_specs.select do |spec|
34
44
  ::Middleman.spec_has_file?(spec, app_dir)
@@ -36,21 +46,26 @@ module Middleman::CoreExtensions::Sprockets
36
46
  js_env.append_path File.join(spec.full_gem_path, app_dir)
37
47
  end
38
48
 
39
- # add paths to js_env (vendor/assets/javascripts)
49
+ # Intercept requests to /javascripts and pass to sprockets
40
50
  map "/#{js_dir}" do
41
51
  run js_env
42
52
  end
43
53
 
54
+ # Setup Sprockets Sass options
44
55
  sass.each { |k, v| ::Sprockets::Sass.options[k] = v }
56
+
57
+ # Create sprockets env for CSS
45
58
  css_env = Middleman::CoreExtensions::Sprockets::StylesheetEnvironment.new(self)
46
59
 
60
+ # Add any gems with vendor/assets/stylesheets to paths
47
61
  vendor_dir = File.join("vendor", "assets", "stylesheets")
48
62
  gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
49
63
  ::Middleman.spec_has_file?(spec, vendor_dir)
50
64
  end.each do |spec|
51
65
  css_env.append_path File.join(spec.full_gem_path, vendor_dir)
52
66
  end
53
-
67
+
68
+ # Add any gems with app/assets/stylesheets to paths
54
69
  app_dir = File.join("app", "assets", "stylesheets")
55
70
  gems_with_css = ::Middleman.rubygems_latest_specs.select do |spec|
56
71
  ::Middleman.spec_has_file?(spec, app_dir)
@@ -58,6 +73,7 @@ module Middleman::CoreExtensions::Sprockets
58
73
  css_env.append_path File.join(spec.full_gem_path, app_dir)
59
74
  end
60
75
 
76
+ # Intercept requests to /stylesheets and pass to sprockets
61
77
  map("/#{css_dir}") do
62
78
  run css_env
63
79
  end
@@ -66,7 +82,9 @@ module Middleman::CoreExtensions::Sprockets
66
82
  alias :included :registered
67
83
  end
68
84
 
85
+ # Generic Middleman Sprockets env
69
86
  class MiddlemanEnvironment < ::Sprockets::Environment
87
+ # Setup
70
88
  def initialize(app)
71
89
  @app = app
72
90
  super app.source_dir
@@ -84,19 +102,26 @@ module Middleman::CoreExtensions::Sprockets
84
102
  end
85
103
  end
86
104
 
105
+ # During development, don't use the asset cache
87
106
  def find_asset(path, options = {})
88
107
  expire_index! if @app.development?
89
108
  super
90
109
  end
91
110
  end
92
111
 
112
+ # Javascript specific environment
93
113
  class JavascriptEnvironment < MiddlemanEnvironment
114
+
115
+ # Init
94
116
  def initialize(app)
95
117
  super
96
118
 
97
119
  expire_index!
98
120
 
121
+ # Remove old compressor
99
122
  unregister_bundle_processor 'application/javascript', :js_compressor
123
+
124
+ # Register compressor from config
100
125
  register_bundle_processor 'application/javascript', :js_compressor do |context, data|
101
126
  if context.pathname.to_s =~ /\.min\./
102
127
  data
@@ -109,19 +134,26 @@ module Middleman::CoreExtensions::Sprockets
109
134
  append_path app.js_dir
110
135
  end
111
136
 
137
+ # Clear cache on error
112
138
  def javascript_exception_response(exception)
113
139
  expire_index!
114
140
  super(exception)
115
141
  end
116
142
  end
117
143
 
144
+ # CSS specific environment
118
145
  class StylesheetEnvironment < MiddlemanEnvironment
146
+
147
+ # Init
119
148
  def initialize(app)
120
149
  super
121
150
 
122
151
  expire_index!
123
152
 
153
+ # Remove old compressor
124
154
  unregister_bundle_processor 'text/css', :css_compressor
155
+
156
+ # Register compressor from config
125
157
  register_bundle_processor 'text/css', :css_compressor do |context, data|
126
158
  if context.pathname.to_s =~ /\.min\./
127
159
  data
@@ -133,7 +165,8 @@ module Middleman::CoreExtensions::Sprockets
133
165
  # configure search paths
134
166
  append_path app.css_dir
135
167
  end
136
-
168
+
169
+ # Clear cache on error
137
170
  def css_exception_response(exception)
138
171
  expire_index!
139
172
  super(exception)
@@ -1,9 +1,18 @@
1
+ # Extension namespace
1
2
  module Middleman::Extensions
3
+
4
+ # The Cache Buster extension
2
5
  module CacheBuster
6
+
7
+ # Setup extension
3
8
  class << self
9
+
10
+ # Once registered
4
11
  def registered(app)
12
+ # Add instance methods to context
5
13
  app.send :include, InstanceMethods
6
14
 
15
+ # After compass is setup, make it use the registered cache buster
7
16
  app.compass_config do |config|
8
17
  config.asset_cache_buster do |path, real_path|
9
18
  real_path = real_path.path if real_path.is_a? File
@@ -19,7 +28,12 @@ module Middleman::Extensions
19
28
  alias :included :registered
20
29
  end
21
30
 
31
+ # Cache buster instance methods
22
32
  module InstanceMethods
33
+
34
+ # asset_url override if we're using cache busting
35
+ # @param [String] path
36
+ # @param [String] prefix
23
37
  def asset_url(path, prefix="")
24
38
  http_path = super
25
39
 
@@ -55,5 +69,6 @@ module Middleman::Extensions
55
69
  end
56
70
  end
57
71
 
72
+ # Register the extension
58
73
  register :cache_buster, CacheBuster
59
74
  end
@@ -1,7 +1,15 @@
1
+ # Extensions namespace
1
2
  module Middleman::Extensions
3
+
4
+ # Minify CSS Extension
2
5
  module MinifyCss
6
+
7
+ # Setup extension
3
8
  class << self
9
+
10
+ # Once registered
4
11
  def registered(app)
12
+ # Tell Sprockets to use the built in CSSMin
5
13
  app.after_configuration do
6
14
  if !css_compressor
7
15
  require "middleman-more/extensions/minify_css/cssmin"
@@ -13,5 +21,6 @@ module Middleman::Extensions
13
21
  end
14
22
  end
15
23
 
24
+ # Register extension
16
25
  register :minify_css, MinifyCss
17
26
  end
@@ -1,25 +1,45 @@
1
+ # Extension namespace
1
2
  module Middleman::Extensions
3
+
4
+ # Minify Javascript Extension
2
5
  module MinifyJavascript
6
+
7
+ # Setup extension
3
8
  class << self
9
+
10
+ # Once registered
4
11
  def registered(app)
12
+
13
+ # Once config is parsed
5
14
  app.after_configuration do
15
+
16
+ # Tell sprockets which compressor to use
6
17
  if !js_compressor
7
18
  require 'uglifier'
8
19
  set :js_compressor, ::Uglifier.new
9
20
  end
10
21
 
22
+ # Setup Rack to watch for inline JS
11
23
  use InlineJavascriptRack, :compressor => js_compressor
12
24
  end
13
25
  end
14
26
  alias :included :registered
15
27
  end
16
28
 
29
+ # Rack middleware to look for JS in HTML and compress it
17
30
  class InlineJavascriptRack
31
+
32
+ # Init
33
+ # @param [Class] app
34
+ # @param [Hash] options
18
35
  def initialize(app, options={})
19
36
  @app = app
20
37
  @compressor = options[:compressor]
21
38
  end
22
39
 
40
+ # Rack interface
41
+ # @param [Rack::Environmemt] env
42
+ # @return [Array]
23
43
  def call(env)
24
44
  status, headers, response = @app.call(env)
25
45
 
@@ -52,5 +72,6 @@ module Middleman::Extensions
52
72
  end
53
73
  end
54
74
 
75
+ # Register extension
55
76
  register :minify_javascript, MinifyJavascript
56
77
  end
@@ -1,17 +1,32 @@
1
+ # Extension namespace
1
2
  module Middleman::Extensions
3
+
4
+ # Relative Assets extension
2
5
  module RelativeAssets
6
+
7
+ # Setup extension
3
8
  class << self
9
+
10
+ # Once registered
4
11
  def registered(app)
12
+ # Tell compass to use relative assets
5
13
  app.compass_config do |config|
6
14
  config.relative_assets = true
7
15
  end
8
16
 
17
+ # Include instance methods
9
18
  app.send :include, InstanceMethods
10
19
  end
11
20
  alias :included :registered
12
21
  end
13
22
 
23
+ # Relative Assets instance method
14
24
  module InstanceMethods
25
+
26
+ # asset_url override for relative assets
27
+ # @param [String] path
28
+ # @param [String] prefix
29
+ # @return [String]
15
30
  def asset_url(path, prefix="")
16
31
  begin
17
32
  prefix = images_dir if prefix == http_images_path
@@ -42,5 +57,6 @@ module Middleman::Extensions
42
57
  end
43
58
  end
44
59
 
60
+ # Register extension
45
61
  register :relative_assets, RelativeAssets
46
62
  end
@@ -1,9 +1,17 @@
1
+ # Require gem
2
+ require "haml"
3
+
4
+ # Haml Renderer
1
5
  module Middleman::Renderers::Haml
6
+
7
+ # Setup extension
2
8
  class << self
9
+ # Once registered
3
10
  def registered(app)
4
- require "haml"
11
+ # Add haml helpers to context
5
12
  app.send :include, ::Haml::Helpers
6
13
 
14
+ # Setup haml helper paths
7
15
  app.ready do
8
16
  init_haml_helpers
9
17
  end
@@ -1,14 +1,23 @@
1
+ # Liquid Renderer
1
2
  module Middleman::Renderers::Liquid
3
+
4
+ # Setup extension
2
5
  class << self
6
+
7
+ # Once registerd
3
8
  def registered(app)
4
9
  # Liquid is not included in the default gems,
5
10
  # but we'll support it if available.
6
11
  begin
12
+
13
+ # Require Gem
7
14
  require "liquid"
8
15
 
16
+ # After config, setup liquid partial paths
9
17
  app.after_configuration do
10
18
  Liquid::Template.file_system = Liquid::LocalFileSystem.new(source_dir)
11
19
 
20
+ # Convert data object into a hash for liquid
12
21
  provides_metadata %r{\.liquid$} do |path|
13
22
  { :locals => { :data => data.to_h } }
14
23
  end
@@ -1,6 +1,12 @@
1
+ # Markdown renderer
1
2
  module Middleman::Renderers::Markdown
3
+
4
+ # Setup extension
2
5
  class << self
6
+
7
+ # Once registered
3
8
  def registered(app)
9
+ # Require redcarpet gem
4
10
  require "redcarpet"
5
11
 
6
12
  # Forcably disable Redcarpet1 support.
@@ -8,17 +14,24 @@ module Middleman::Renderers::Markdown
8
14
  # layer disables extensions.
9
15
  Object.send(:remove_const, :RedcarpetCompat) if defined? ::RedcarpetCompat
10
16
 
17
+ # Set our preference for a markdown engine
11
18
  app.set :markdown_engine, :redcarpet
12
19
  app.set :markdown_engine_prefix, ::Tilt
13
20
 
21
+ # Once configuration is parsed
14
22
  app.after_configuration do
23
+
24
+ # Look for the user's preferred engine
15
25
  unless markdown_engine.nil?
26
+
27
+ # Map symbols to classes
16
28
  if markdown_engine.is_a? Symbol
17
29
  engine = engine.to_s
18
30
  engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
19
31
  markdown_engine = markdown_engine_prefix.const_get("#{engine}Template")
20
32
  end
21
33
 
34
+ # Tell tilt to use that engine
22
35
  ::Tilt.prefer(markdown_engine)
23
36
  end
24
37
  end
@@ -1,9 +1,15 @@
1
+ # Pull in gems
2
+ require "sass"
1
3
  require "sprockets"
2
4
  require "sprockets-sass"
3
- require "sass"
4
5
 
6
+ # Sass renderer
5
7
  module Middleman::Renderers::Sass
8
+
9
+ # Setup extension
6
10
  class << self
11
+
12
+ # Once registered
7
13
  def registered(app)
8
14
  # Default sass options
9
15
  app.set :sass, {}
@@ -11,8 +17,13 @@ module Middleman::Renderers::Sass
11
17
  alias :included :registered
12
18
  end
13
19
 
20
+ # A SassTemplate for Sprockets/Tilt which outputs debug messages
14
21
  class SassPlusCSSFilenameTemplate < ::Sprockets::Sass::SassTemplate
22
+
15
23
  # Add exception messaging
24
+ # @param [Class] context
25
+ # @param [Hash] locals
26
+ # @return [String]
16
27
  def evaluate(context, locals, &block)
17
28
  begin
18
29
  super
@@ -22,6 +33,8 @@ module Middleman::Renderers::Sass
22
33
  end
23
34
 
24
35
  protected
36
+ # Change Sass path, for url functions, to the build folder if we're building
37
+ # @return [Hash]
25
38
  def sass_options
26
39
  location_of_sass_file = if @context.build?
27
40
  File.expand_path(@context.build_dir, @context.root)
@@ -36,18 +49,27 @@ module Middleman::Renderers::Sass
36
49
  super.merge(:css_filename => css_filename)
37
50
  end
38
51
  end
52
+
53
+ # Tell Sprockets to use our custom Sass template
39
54
  ::Sprockets.register_engine ".sass", SassPlusCSSFilenameTemplate
55
+
56
+ # Tell Tilt to use it as well (for inline sass blocks)
40
57
  ::Tilt.register 'sass', SassPlusCSSFilenameTemplate
41
58
  ::Tilt.prefer(SassPlusCSSFilenameTemplate)
42
59
 
60
+ # SCSS version of the above template
43
61
  class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
44
62
  # Define the expected syntax for the template
63
+ # @return [Symbol]
45
64
  def syntax
46
65
  :scss
47
66
  end
48
67
  end
49
68
 
69
+ # Tell Sprockets to use our custom Scss template
50
70
  ::Sprockets.register_engine ".scss", ScssPlusCSSFilenameTemplate
71
+
72
+ # Tell Tilt to use it as well (for inline scss blocks)
51
73
  ::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
52
74
  ::Tilt.prefer(ScssPlusCSSFilenameTemplate)
53
75
  end
@@ -1,11 +1,18 @@
1
+ # Slim renderer
1
2
  module Middleman::Renderers::Slim
3
+
4
+ # Setup extension
2
5
  class << self
6
+
7
+ # Once registered
3
8
  def registered(app)
4
9
  # Slim is not included in the default gems,
5
10
  # but we'll support it if available.
6
11
  begin
12
+ # Load gem
7
13
  require "slim"
8
14
 
15
+ # Setup Slim options to work with partials
9
16
  Slim::Engine.set_default_options(:buffer => '@_out_buf', :generator => Temple::Generators::StringBuffer) if defined?(Slim)
10
17
  rescue LoadError
11
18
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-more
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3702664398
4
+ hash: -3702664404
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
10
  - alpha
11
- - 7
12
- version: 3.0.0.alpha.7
11
+ - 8
12
+ version: 3.0.0.alpha.8
13
13
  platform: ruby
14
14
  authors:
15
15
  - Thomas Reynolds
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-12-29 00:00:00 -08:00
20
+ date: 2012-01-02 00:00:00 -08:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -28,14 +28,14 @@ dependencies:
28
28
  requirements:
29
29
  - - "="
30
30
  - !ruby/object:Gem::Version
31
- hash: -3702664398
31
+ hash: -3702664404
32
32
  segments:
33
33
  - 3
34
34
  - 0
35
35
  - 0
36
36
  - alpha
37
- - 7
38
- version: 3.0.0.alpha.7
37
+ - 8
38
+ version: 3.0.0.alpha.8
39
39
  name: middleman-core
40
40
  version_requirements: *id001
41
41
  - !ruby/object:Gem::Dependency