middleman-more 3.0.0 → 3.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.cane +2 -0
  2. data/.cane-exclusions.yml +3 -0
  3. data/features/coffee-script.feature +6 -1
  4. data/features/markdown_redcarpet.feature +23 -1
  5. data/features/minify_css.feature +2 -0
  6. data/features/sass-assets-paths.feature +11 -0
  7. data/features/sass_cache_path.feature +22 -0
  8. data/features/slim.feature +49 -1
  9. data/features/support/env.rb +2 -2
  10. data/fixtures/asset-host-app/config.rb +1 -1
  11. data/fixtures/auto-css-app/config.rb +1 -1
  12. data/fixtures/auto-js-app/config.rb +1 -1
  13. data/fixtures/coffeescript-app/config.rb +1 -1
  14. data/fixtures/content-for-app/config.rb +1 -1
  15. data/fixtures/extensionless-text-files-app/config.rb +1 -1
  16. data/fixtures/lorem-app/config.rb +1 -1
  17. data/fixtures/markdown-app/source/images/blank.gif +0 -0
  18. data/fixtures/minify-css-app/source/stylesheets/report.css +1 -0
  19. data/fixtures/nested-layout-app/config.rb +1 -1
  20. data/fixtures/page-classes-app/config.rb +1 -1
  21. data/fixtures/relative-assets-app/config.rb +1 -1
  22. data/fixtures/sass-assets-path-app/assets/stylesheets/_shared-asset.sass +1 -0
  23. data/fixtures/sass-assets-path-app/assets/stylesheets/_shared-asset.scss +1 -0
  24. data/fixtures/sass-assets-path-app/config.rb +4 -0
  25. data/fixtures/sass-assets-path-app/my-vendor/stylesheets/_partial.sass +2 -0
  26. data/fixtures/sass-assets-path-app/source/stylesheets/plain.css.sass +16 -0
  27. data/fixtures/sass-cache-path-custom-app/config.rb +3 -0
  28. data/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass +4 -0
  29. data/fixtures/sass-cache-path-default-app/config.rb +3 -0
  30. data/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass +4 -0
  31. data/fixtures/traversal-app/config.rb +1 -1
  32. data/fixtures/wildcard-directory-index-app/config.rb +1 -1
  33. data/lib/middleman-more.rb +19 -16
  34. data/lib/middleman-more/core_extensions/assets.rb +5 -5
  35. data/lib/middleman-more/core_extensions/compass.rb +9 -4
  36. data/lib/middleman-more/core_extensions/default_helpers.rb +3 -3
  37. data/lib/middleman-more/core_extensions/i18n.rb +31 -27
  38. data/lib/middleman-more/extensions/asset_hash.rb +8 -7
  39. data/lib/middleman-more/extensions/asset_host.rb +9 -9
  40. data/lib/middleman-more/extensions/automatic_image_sizes.rb +6 -6
  41. data/lib/middleman-more/extensions/automatic_image_sizes/fastimage.rb +6 -6
  42. data/lib/middleman-more/extensions/cache_buster.rb +11 -11
  43. data/lib/middleman-more/extensions/directory_indexes.rb +14 -13
  44. data/lib/middleman-more/extensions/gzip.rb +7 -7
  45. data/lib/middleman-more/extensions/lorem.rb +10 -10
  46. data/lib/middleman-more/extensions/minify_css.rb +5 -5
  47. data/lib/middleman-more/extensions/minify_css/rainpress.rb +2 -2
  48. data/lib/middleman-more/extensions/minify_javascript.rb +7 -7
  49. data/lib/middleman-more/extensions/relative_assets.rb +9 -9
  50. data/lib/middleman-more/templates/smacss.rb +30 -0
  51. data/lib/middleman-more/templates/smacss/source/_footer.haml +1 -0
  52. data/lib/middleman-more/templates/smacss/source/index.html.haml +1 -0
  53. data/lib/middleman-more/templates/smacss/source/layouts/layout.haml +13 -0
  54. data/lib/middleman-more/templates/smacss/source/stylesheets/_0.site-settings.scss +0 -0
  55. data/lib/middleman-more/templates/smacss/source/stylesheets/_1.base.scss +2 -0
  56. data/lib/middleman-more/templates/smacss/source/stylesheets/_2.layout.scss +2 -0
  57. data/lib/middleman-more/templates/smacss/source/stylesheets/_3.states.scss +2 -0
  58. data/lib/middleman-more/templates/smacss/source/stylesheets/_4.themes.scss +2 -0
  59. data/lib/middleman-more/templates/smacss/source/stylesheets/modules/_btn.scss +2 -0
  60. data/lib/middleman-more/templates/smacss/source/stylesheets/style.css.scss +7 -0
  61. data/lib/middleman_extension.rb +1 -1
  62. metadata +47 -11
@@ -8,7 +8,7 @@ module Middleman
8
8
  # @private
9
9
  def registered(app)
10
10
  require 'padrino-helpers'
11
-
11
+
12
12
  app.helpers ::Padrino::Helpers::OutputHelpers
13
13
  app.helpers ::Padrino::Helpers::TagHelpers
14
14
  app.helpers ::Padrino::Helpers::AssetTagHelpers
@@ -124,7 +124,7 @@ module Middleman
124
124
  if url = args[url_arg_index]
125
125
  options = args[options_index] || {}
126
126
  relative = options.delete(:relative)
127
-
127
+
128
128
  # Handle Resources, which define their own url method
129
129
  if url.respond_to? :url
130
130
  args[url_arg_index] = url.url
@@ -139,7 +139,7 @@ module Middleman
139
139
  url = current_source_dir.join(path).to_s if path.relative?
140
140
 
141
141
  resource = sitemap.find_resource_by_path(url)
142
-
142
+
143
143
  # Allow people to turn on relative paths for all links with set :relative_links, true
144
144
  # but still override on a case by case basis with the :relative parameter.
145
145
  effective_relative = relative || false
@@ -1,45 +1,49 @@
1
1
  module Middleman
2
2
  module CoreExtensions
3
-
3
+
4
4
  # i18n Namespace
5
5
  module Internationalization
6
6
 
7
7
  # Setup extension
8
8
  class << self
9
-
9
+
10
10
  # Once registerd
11
11
  def registered(app, options={})
12
12
  app.set :locales_dir, "locales"
13
-
13
+
14
14
  # Needed for helpers as well
15
15
  app.after_configuration do
16
16
  ::I18n.load_path += Dir[File.join(root, locales_dir, "*.yml")]
17
17
  ::I18n.reload!
18
-
18
+
19
19
  Localizer.new(self, options)
20
20
  end
21
21
  end
22
22
  alias :included :registered
23
23
  end
24
-
24
+
25
+ # Central class for managing i18n extension
25
26
  class Localizer
27
+ attr_reader :app
28
+ delegate :logger, :to => :app
29
+
26
30
  def initialize(app, options={})
27
31
  @app = app
28
32
  @maps = {}
29
33
  @options = options
30
-
34
+
31
35
  @lang_map = @options[:lang_map] || {}
32
36
  @path = @options[:path] || "/:locale/"
33
37
  @templates_dir = @options[:templates_dir] || "localizable"
34
38
  @mount_at_root = @options.has_key?(:mount_at_root) ? @options[:mount_at_root] : langs.first
35
-
39
+
36
40
  if !@app.build?
37
- puts "== Locales: #{langs.join(", ")}"
41
+ logger.info "== Locales: #{langs.join(", ")}"
38
42
  end
39
-
43
+
40
44
  # Don't output localizable files
41
45
  @app.ignore File.join(@templates_dir, "**")
42
-
46
+
43
47
  @app.sitemap.provides_metadata_for_path do |url|
44
48
  if d = get_localization_data(url)
45
49
  lang, page_id = d
@@ -53,44 +57,44 @@ module Middleman
53
57
  {}
54
58
  end
55
59
  end
56
-
60
+
57
61
  @app.sitemap.register_resource_list_manipulator(
58
62
  :i18n,
59
63
  self
60
64
  )
61
65
  end
62
-
66
+
63
67
  def langs
64
68
  @options[:langs] || begin
65
- Dir[File.join(@app.root, @app.locales_dir, "*.yml")].map { |file|
66
- File.basename(file).gsub(".yml", "")
69
+ Dir[File.join(@app.root, @app.locales_dir, "*.yml")].map { |file|
70
+ File.basename(file).gsub(".yml", "")
67
71
  }.sort.map(&:to_sym)
68
72
  end
69
73
  end
70
-
74
+
71
75
  def get_localization_data(path)
72
76
  @_localization_data ||= {}
73
77
  @_localization_data[path]
74
78
  end
75
-
79
+
76
80
  # Update the main sitemap resource list
77
81
  # @return [void]
78
82
  def manipulate_resource_list(resources)
79
83
  @_localization_data = {}
80
-
84
+
81
85
  new_resources = []
82
-
86
+
83
87
  resources.each do |resource|
84
88
  next unless File.fnmatch(File.join(@templates_dir, "**"), resource.path)
85
-
89
+
86
90
  page_id = File.basename(resource.path, File.extname(resource.path))
87
-
91
+
88
92
  langs.map do |lang|
89
93
  ::I18n.locale = lang
90
-
94
+
91
95
  localized_page_id = ::I18n.t("paths.#{page_id}", :default => page_id)
92
96
  path = resource.path.sub(@templates_dir, "")
93
-
97
+
94
98
  # Build lang path
95
99
  if @mount_at_root == lang
96
100
  prefix = "/"
@@ -98,23 +102,23 @@ module Middleman
98
102
  replacement = @lang_map.has_key?(lang) ? @lang_map[lang] : lang
99
103
  prefix = @path.sub(":locale", replacement.to_s)
100
104
  end
101
-
105
+
102
106
  path = ::Middleman::Util.normalize_path(
103
107
  File.join(prefix, path.sub(page_id, localized_page_id))
104
108
  )
105
-
109
+
106
110
  @_localization_data[path] = [lang, path, localized_page_id]
107
-
111
+
108
112
  p = ::Middleman::Sitemap::Resource.new(
109
113
  @app.sitemap,
110
114
  path
111
115
  )
112
116
  p.proxy_to(resource.path)
113
-
117
+
114
118
  new_resources << p
115
119
  end
116
120
  end
117
-
121
+
118
122
  resources + new_resources
119
123
  end
120
124
  end
@@ -5,13 +5,13 @@ module Middleman
5
5
  def registered(app, options={})
6
6
  require 'digest/sha1'
7
7
  exts = options[:exts] || %w(.jpg .jpeg .png .gif .js .css)
8
-
8
+
9
9
  # Allow specifying regexes to ignore, plus always ignore apple touch icons
10
10
  ignore = Array(options[:ignore]) << /^apple-touch-icon/
11
11
 
12
12
  app.ready do
13
13
  sitemap.register_resource_list_manipulator(
14
- :asset_hash,
14
+ :asset_hash,
15
15
  AssetHashManager.new(self, exts, ignore)
16
16
  )
17
17
  use Middleware, :exts => exts, :middleman_app => self, :ignore => ignore
@@ -20,20 +20,21 @@ module Middleman
20
20
  alias :included :registered
21
21
  end
22
22
 
23
+ # Central class for managing asset_hash extension
23
24
  class AssetHashManager
24
25
  def initialize(app, exts, ignore)
25
26
  @app = app
26
27
  @exts = exts
27
28
  @ignore = ignore
28
29
  end
29
-
30
+
30
31
  # Update the main sitemap resource list
31
32
  # @return [void]
32
33
  def manipulate_resource_list(resources)
33
34
  resources.each do |resource|
34
35
  next unless @exts.include? resource.ext
35
36
  next if @ignore.any? { |ignore| Middleman::Util.path_match(ignore, resource.destination_path) }
36
-
37
+
37
38
  if resource.template? # if it's a template, render it out
38
39
  digest = Digest::SHA1.hexdigest(resource.render)[0..7]
39
40
  else # if it's a static file, just hash it
@@ -70,17 +71,17 @@ module Middleman
70
71
  body.gsub! /([=\'\"\(]\s*)([^\s\'\"\)]+(#{@exts_regex_text}))/ do |match|
71
72
  opening_character = $1
72
73
  asset_path = $2
73
-
74
+
74
75
  relative_path = Pathname.new(asset_path).relative?
75
76
 
76
77
  asset_path = dirpath.join(asset_path).to_s if relative_path
77
-
78
+
78
79
  if @ignore.any? { |r| asset_path.match(r) }
79
80
  match
80
81
  elsif asset_page = @middleman_app.sitemap.find_resource_by_path(asset_path)
81
82
  replacement_path = "/#{asset_page.destination_path}"
82
83
  replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
83
-
84
+
84
85
  "#{opening_character}#{replacement_path}"
85
86
  else
86
87
  match
@@ -1,28 +1,28 @@
1
1
  # Extensions namespace
2
2
  module Middleman
3
3
  module Extensions
4
-
4
+
5
5
  # Asset Host module
6
6
  module AssetHost
7
-
7
+
8
8
  # Setup extension
9
9
  class << self
10
-
10
+
11
11
  # Once registered
12
12
  def registered(app)
13
13
  # Default to no host
14
14
  app.set :asset_host, false
15
-
15
+
16
16
  # Include methods
17
17
  app.send :include, InstanceMethods
18
18
  end
19
-
19
+
20
20
  alias :included :registered
21
21
  end
22
-
22
+
23
23
  # Asset Host Instance Methods
24
24
  module InstanceMethods
25
-
25
+
26
26
  # Override default asset url helper to include asset hosts
27
27
  #
28
28
  # @param [String] path
@@ -37,10 +37,10 @@ module Middleman
37
37
  elsif asset_host.is_a?(String)
38
38
  asset_host
39
39
  end
40
-
40
+
41
41
  File.join(asset_prefix, original_output)
42
42
  end
43
43
  end
44
44
  end
45
45
  end
46
- end
46
+ end
@@ -1,13 +1,13 @@
1
1
  # Extensions namespace
2
2
  module Middleman
3
3
  module Extensions
4
-
4
+
5
5
  # Automatic Image Sizes extension
6
6
  module AutomaticImageSizes
7
-
7
+
8
8
  # Setup extension
9
9
  class << self
10
-
10
+
11
11
  # Once registered
12
12
  def registered(app)
13
13
  # Include 3rd-party fastimage library
@@ -16,13 +16,13 @@ module Middleman
16
16
  # Include methods
17
17
  app.send :include, InstanceMethods
18
18
  end
19
-
19
+
20
20
  alias :included :registered
21
21
  end
22
-
22
+
23
23
  # Automatic Image Sizes Instance Methods
24
24
  module InstanceMethods
25
-
25
+
26
26
  # Override default image_tag helper to automatically calculate and include
27
27
  # image dimensions.
28
28
  #
@@ -3,7 +3,7 @@
3
3
  # It does this by using a feature of Net::HTTP that yields strings from the resource being fetched
4
4
  # as soon as the packets arrive.
5
5
  #
6
- # No external libraries such as ImageMagick are used here, this is a very lightweight solution to
6
+ # No external libraries such as ImageMagick are used here, this is a very lightweight solution to
7
7
  # finding image information.
8
8
  #
9
9
  # FastImage knows about GIF, JPEG, BMP and PNG files.
@@ -47,7 +47,7 @@ class FastImage
47
47
  end
48
48
 
49
49
  DefaultTimeout = 2
50
-
50
+
51
51
  LocalFileChunkSize = 256
52
52
 
53
53
  # Returns an array containing the width and height of the image.
@@ -148,7 +148,7 @@ class FastImage
148
148
  end
149
149
  end
150
150
  raise SizeNotFound if options[:raise_on_failure] && @property == :size && !@size
151
- rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,
151
+ rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,
152
152
  ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT
153
153
  raise ImageFetchFailure if options[:raise_on_failure]
154
154
  rescue NoMethodError # 1.8.7p248 can raise this due to a net/http bug
@@ -192,7 +192,7 @@ class FastImage
192
192
  @strpos = 0
193
193
  begin
194
194
  result = send("parse_#{@property}")
195
- if result
195
+ if result
196
196
  instance_variable_set("@#{@property}", result)
197
197
  true
198
198
  end
@@ -257,7 +257,7 @@ class FastImage
257
257
  get_chars(2)
258
258
  :started
259
259
  when :started
260
- get_byte == 0xFF ? :sof : :started
260
+ get_byte == 0xFF ? :sof : :started
261
261
  when :sof
262
262
  c = get_byte
263
263
  if (0xe0..0xef).include?(c)
@@ -284,4 +284,4 @@ class FastImage
284
284
  d = get_chars(29)[14..28]
285
285
  d.unpack("C")[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS')
286
286
  end
287
- end
287
+ end
@@ -1,37 +1,37 @@
1
1
  # Extension namespace
2
2
  module Middleman
3
3
  module Extensions
4
-
4
+
5
5
  # The Cache Buster extension
6
6
  module CacheBuster
7
-
7
+
8
8
  # Setup extension
9
9
  class << self
10
-
10
+
11
11
  # Once registered
12
12
  def registered(app)
13
13
  # Add instance methods to context
14
14
  app.send :include, InstanceMethods
15
-
15
+
16
16
  # After compass is setup, make it use the registered cache buster
17
17
  app.compass_config do |config|
18
18
  config.asset_cache_buster do |path, real_path|
19
19
  real_path = real_path.path if real_path.is_a? File
20
20
  real_path = real_path.gsub(File.join(root, build_dir), source)
21
21
  if File.readable?(real_path)
22
- File.mtime(real_path).strftime("%s")
22
+ File.mtime(real_path).strftime("%s")
23
23
  else
24
- $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
24
+ logger.warn "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
25
25
  end
26
26
  end
27
27
  end
28
28
  end
29
29
  alias :included :registered
30
30
  end
31
-
31
+
32
32
  # Cache buster instance methods
33
33
  module InstanceMethods
34
-
34
+
35
35
  # asset_url override if we're using cache busting
36
36
  # @param [String] path
37
37
  # @param [String] prefix
@@ -46,7 +46,7 @@ module Middleman
46
46
  end
47
47
 
48
48
  real_path_static = File.join(prefix, path)
49
-
49
+
50
50
  if build?
51
51
  real_path_dynamic = File.join(build_dir, prefix, path)
52
52
  real_path_dynamic = File.expand_path(real_path_dynamic, root)
@@ -61,11 +61,11 @@ module Middleman
61
61
  http_path << "?" + Time.now.strftime("%s")
62
62
  end
63
63
  end
64
-
64
+
65
65
  http_path
66
66
  end
67
67
  end
68
68
  end
69
69
  end
70
70
  end
71
- end
71
+ end
@@ -1,18 +1,18 @@
1
1
  # Extensions namespace
2
2
  module Middleman
3
3
  module Extensions
4
-
4
+
5
5
  # Directory Indexes extension
6
6
  module DirectoryIndexes
7
-
7
+
8
8
  # Setup extension
9
9
  class << self
10
-
10
+
11
11
  # Once registered
12
12
  def registered(app)
13
13
  app.ready do
14
14
  sitemap.register_resource_list_manipulator(
15
- :directory_indexes,
15
+ :directory_indexes,
16
16
  DirectoryIndexManager.new(self)
17
17
  )
18
18
  end
@@ -20,37 +20,38 @@ module Middleman
20
20
 
21
21
  alias :included :registered
22
22
  end
23
-
23
+
24
+ # Central class for managing the directory indexes extension
24
25
  class DirectoryIndexManager
25
26
  def initialize(app)
26
27
  @app = app
27
28
  end
28
-
29
+
29
30
  # Update the main sitemap resource list
30
31
  # @return [void]
31
32
  def manipulate_resource_list(resources)
32
33
  index_file = @app.index_file
33
34
  new_index_path = "/#{index_file}"
34
-
35
+
35
36
  resources.each do |resource|
36
37
  # Check if it would be pointless to reroute
37
- next if resource.path == index_file ||
38
- resource.path.end_with?(new_index_path) ||
38
+ next if resource.destination_path == index_file ||
39
+ resource.destination_path.end_with?(new_index_path) ||
39
40
  File.extname(index_file) != resource.ext
40
-
41
+
41
42
  # Check if frontmatter turns directory_index off
42
43
  d = resource.data
43
44
  next if d && d["directory_index"] == false
44
-
45
+
45
46
  # Check if file metadata (options set by "page" in config.rb) turns directory_index off
46
47
  if resource.metadata[:options] && resource.metadata[:options][:directory_index] == false
47
48
  next
48
49
  end
49
-
50
+
50
51
  resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path
51
52
  end
52
53
  end
53
54
  end
54
55
  end
55
56
  end
56
- end
57
+ end