diff --git a/middleman-core/features/clean_build.feature b/middleman-core/features/clean_build.feature index e9400558..ba93ae0e 100644 --- a/middleman-core/features/clean_build.feature +++ b/middleman-core/features/clean_build.feature @@ -16,19 +16,6 @@ Feature: Build Clean | build/should_be_ignored3.html | And the file "build/index.html" should contain "Comment in layout" - Scenario: Clean an app with directory indexes - Given a successfully built app at "clean-dir-app" - Then the following files should exist: - | build/about/index.html | - Given a successfully built app at "clean-dir-app" with flags "--clean" - Then the following files should exist: - | build/about/index.html | - - Scenario: Clean build an app that's never been built - Given a successfully built app at "clean-dir-app" with flags "--clean" - Then the following files should exist: - | build/about/index.html | - Scenario: Clean build an app with newly ignored files and a nested output directory Given a built app at "clean-nested-app" Then a directory named "sub/dir" should exist diff --git a/middleman-core/features/extensionless_text_files.feature b/middleman-core/features/extensionless_text_files.feature index d5e983d9..331d523f 100644 --- a/middleman-core/features/extensionless_text_files.feature +++ b/middleman-core/features/extensionless_text_files.feature @@ -1,46 +1,14 @@ Feature: Text Files Without Extensions Should Build and Preview Scenario: Building Text Files without directory indexes - Given a fixture app "extensionless-text-files-app" - And a file named "config.rb" with: - """ - """ - And a successfully built app at "extensionless-text-files-app" + Given a successfully built app at "extensionless-text-files-app" When I cd to "build" Then the following files should exist: | CNAME | | LICENSE | | README | - - Scenario: Building Text Files with directory indexes - Given a fixture app "extensionless-text-files-app" - And a file named "config.rb" with: - """ - activate :directory_indexes - """ - And a successfully built app at "extensionless-text-files-app" - When I cd to "build" - Then the following files should exist: - | CNAME | - | LICENSE | - | README | - Then the following files should not exist: - | CNAME/index.html | - | LICENSE/index.html | - | README/index.html | - Scenario: Previewing Text Files without directory indexes - Given "directory_indexes" feature is "disabled" - Given the Server is running at "extensionless-text-files-app" - When I go to "/CNAME" - Then I should see "test.github.com" - When I go to "/LICENSE" - Then I should see "You have the right to remain classy." - When I go to "/README" - Then I should see "Bork bork bork" - - Scenario: Previewing Text Files with directory indexes - Given "directory_indexes" feature is "enabled" + Scenario: Previewing Text Files Given the Server is running at "extensionless-text-files-app" When I go to "/CNAME" Then I should see "test.github.com" diff --git a/middleman-core/features/frontmatter_page_settings.feature b/middleman-core/features/frontmatter_page_settings.feature index 1a12cfd7..f9f3ec94 100644 --- a/middleman-core/features/frontmatter_page_settings.feature +++ b/middleman-core/features/frontmatter_page_settings.feature @@ -2,33 +2,24 @@ Feature: Setting page settings through frontmatter Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (build) Given a successfully built app at "frontmatter-settings-app" Then the following files should exist: - | build/proxied/index.html | - | build/no_index.html | - And the file "build/alternate_layout/index.html" should contain "Alternate layout" + | build/proxied.html | + And the file "build/alternate_layout.html" should contain "Alternate layout" And the following files should not exist: - | build/ignored/index.html | - | build/no_index/index.html | - + | build/ignored.html | Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (preview) Given the Server is running at "frontmatter-settings-app" - # When I go to "/proxied/" - # Then I should not see "File Not Found" - When I go to "/no_index.html" - Then I should not see "File Not Found" - When I go to "/alternate_layout/" + When I go to "/alternate_layout.html" Then I should not see "File Not Found" And I should see "Alternate layout" When I go to "/ignored.html" Then I should see "File Not Found" When I go to "/ignored/index.html" Then I should see "File Not Found" - When I go to "/no_index/index.html" - Then I should see "File Not Found" Scenario: Changing frontmatter in preview server Given the Server is running at "frontmatter-settings-app" - When I go to "/ignored/index.html" + When I go to "/ignored.html" Then I should see "File Not Found" And the file "source/ignored.html.erb" has the contents """ @@ -38,5 +29,5 @@ Feature: Setting page settings through frontmatter This file is no longer ignored. """ - When I go to "/ignored/index.html" + When I go to "/ignored.html" Then I should see "This file is no longer ignored." diff --git a/middleman-core/features/helpers_relative_link_to.feature b/middleman-core/features/helpers_relative_link_to.feature index b9ba39d2..75abf62d 100644 --- a/middleman-core/features/helpers_relative_link_to.feature +++ b/middleman-core/features/helpers_relative_link_to.feature @@ -45,24 +45,4 @@ Feature: relative_link_to helper Then I should see 'unknown: Unknown' When I go to "/link_to/sub.html" Then I should see 'absolute: Needs Index' - Then I should see 'relative: Relative' - - Scenario: relative_link_to knows about directory indexes - Given a fixture app "indexable-app" - And a file named "source/link_to.html.erb" with: - """ - absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %> - relative: <%= link_to "Relative", "needs_index.html", :relative => true %> - """ - And a file named "source/link_to/sub.html.erb" with: - """ - absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %> - relative: <%= link_to "Relative", "../needs_index.html", :relative => true %> - """ - And the Server is running at "indexable-app" - When I go to "/link_to/" - Then I should see 'absolute: Needs Index' - Then I should see 'relative: Relative' - When I go to "/link_to/sub/" - Then I should see 'absolute: Needs Index' - Then I should see 'relative: Relative' \ No newline at end of file + Then I should see 'relative: Relative' \ No newline at end of file diff --git a/middleman-core/features/ignore.feature b/middleman-core/features/ignore.feature index f98444bc..166002c5 100644 --- a/middleman-core/features/ignore.feature +++ b/middleman-core/features/ignore.feature @@ -118,81 +118,4 @@ Feature: Ignoring paths When I go to "/reports/another.html" Then I should see "File Not Found" When I go to "/images/icons/messages.png" - Then I should see "File Not Found" - - Scenario: Ignore with directory indexes (source file, build) - Given a fixture app "ignore-app" - And a file named "config.rb" with: - """ - activate :directory_indexes - ignore 'about.html.erb' - ignore 'plain.html' - """ - And a successfully built app at "ignore-app" - Then the following files should exist: - | build/index.html | - And the following files should not exist: - | build/about/index.html | - | build/plain/index.html | - - Scenario: Ignore with directory indexes (source file, server) - Given a fixture app "ignore-app" - And a file named "config.rb" with: - """ - activate :directory_indexes - ignore 'about.html.erb' - ignore 'plain.html' - """ - And the Server is running - When I go to "/index.html" - Then I should not see "File Not Found" - When I go to "/about/index.html" - Then I should see "File Not Found" - When I go to "/plain/index.html" - Then I should see "File Not Found" - - Scenario: Ignore with directory indexes (output path splat, build) - Given a fixture app "ignore-app" - And a file named "config.rb" with: - """ - activate :directory_indexes - ignore 'about*' - ignore 'plain*' - """ - And a successfully built app at "ignore-app" - Then the following files should exist: - | build/index.html | - And the following files should not exist: - | build/about/index.html | - | build/plain/index.html | - - Scenario: Ignore with directory indexes (output path splat, server) - Given a fixture app "ignore-app" - And a file named "config.rb" with: - """ - activate :directory_indexes - ignore 'about*' - ignore 'plain*' - """ - And the Server is running - When I go to "/index.html" - Then I should not see "File Not Found" - When I go to "/about/index.html" - Then I should see "File Not Found" - When I go to "/plain/index.html" - Then I should see "File Not Found" - - # Scenario: Ignore with directory indexes (output path index) - # Given a fixture app "ignore-app" - # And a file named "config.rb" with: - # """ - # activate :directory_indexes - # ignore 'about/index.html' - # ignore 'plain/index.html' - # """ - # And a successfully built app at "ignore-app" - # Then the following files should exist: - # | build/index.html | - # And the following files should not exist: - # | build/about/index.html | - # | build/plain/index.html | \ No newline at end of file + Then I should see "File Not Found" \ No newline at end of file diff --git a/middleman-core/features/sitemap_traversal.feature b/middleman-core/features/sitemap_traversal.feature index d6e94637..828a2507 100644 --- a/middleman-core/features/sitemap_traversal.feature +++ b/middleman-core/features/sitemap_traversal.feature @@ -35,7 +35,7 @@ Feature: Step through sitemap as a tree Scenario: Page has siblings, parent, and source file Given the Server is running at "traversal-app" - When I go to "/sub/sibling/" + When I go to "/sub/sibling.html" Then I should see "Parent: sub/index.html" Then I should see "Sibling: sub/fake.html" Then I should see "Sibling: sub/fake2.html" @@ -45,7 +45,7 @@ Feature: Step through sitemap as a tree Scenario: Proxied page has siblings, parent, and source file Given the Server is running at "traversal-app" - When I go to "/sub/fake/" + When I go to "/sub/fake.html" Then I should see "Path: sub/fake.html" Then I should see "Parent: sub/index.html" Then I should see "Sibling: sub/fake2.html" @@ -56,13 +56,13 @@ Feature: Step through sitemap as a tree Scenario: Child pages have data Given the Server is running at "traversal-app" - When I go to "/directory-indexed" + When I go to "/directory-indexed.html" Then I should see "Title of Sibling One" Then I should see "Title of Sibling Two" - Scenario: When directory_index extension is active, child pages are found in named directory + Scenario: When directory_index extension is inactive, child pages are found in named directory Given the Server is running at "traversal-app" - When I go to "/directory-indexed" + When I go to "/directory-indexed.html" Then I should see "Path: directory-indexed.html" Then I should see "Parent: index.html" Then I should see "Child: directory-indexed/fake.html" diff --git a/middleman-core/features/wildcard_page_helper.feature b/middleman-core/features/wildcard_page_helper.feature index 5ac7a25e..9dd21b2b 100644 --- a/middleman-core/features/wildcard_page_helper.feature +++ b/middleman-core/features/wildcard_page_helper.feature @@ -7,13 +7,4 @@ Feature: Wildcards in Page helper When I go to "/admin/index.html" Then I should see "Admin Layout" When I go to "/admin/page.html" - Then I should see "Admin Layout" - - Scenario: Setting the layout for a folder - Given the Server is running at "wildcard-directory-index-app" - When I go to "/" - Then I should see "Normal Layout" - When I go to "/admin/" - Then I should see "Admin Layout" - When I go to "/admin/page/" Then I should see "Admin Layout" \ No newline at end of file diff --git a/middleman-core/fixtures/asset-host-app/config.rb b/middleman-core/fixtures/asset-host-app/config.rb deleted file mode 100644 index 3338c450..00000000 --- a/middleman-core/fixtures/asset-host-app/config.rb +++ /dev/null @@ -1,6 +0,0 @@ -set :layout, false - -activate :asset_host -set :asset_host do |asset| - "http://assets%d.example.com" % (asset.hash % 4) -end \ No newline at end of file diff --git a/middleman-core/fixtures/automatic-image-size-app/source/images/blank.gif b/middleman-core/fixtures/automatic-image-size-app/source/images/blank.gif deleted file mode 100755 index 2498f1aa..00000000 Binary files a/middleman-core/fixtures/automatic-image-size-app/source/images/blank.gif and /dev/null differ diff --git a/middleman-core/fixtures/frontmatter-settings-app/config.rb b/middleman-core/fixtures/frontmatter-settings-app/config.rb index 3c393758..6ec38e93 100644 --- a/middleman-core/fixtures/frontmatter-settings-app/config.rb +++ b/middleman-core/fixtures/frontmatter-settings-app/config.rb @@ -1,4 +1,2 @@ -activate :directory_indexes - # Proxy ignored.html, which should ignore itself through a frontmatter -page 'proxied.html', :proxy => 'ignored.html' +page 'proxied.html', :proxy => 'ignored.html' \ No newline at end of file diff --git a/middleman-core/fixtures/indexable-app/config.rb b/middleman-core/fixtures/indexable-app/config.rb index 54b79b5c..e69de29b 100644 --- a/middleman-core/fixtures/indexable-app/config.rb +++ b/middleman-core/fixtures/indexable-app/config.rb @@ -1,4 +0,0 @@ -activate :directory_indexes -page "/leave_me_alone.html", :directory_index => false - -page "/wildcard*", :directory_index => false diff --git a/middleman-core/fixtures/traversal-app/config.rb b/middleman-core/fixtures/traversal-app/config.rb index 6d1883c4..c5254d61 100644 --- a/middleman-core/fixtures/traversal-app/config.rb +++ b/middleman-core/fixtures/traversal-app/config.rb @@ -1,5 +1,3 @@ -activate :directory_indexes - page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index b6ff0da2..99afa35c 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -111,10 +111,6 @@ module Middleman # @return [Boolean] set :show_exceptions, true - # Automatically loaded extensions - # @return [Array] - set :default_extensions, [ :lorem ] - # Default layout name # @return [String, Symbold] set :layout, :_auto_layout @@ -162,37 +158,6 @@ module Middleman # i18n register Middleman::CoreExtensions::I18n - # Built-in Extensions - - # Provide Apache-style index.html files for directories - Middleman::Extensions.register(:directory_indexes) do - require "middleman-core/extensions/directory_indexes" - Middleman::Extensions::DirectoryIndexes - end - - # Lorem provides a handful of helpful prototyping methods to generate - # words, paragraphs, fake images, names and email addresses. - Middleman::Extensions.register(:lorem) do - require "middleman-core/extensions/lorem" - Middleman::Extensions::Lorem - end - - # AutomaticImageSizes inspects the images used in your dynamic templates - # and automatically adds width and height attributes to their HTML - # elements. - Middleman::Extensions.register(:automatic_image_sizes) do - require "middleman-core/extensions/automatic_image_sizes" - Middleman::Extensions::AutomaticImageSizes - end - - # AssetHost allows you to setup multiple domains to host your static - # assets. Calls to asset paths in dynamic templates will then rotate - # through each of the asset servers to better spread the load. - Middleman::Extensions.register(:asset_host) do - require "middleman-core/extensions/asset_host" - Middleman::Extensions::AssetHost - end - # Initialize the Middleman project def initialize(&block) # Current path defaults to nil, used in views. diff --git a/middleman-core/lib/middleman-core/core_extensions/extensions.rb b/middleman-core/lib/middleman-core/core_extensions/extensions.rb index 646d4fcb..48974fcd 100644 --- a/middleman-core/lib/middleman-core/core_extensions/extensions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/extensions.rb @@ -40,7 +40,6 @@ module Middleman # Using for version parsing require "rubygems" - # app.set :default_extensions, [] app.define_hook :after_configuration app.define_hook :before_configuration app.define_hook :build_config @@ -140,11 +139,6 @@ module Middleman run_hook :after_configuration - # Add in defaults - default_extensions.each do |ext| - activate ext - end - if logging? self.class.extensions.each do |ext| puts "== Extension: #{ext}" diff --git a/middleman-core/lib/middleman-core/extensions/asset_host.rb b/middleman-core/lib/middleman-core/extensions/asset_host.rb deleted file mode 100644 index 113f991a..00000000 --- a/middleman-core/lib/middleman-core/extensions/asset_host.rb +++ /dev/null @@ -1,47 +0,0 @@ -# Extensions namespace -module Middleman::Extensions - - # Asset Host module - module AssetHost - - # Setup extension - class << self - - # Once registered - def registered(app) - # Default to no host - app.set :asset_host, false - - # Include methods - app.send :include, InstanceMethods - end - - alias :included :registered - end - - # Asset Host Instance Methods - module InstanceMethods - - # Override default asset url helper to include asset hosts - # - # @param [String] path - # @param [String] prefix - # @return [String] - def asset_url(path, prefix="") - original_output = super - return original_output unless asset_host - - asset_prefix = if asset_host.is_a?(Proc) - asset_host.call(original_output) - elsif asset_host.is_a?(String) - asset_host - end - - File.join(asset_prefix, original_output) - end - end - end - - # Register the extension - register :asset_host, AssetHost -end \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb b/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb deleted file mode 100755 index a31cf140..00000000 --- a/middleman-core/lib/middleman-core/extensions/automatic_image_sizes.rb +++ /dev/null @@ -1,57 +0,0 @@ -# Extensions namespace -module Middleman::Extensions - - # Automatic Image Sizes extension - module AutomaticImageSizes - - # Setup extension - class << self - - # Once registered - def registered(app) - # Include 3rd-party fastimage library - require "middleman-core/extensions/automatic_image_sizes/fastimage" - - # Include methods - app.send :include, InstanceMethods - end - - alias :included :registered - end - - # Automatic Image Sizes Instance Methods - module InstanceMethods - - # Override default image_tag helper to automatically calculate and include - # image dimensions. - # - # @param [String] path - # @param [Hash] params - # @return [String] - def image_tag(path, params={}) - if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://") - params[:alt] ||= "" - http_prefix = http_images_path rescue images_dir - - begin - real_path = File.join(source, images_dir, path) - full_path = File.expand_path(real_path, root) - http_prefix = http_images_path rescue images_dir - if File.exists? full_path - dimensions = ::FastImage.size(full_path, :raise_on_failure => true) - params[:width] = dimensions[0] - params[:height] = dimensions[1] - end - rescue - # $stderr.puts params.inspect - end - end - - super(path, params) - end - end - end - - # Register the extension - register :automatic_image_sizes, AutomaticImageSizes -end \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/extensions/directory_indexes.rb b/middleman-core/lib/middleman-core/extensions/directory_indexes.rb deleted file mode 100644 index 78822ebd..00000000 --- a/middleman-core/lib/middleman-core/extensions/directory_indexes.rb +++ /dev/null @@ -1,54 +0,0 @@ -# Extensions namespace -module Middleman::Extensions - - # Directory Indexes extension - module DirectoryIndexes - - # Setup extension - class << self - - # Once registered - def registered(app) - app.ready do - sitemap.register_resource_list_manipulator( - :directory_indexes, - DirectoryIndexManager.new(self) - ) - end - end - - alias :included :registered - end - - class DirectoryIndexManager - def initialize(app) - @app = app - end - - # Update the main sitemap resource list - # @return [void] - def manipulate_resource_list(resources) - index_file = @app.index_file - new_index_path = "/#{index_file}" - - resources.each do |resource| - # Check if it would be pointless to reroute - next if resource.path == index_file || - resource.path.end_with?(new_index_path) || - File.extname(index_file) != resource.ext - - # Check if frontmatter turns directory_index off - d = resource.data - next if d && d["directory_index"] == false - - # Check if file metadata (options set by "page" in config.rb) turns directory_index off - if resource.metadata[:options] && resource.metadata[:options][:directory_index] == false - next - end - - resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path - end - end - end - end -end diff --git a/middleman-core/lib/middleman-core/extensions/lorem.rb b/middleman-core/lib/middleman-core/extensions/lorem.rb deleted file mode 100644 index 418d7bfc..00000000 --- a/middleman-core/lib/middleman-core/extensions/lorem.rb +++ /dev/null @@ -1,195 +0,0 @@ -# Extension namespace -module Middleman::Extensions - - # Lorem helper - module Lorem - - # Setup extension - class << self - - # Once registered - def registered(app) - # Include methods - app.send :include, InstanceMethods - end - - alias :included :registered - end - - # Lorem extension instance methods - module InstanceMethods - # Access to the Lorem object - # @return [Middleman::Extensions::Lorem::LoremObject] - def lorem - @_lorem ||= LoremObject.new - end - - # Return a placeholder image using placekitten.com - # - # @param [String] size - # @param [Hash] options - # @return [String] - def placekitten(size, options={}) - options[:domain] = "http://placekitten.com" - lorem.image(size, options) - end - end - - # Adapted from Frank: - # https://github.com/blahed/frank/ - # Copyright (c) 2010 Travis Dunn - # - # Permission is hereby granted, free of charge, to any person - # obtaining a copy of this software and associated documentation - # files (the "Software"), to deal in the Software without - # restriction, including without limitation the rights to use, - # copy, modify, merge, publish, distribute, sublicense, and/or sell - # copies of the Software, and to permit persons to whom the - # Software is furnished to do so, subject to the following - # conditions: - # - # The above copyright notice and this permission notice shall be - # included in all copies or substantial portions of the Software. - # - # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - # OTHER DEALINGS IN THE SOFTWARE. - class LoremObject - # Words for use in lorem text - WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat) - - # Get one placeholder word - # @return [String] - def word - words(1) - end - - # Get some number of placeholder words - # @param [Fixnum] total - # @return [String] - def words(total) - (1..total).map do - randm(WORDS) - end.join(' ') - end - - # Get one placeholder sentence - # @return [String] - def sentence - sentences(1) - end - - # Get some number of placeholder sentences - # @param [Fixnum] total - # @return [String] - def sentences(total) - (1..total).map do - words(randm(4..15)).capitalize - end.join('. ') - end - - # Get one placeholder paragraph - # @return [String] - def paragraph - paragraphs(1) - end - - # Get some number of placeholder paragraphs - # @param [Fixnum] total - # @return [String] - def paragraphs(total) - (1..total).map do - sentences(randm(3..7)).capitalize - end.join("\n\n") - end - - # Get a placeholder date - # @param [String] fmt - # @return [String] - def date(fmt = '%a %b %d, %Y') - y = rand(20) + 1990 - m = rand(12) + 1 - d = rand(31) + 1 - Time.local(y,m,d).strftime(fmt) - end - - # Get a placeholder name - # @return [String] - def name - "#{first_name} #{last_name}" - end - - # Get a placeholder first name - # @return [String] - def first_name - names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ") - names[rand(names.size)] - end - - # Get a placeholder last name - # @return [String] - def last_name - names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ") - names[rand(names.size)] - end - - # Get a placeholder 140 character tweet about Philip the Purple Otter - # Via http://www.kevadamson.com/talking-of-design/article/140-alternative-characters-to-lorem-ipsum - # @return [String] - def tweet - tweets = [ 'Far away, in a forest next to a river beneath the mountains, there lived a small purple otter called Philip. Philip likes sausages. The End.', - 'He liked the quality sausages from Marks & Spencer but due to the recession he had been forced to shop in a less desirable supermarket. End.', - 'He awoke one day to find his pile of sausages missing. Roger the greedy boar with human eyes, had skateboarded into the forest & eaten them!'] - tweets[rand(tweets.size)] - end - - # Get a placeholder email address - # @return [String] - def email - delimiters = [ '_', '-', '' ] - domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com) - username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)]) - "#{username}@#{domains[rand(domains.size)]}".downcase - end - - # Get a placeholder image, using placehold.it by default - # @param [String] size - # @param [Hash] options - # @return [String] - def image(size, options={}) - domain = options[:domain] || "http://placehold.it" - src = "#{domain}/#{size}" - hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9] - background_color = options[:background_color] - color = options[:color] - - if options[:random_color] - background_color = hex.shuffle[0...6].join - color = hex.shuffle[0...6].join - end - - src << "/#{background_color.sub(/^#/, '')}" if background_color - src << "/ccc" if background_color.nil? && color - src << "/#{color.sub(/^#/, '')}" if color - src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text] - - src - end - - private - - # Pick a random item from a given range - # @param [Range] range - # @return [Object] - def randm(range) - a = range.to_a - a[rand(a.length)] - end - end - end -end \ No newline at end of file diff --git a/middleman-core/features/asset_host.feature b/middleman-more/features/asset_host.feature similarity index 100% rename from middleman-core/features/asset_host.feature rename to middleman-more/features/asset_host.feature diff --git a/middleman-core/features/automatic_image_sizes.feature b/middleman-more/features/automatic_image_sizes.feature similarity index 100% rename from middleman-core/features/automatic_image_sizes.feature rename to middleman-more/features/automatic_image_sizes.feature diff --git a/middleman-more/features/clean_build.feature b/middleman-more/features/clean_build.feature new file mode 100644 index 00000000..f9ef15dc --- /dev/null +++ b/middleman-more/features/clean_build.feature @@ -0,0 +1,14 @@ +Feature: Build Clean + + Scenario: Clean an app with directory indexes + Given a successfully built app at "clean-dir-app" + Then the following files should exist: + | build/about/index.html | + Given a successfully built app at "clean-dir-app" with flags "--clean" + Then the following files should exist: + | build/about/index.html | + + Scenario: Clean build an app that's never been built + Given a successfully built app at "clean-dir-app" with flags "--clean" + Then the following files should exist: + | build/about/index.html | \ No newline at end of file diff --git a/middleman-core/features/directory_index.feature b/middleman-more/features/directory_index.feature similarity index 100% rename from middleman-core/features/directory_index.feature rename to middleman-more/features/directory_index.feature diff --git a/middleman-more/features/extensionless_text_files.feature b/middleman-more/features/extensionless_text_files.feature new file mode 100644 index 00000000..f5bc4921 --- /dev/null +++ b/middleman-more/features/extensionless_text_files.feature @@ -0,0 +1,28 @@ +Feature: Text Files Without Extensions Should Build and Preview + + Scenario: Building Text Files with directory indexes + Given a successfully built app at "extensionless-text-files-app" + When I cd to "build" + Then the following files should exist: + | CNAME | + | LICENSE | + | README | + Then the following files should not exist: + | CNAME/index.html | + | LICENSE/index.html | + | README/index.html | + + Scenario: Previewing Text Files + Given the Server is running at "extensionless-text-files-app" + When I go to "/CNAME" + Then I should see "test.github.com" + When I go to "/LICENSE" + Then I should see "You have the right to remain classy." + When I go to "/README" + Then I should see "Bork bork bork" + # When I go to "/CNAME/index.html" + # Then I should see "File Not Found" + # When I go to "/LICENSE/index.html" + # Then I should see "File Not Found" + # When I go to "/README/index.html" + # Then I should see "File Not Found" \ No newline at end of file diff --git a/middleman-more/features/frontmatter_page_settings.feature b/middleman-more/features/frontmatter_page_settings.feature new file mode 100644 index 00000000..f198ea3b --- /dev/null +++ b/middleman-more/features/frontmatter_page_settings.feature @@ -0,0 +1,42 @@ +Feature: Setting page settings through frontmatter + Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (build) + Given a successfully built app at "frontmatter-settings-app" + Then the following files should exist: + | build/proxied/index.html | + | build/no_index.html | + And the file "build/alternate_layout/index.html" should contain "Alternate layout" + And the following files should not exist: + | build/ignored/index.html | + | build/no_index/index.html | + + + Scenario: Setting layout, ignoring, and disabling directory indexes through frontmatter (preview) + Given the Server is running at "frontmatter-settings-app" + # When I go to "/proxied/" + # Then I should not see "File Not Found" + When I go to "/no_index.html" + Then I should not see "File Not Found" + When I go to "/alternate_layout/" + Then I should not see "File Not Found" + And I should see "Alternate layout" + When I go to "/ignored.html" + Then I should see "File Not Found" + When I go to "/ignored/index.html" + Then I should see "File Not Found" + When I go to "/no_index/index.html" + Then I should see "File Not Found" + + Scenario: Changing frontmatter in preview server + Given the Server is running at "frontmatter-settings-app" + When I go to "/ignored/index.html" + Then I should see "File Not Found" + And the file "source/ignored.html.erb" has the contents + """ + --- + ignored: false + --- + + This file is no longer ignored. + """ + When I go to "/ignored/index.html" + Then I should see "This file is no longer ignored." \ No newline at end of file diff --git a/middleman-core/features/helpers_lorem.feature b/middleman-more/features/helpers_lorem.feature similarity index 100% rename from middleman-core/features/helpers_lorem.feature rename to middleman-more/features/helpers_lorem.feature diff --git a/middleman-more/features/helpers_relative_link_to.feature b/middleman-more/features/helpers_relative_link_to.feature new file mode 100644 index 00000000..dde87d3a --- /dev/null +++ b/middleman-more/features/helpers_relative_link_to.feature @@ -0,0 +1,21 @@ +Feature: relative_link_to helper + + Scenario: relative_link_to knows about directory indexes + Given a fixture app "indexable-app" + And a file named "source/link_to.html.erb" with: + """ + absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %> + relative: <%= link_to "Relative", "needs_index.html", :relative => true %> + """ + And a file named "source/link_to/sub.html.erb" with: + """ + absolute: <%= link_to "Needs Index", "/needs_index.html", :relative => true %> + relative: <%= link_to "Relative", "../needs_index.html", :relative => true %> + """ + And the Server is running at "indexable-app" + When I go to "/link_to/" + Then I should see 'absolute: Needs Index' + Then I should see 'relative: Relative' + When I go to "/link_to/sub/" + Then I should see 'absolute: Needs Index' + Then I should see 'relative: Relative' \ No newline at end of file diff --git a/middleman-more/features/ignore.feature b/middleman-more/features/ignore.feature new file mode 100644 index 00000000..b4d920ac --- /dev/null +++ b/middleman-more/features/ignore.feature @@ -0,0 +1,62 @@ +Feature: Ignoring paths + Scenario: Ignore with directory indexes (source file, build) + Given a fixture app "ignore-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + ignore 'about.html.erb' + ignore 'plain.html' + """ + And a successfully built app at "ignore-app" + Then the following files should exist: + | build/index.html | + And the following files should not exist: + | build/about/index.html | + | build/plain/index.html | + + Scenario: Ignore with directory indexes (source file, server) + Given a fixture app "ignore-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + ignore 'about.html.erb' + ignore 'plain.html' + """ + And the Server is running + When I go to "/index.html" + Then I should not see "File Not Found" + When I go to "/about/index.html" + Then I should see "File Not Found" + When I go to "/plain/index.html" + Then I should see "File Not Found" + + Scenario: Ignore with directory indexes (output path splat, build) + Given a fixture app "ignore-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + ignore 'about*' + ignore 'plain*' + """ + And a successfully built app at "ignore-app" + Then the following files should exist: + | build/index.html | + And the following files should not exist: + | build/about/index.html | + | build/plain/index.html | + + Scenario: Ignore with directory indexes (output path splat, server) + Given a fixture app "ignore-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + ignore 'about*' + ignore 'plain*' + """ + And the Server is running + When I go to "/index.html" + Then I should not see "File Not Found" + When I go to "/about/index.html" + Then I should see "File Not Found" + When I go to "/plain/index.html" + Then I should see "File Not Found" \ No newline at end of file diff --git a/middleman-more/features/sitemap_traversal.feature b/middleman-more/features/sitemap_traversal.feature new file mode 100644 index 00000000..d6e94637 --- /dev/null +++ b/middleman-more/features/sitemap_traversal.feature @@ -0,0 +1,73 @@ +Feature: Step through sitemap as a tree + + Scenario: Root + Given the Server is running at "traversal-app" + When I go to "/index.html" + Then I should see "Path: index.html" + Then I should not see "Parent: index.html" + Then I should see "Child: sub/index.html" + Then I should see "Child: root.html" + Then I should not see "Child: proxied.html" + + Scenario: Directories have children and a parent + Given the Server is running at "traversal-app" + When I go to "/sub/index.html" + Then I should see "Path: sub/index.html" + Then I should see "Parent: index.html" + Then I should see "Child: sub/fake.html" + Then I should see "Child: sub/fake2.html" + Then I should see "Child: sub/sibling.html" + Then I should see "Child: sub/sibling2.html" + Then I should see "Child: sub/sub2/index.html" + Then I should see "Sibling: root.html" + + Scenario: Directory accessed without index.html + Given the Server is running at "traversal-app" + When I go to "/sub/" + Then I should see "Path: sub/index.html" + Then I should see "Parent: index.html" + Then I should see "Child: sub/fake.html" + Then I should see "Child: sub/fake2.html" + Then I should see "Child: sub/sibling.html" + Then I should see "Child: sub/sibling2.html" + Then I should see "Child: sub/sub2/index.html" + Then I should see "Sibling: root.html" + + Scenario: Page has siblings, parent, and source file + Given the Server is running at "traversal-app" + When I go to "/sub/sibling/" + Then I should see "Parent: sub/index.html" + Then I should see "Sibling: sub/fake.html" + Then I should see "Sibling: sub/fake2.html" + Then I should see "Sibling: sub/sibling2.html" + Then I should see "Sibling: sub/sub2/index.html" + Then I should see "Source: source/sub/sibling.html.erb" + + Scenario: Proxied page has siblings, parent, and source file + Given the Server is running at "traversal-app" + When I go to "/sub/fake/" + Then I should see "Path: sub/fake.html" + Then I should see "Parent: sub/index.html" + Then I should see "Sibling: sub/fake2.html" + Then I should see "Sibling: sub/sibling.html" + Then I should see "Sibling: sub/sibling2.html" + Then I should see "Sibling: sub/sub2/index.html" + Then I should see "Source: source/proxied.html.erb" + + Scenario: Child pages have data + Given the Server is running at "traversal-app" + When I go to "/directory-indexed" + Then I should see "Title of Sibling One" + Then I should see "Title of Sibling Two" + + Scenario: When directory_index extension is active, child pages are found in named directory + Given the Server is running at "traversal-app" + When I go to "/directory-indexed" + Then I should see "Path: directory-indexed.html" + Then I should see "Parent: index.html" + Then I should see "Child: directory-indexed/fake.html" + Then I should see "Child: directory-indexed/fake2.html" + Then I should see "Child: directory-indexed/sibling.html" + Then I should see "Child: directory-indexed/sibling2.html" + Then I should see "Child: directory-indexed/sub2/index.html" + Then I should see "Sibling: root.html" diff --git a/middleman-more/features/wildcard_page_helper.feature b/middleman-more/features/wildcard_page_helper.feature new file mode 100644 index 00000000..caf056f6 --- /dev/null +++ b/middleman-more/features/wildcard_page_helper.feature @@ -0,0 +1,10 @@ +Feature: Wildcards in Page helper + + Scenario: Setting the layout for a folder + Given the Server is running at "wildcard-directory-index-app" + When I go to "/" + Then I should see "Normal Layout" + When I go to "/admin/" + Then I should see "Admin Layout" + When I go to "/admin/page/" + Then I should see "Admin Layout" \ No newline at end of file diff --git a/middleman-core/fixtures/asset-host-app/source/asset_host.html.erb b/middleman-more/fixtures/asset-host-app/source/asset_host.html.erb similarity index 100% rename from middleman-core/fixtures/asset-host-app/source/asset_host.html.erb rename to middleman-more/fixtures/asset-host-app/source/asset_host.html.erb diff --git a/middleman-core/fixtures/automatic-image-size-app/config.rb b/middleman-more/fixtures/automatic-image-size-app/config.rb similarity index 100% rename from middleman-core/fixtures/automatic-image-size-app/config.rb rename to middleman-more/fixtures/automatic-image-size-app/config.rb diff --git a/middleman-core/fixtures/automatic-image-size-app/source/auto-image-sizes.html.erb b/middleman-more/fixtures/automatic-image-size-app/source/auto-image-sizes.html.erb similarity index 100% rename from middleman-core/fixtures/automatic-image-size-app/source/auto-image-sizes.html.erb rename to middleman-more/fixtures/automatic-image-size-app/source/auto-image-sizes.html.erb diff --git a/middleman-core/fixtures/asset-host-app/source/images/blank.gif b/middleman-more/fixtures/automatic-image-size-app/source/images/blank.gif similarity index 100% rename from middleman-core/fixtures/asset-host-app/source/images/blank.gif rename to middleman-more/fixtures/automatic-image-size-app/source/images/blank.gif diff --git a/middleman-core/fixtures/clean-dir-app/config.rb b/middleman-more/fixtures/clean-dir-app/config.rb similarity index 100% rename from middleman-core/fixtures/clean-dir-app/config.rb rename to middleman-more/fixtures/clean-dir-app/config.rb diff --git a/middleman-core/fixtures/clean-dir-app/source/about.html b/middleman-more/fixtures/clean-dir-app/source/about.html similarity index 100% rename from middleman-core/fixtures/clean-dir-app/source/about.html rename to middleman-more/fixtures/clean-dir-app/source/about.html diff --git a/middleman-more/fixtures/extensionless-text-files-app/config.rb b/middleman-more/fixtures/extensionless-text-files-app/config.rb new file mode 100644 index 00000000..f343b291 --- /dev/null +++ b/middleman-more/fixtures/extensionless-text-files-app/config.rb @@ -0,0 +1 @@ +activate :directory_indexes \ No newline at end of file diff --git a/middleman-more/fixtures/extensionless-text-files-app/source/CNAME b/middleman-more/fixtures/extensionless-text-files-app/source/CNAME new file mode 100644 index 00000000..c8dc4813 --- /dev/null +++ b/middleman-more/fixtures/extensionless-text-files-app/source/CNAME @@ -0,0 +1 @@ +test.github.com \ No newline at end of file diff --git a/middleman-more/fixtures/extensionless-text-files-app/source/LICENSE b/middleman-more/fixtures/extensionless-text-files-app/source/LICENSE new file mode 100644 index 00000000..8bf82c48 --- /dev/null +++ b/middleman-more/fixtures/extensionless-text-files-app/source/LICENSE @@ -0,0 +1 @@ +You have the right to remain classy. \ No newline at end of file diff --git a/middleman-more/fixtures/extensionless-text-files-app/source/README b/middleman-more/fixtures/extensionless-text-files-app/source/README new file mode 100644 index 00000000..44c2bac0 --- /dev/null +++ b/middleman-more/fixtures/extensionless-text-files-app/source/README @@ -0,0 +1 @@ +Bork bork bork \ No newline at end of file diff --git a/middleman-more/fixtures/extensionless-text-files-app/source/index.html b/middleman-more/fixtures/extensionless-text-files-app/source/index.html new file mode 100644 index 00000000..0b90e2b8 --- /dev/null +++ b/middleman-more/fixtures/extensionless-text-files-app/source/index.html @@ -0,0 +1 @@ +sup \ No newline at end of file diff --git a/middleman-more/fixtures/frontmatter-settings-app/config.rb b/middleman-more/fixtures/frontmatter-settings-app/config.rb new file mode 100644 index 00000000..3c393758 --- /dev/null +++ b/middleman-more/fixtures/frontmatter-settings-app/config.rb @@ -0,0 +1,4 @@ +activate :directory_indexes + +# Proxy ignored.html, which should ignore itself through a frontmatter +page 'proxied.html', :proxy => 'ignored.html' diff --git a/middleman-more/fixtures/frontmatter-settings-app/source/alternate_layout.html.erb b/middleman-more/fixtures/frontmatter-settings-app/source/alternate_layout.html.erb new file mode 100644 index 00000000..c385be0d --- /dev/null +++ b/middleman-more/fixtures/frontmatter-settings-app/source/alternate_layout.html.erb @@ -0,0 +1,5 @@ +--- +layout: alternate +--- + +This uses an alternate layout diff --git a/middleman-more/fixtures/frontmatter-settings-app/source/ignored.html.erb b/middleman-more/fixtures/frontmatter-settings-app/source/ignored.html.erb new file mode 100644 index 00000000..a2c04fe3 --- /dev/null +++ b/middleman-more/fixtures/frontmatter-settings-app/source/ignored.html.erb @@ -0,0 +1,5 @@ +--- +ignored: true +--- + +This file ignores itself! But it can still be proxied. diff --git a/middleman-more/fixtures/frontmatter-settings-app/source/layouts/alternate.erb b/middleman-more/fixtures/frontmatter-settings-app/source/layouts/alternate.erb new file mode 100644 index 00000000..a38f2d07 --- /dev/null +++ b/middleman-more/fixtures/frontmatter-settings-app/source/layouts/alternate.erb @@ -0,0 +1,3 @@ +Alternate layout! + +<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/frontmatter-settings-app/source/no_index.html.erb b/middleman-more/fixtures/frontmatter-settings-app/source/no_index.html.erb similarity index 100% rename from middleman-core/fixtures/frontmatter-settings-app/source/no_index.html.erb rename to middleman-more/fixtures/frontmatter-settings-app/source/no_index.html.erb diff --git a/middleman-more/fixtures/ignore-app/source/about.html.erb b/middleman-more/fixtures/ignore-app/source/about.html.erb new file mode 100644 index 00000000..ae21d833 --- /dev/null +++ b/middleman-more/fixtures/ignore-app/source/about.html.erb @@ -0,0 +1 @@ +About \ No newline at end of file diff --git a/middleman-more/fixtures/ignore-app/source/images/icon/messages.png b/middleman-more/fixtures/ignore-app/source/images/icon/messages.png new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/ignore-app/source/images/pic.png b/middleman-more/fixtures/ignore-app/source/images/pic.png new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/ignore-app/source/images/portrait.jpg b/middleman-more/fixtures/ignore-app/source/images/portrait.jpg new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/ignore-app/source/index.html.erb b/middleman-more/fixtures/ignore-app/source/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/ignore-app/source/plain.html b/middleman-more/fixtures/ignore-app/source/plain.html new file mode 100644 index 00000000..4061eab2 --- /dev/null +++ b/middleman-more/fixtures/ignore-app/source/plain.html @@ -0,0 +1 @@ +Plain \ No newline at end of file diff --git a/middleman-more/fixtures/ignore-app/source/reports/another.html b/middleman-more/fixtures/ignore-app/source/reports/another.html new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/ignore-app/source/reports/index.html b/middleman-more/fixtures/ignore-app/source/reports/index.html new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/indexable-app/config.rb b/middleman-more/fixtures/indexable-app/config.rb new file mode 100644 index 00000000..54b79b5c --- /dev/null +++ b/middleman-more/fixtures/indexable-app/config.rb @@ -0,0 +1,4 @@ +activate :directory_indexes +page "/leave_me_alone.html", :directory_index => false + +page "/wildcard*", :directory_index => false diff --git a/middleman-core/fixtures/asset-host-app/source/.htaccess b/middleman-more/fixtures/indexable-app/source/.htaccess similarity index 100% rename from middleman-core/fixtures/asset-host-app/source/.htaccess rename to middleman-more/fixtures/indexable-app/source/.htaccess diff --git a/middleman-more/fixtures/indexable-app/source/a_folder/needs_index.html b/middleman-more/fixtures/indexable-app/source/a_folder/needs_index.html new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/middleman-more/fixtures/indexable-app/source/a_folder/needs_index.html @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/middleman-more/fixtures/indexable-app/source/leave_me_alone.html b/middleman-more/fixtures/indexable-app/source/leave_me_alone.html new file mode 100644 index 00000000..163cebf8 --- /dev/null +++ b/middleman-more/fixtures/indexable-app/source/leave_me_alone.html @@ -0,0 +1 @@ +Stay away \ No newline at end of file diff --git a/middleman-more/fixtures/indexable-app/source/needs_index.html b/middleman-more/fixtures/indexable-app/source/needs_index.html new file mode 100644 index 00000000..1eeec11b --- /dev/null +++ b/middleman-more/fixtures/indexable-app/source/needs_index.html @@ -0,0 +1 @@ +Indexable \ No newline at end of file diff --git a/middleman-more/fixtures/indexable-app/source/regular/index.html b/middleman-more/fixtures/indexable-app/source/regular/index.html new file mode 100644 index 00000000..ea9503c0 --- /dev/null +++ b/middleman-more/fixtures/indexable-app/source/regular/index.html @@ -0,0 +1 @@ +Regular \ No newline at end of file diff --git a/middleman-more/fixtures/indexable-app/source/wildcard_leave_me_alone.html b/middleman-more/fixtures/indexable-app/source/wildcard_leave_me_alone.html new file mode 100644 index 00000000..5ff5317a --- /dev/null +++ b/middleman-more/fixtures/indexable-app/source/wildcard_leave_me_alone.html @@ -0,0 +1 @@ +Stay away, wildcards! diff --git a/middleman-core/fixtures/lorem-app/config.rb b/middleman-more/fixtures/lorem-app/config.rb similarity index 100% rename from middleman-core/fixtures/lorem-app/config.rb rename to middleman-more/fixtures/lorem-app/config.rb diff --git a/middleman-core/fixtures/lorem-app/source/lorem.html.erb b/middleman-more/fixtures/lorem-app/source/lorem.html.erb similarity index 100% rename from middleman-core/fixtures/lorem-app/source/lorem.html.erb rename to middleman-more/fixtures/lorem-app/source/lorem.html.erb diff --git a/middleman-more/fixtures/traversal-app/config.rb b/middleman-more/fixtures/traversal-app/config.rb new file mode 100644 index 00000000..6d1883c4 --- /dev/null +++ b/middleman-more/fixtures/traversal-app/config.rb @@ -0,0 +1,7 @@ +activate :directory_indexes + +page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true +page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true + +page "/directory-indexed/fake.html", :proxy => "/proxied.html", :ignore => true +page "/directory-indexed/fake2.html", :proxy => "/proxied.html", :ignore => true \ No newline at end of file diff --git a/middleman-more/fixtures/traversal-app/source/directory-indexed.html.erb b/middleman-more/fixtures/traversal-app/source/directory-indexed.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/directory-indexed/sibling.html.erb b/middleman-more/fixtures/traversal-app/source/directory-indexed/sibling.html.erb new file mode 100644 index 00000000..03491028 --- /dev/null +++ b/middleman-more/fixtures/traversal-app/source/directory-indexed/sibling.html.erb @@ -0,0 +1,3 @@ +--- +title: Title of Sibling One +--- \ No newline at end of file diff --git a/middleman-more/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb b/middleman-more/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb new file mode 100644 index 00000000..350f799d --- /dev/null +++ b/middleman-more/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb @@ -0,0 +1,3 @@ +--- +title: Title of Sibling Two +--- \ No newline at end of file diff --git a/middleman-more/fixtures/traversal-app/source/directory-indexed/sub2/index.html.erb b/middleman-more/fixtures/traversal-app/source/directory-indexed/sub2/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/directory-indexed/sub3/deep.html.erb b/middleman-more/fixtures/traversal-app/source/directory-indexed/sub3/deep.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/index.html.erb b/middleman-more/fixtures/traversal-app/source/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/layout.erb b/middleman-more/fixtures/traversal-app/source/layout.erb new file mode 100644 index 00000000..8725e85f --- /dev/null +++ b/middleman-more/fixtures/traversal-app/source/layout.erb @@ -0,0 +1,21 @@ +Path: <%= current_page.path %> + +Source: <%= current_page.source_file.sub(root + "/", "") %> + +<% if current_page.parent %> + Parent: <%= current_page.parent.path %> +<% end %> + +<% current_page.children.each do |p| %> + Child: <%= p.path %> +<% end %> + +<% current_page.siblings.each do |p| %> + Sibling: <%= p.path %> +<% end %> + +<% current_page.children.each do |p| %> + <% if p.data %> + Data: <%= p.data %> + <% end %> +<% end %> \ No newline at end of file diff --git a/middleman-more/fixtures/traversal-app/source/proxied.html.erb b/middleman-more/fixtures/traversal-app/source/proxied.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/root.html.erb b/middleman-more/fixtures/traversal-app/source/root.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/sub/index.html.erb b/middleman-more/fixtures/traversal-app/source/sub/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/sub/sibling.html.erb b/middleman-more/fixtures/traversal-app/source/sub/sibling.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/sub/sibling2.html.erb b/middleman-more/fixtures/traversal-app/source/sub/sibling2.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/sub/sub2/index.html.erb b/middleman-more/fixtures/traversal-app/source/sub/sub2/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-more/fixtures/traversal-app/source/sub/sub3/deep.html.erb b/middleman-more/fixtures/traversal-app/source/sub/sub3/deep.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/fixtures/wildcard-directory-index-app/config.rb b/middleman-more/fixtures/wildcard-directory-index-app/config.rb similarity index 100% rename from middleman-core/fixtures/wildcard-directory-index-app/config.rb rename to middleman-more/fixtures/wildcard-directory-index-app/config.rb diff --git a/middleman-core/fixtures/wildcard-directory-index-app/source/admin/index.html.erb b/middleman-more/fixtures/wildcard-directory-index-app/source/admin/index.html.erb similarity index 100% rename from middleman-core/fixtures/wildcard-directory-index-app/source/admin/index.html.erb rename to middleman-more/fixtures/wildcard-directory-index-app/source/admin/index.html.erb diff --git a/middleman-core/fixtures/wildcard-directory-index-app/source/admin/page.html.erb b/middleman-more/fixtures/wildcard-directory-index-app/source/admin/page.html.erb similarity index 100% rename from middleman-core/fixtures/wildcard-directory-index-app/source/admin/page.html.erb rename to middleman-more/fixtures/wildcard-directory-index-app/source/admin/page.html.erb diff --git a/middleman-core/fixtures/wildcard-directory-index-app/source/index.html.erb b/middleman-more/fixtures/wildcard-directory-index-app/source/index.html.erb similarity index 100% rename from middleman-core/fixtures/wildcard-directory-index-app/source/index.html.erb rename to middleman-more/fixtures/wildcard-directory-index-app/source/index.html.erb diff --git a/middleman-core/fixtures/wildcard-directory-index-app/source/layouts/admin.erb b/middleman-more/fixtures/wildcard-directory-index-app/source/layouts/admin.erb similarity index 100% rename from middleman-core/fixtures/wildcard-directory-index-app/source/layouts/admin.erb rename to middleman-more/fixtures/wildcard-directory-index-app/source/layouts/admin.erb diff --git a/middleman-core/fixtures/wildcard-directory-index-app/source/layouts/layout.erb b/middleman-more/fixtures/wildcard-directory-index-app/source/layouts/layout.erb similarity index 100% rename from middleman-core/fixtures/wildcard-directory-index-app/source/layouts/layout.erb rename to middleman-more/fixtures/wildcard-directory-index-app/source/layouts/layout.erb diff --git a/middleman-more/lib/middleman-more.rb b/middleman-more/lib/middleman-more.rb index 06a55b29..18fe42f5 100644 --- a/middleman-more/lib/middleman-more.rb +++ b/middleman-more/lib/middleman-more.rb @@ -1,6 +1,127 @@ +require "middleman-core" + # Setup our load paths libdir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) -require "middleman-core" -require "middleman-more/register_extensions" \ No newline at end of file +module Middleman::More + + # Setup extension + class << self + + # Once registered + def registered(app, options={}) + ### + # Setup renderers + ### + + # CoffeeScript Support + require "middleman-more/renderers/coffee_script" + Middleman::Application.register Middleman::Renderers::CoffeeScript + + # Haml Support + require "middleman-more/renderers/haml" + Middleman::Application.register Middleman::Renderers::Haml + + # Sass Support + require "middleman-more/renderers/sass" + Middleman::Application.register Middleman::Renderers::Sass + + # Markdown Support + require "middleman-more/renderers/markdown" + Middleman::Application.register Middleman::Renderers::Markdown + + # Liquid Support + require "middleman-more/renderers/liquid" + Middleman::Application.register Middleman::Renderers::Liquid + + # Slim Support + require "middleman-more/renderers/slim" + Middleman::Application.register Middleman::Renderers::Slim + + ### + # Setup Core Extensions + ### + + # Compass framework + require "middleman-more/core_extensions/compass" + Middleman::Application.register Middleman::CoreExtensions::Compass + + # Sprockets asset handling + require "middleman-more/core_extensions/sprockets" + Middleman::Application.register Middleman::CoreExtensions::Sprockets + + ### + # Setup Optional Extensions + ### + + # CacheBuster adds a query string to assets in dynamic templates to avoid + # browser caches failing to update to your new content. + Middleman::Extensions.register(:cache_buster) do + require "middleman-more/extensions/cache_buster" + Middleman::Extensions::CacheBuster + end + + # MinifyCss compresses CSS + Middleman::Extensions.register(:minify_css) do + require "middleman-more/extensions/minify_css" + Middleman::Extensions::MinifyCss + end + + # MinifyJavascript compresses JS + Middleman::Extensions.register(:minify_javascript) do + require "middleman-more/extensions/minify_javascript" + Middleman::Extensions::MinifyJavascript + end + + # RelativeAssets allow any asset path in dynamic templates to be either + # relative to the root of the project or use an absolute URL. + Middleman::Extensions.register(:relative_assets) do + require "middleman-more/extensions/relative_assets" + Middleman::Extensions::RelativeAssets + end + + # GZIP assets and pages during build + Middleman::Extensions.register(:gzip) do + require "middleman-more/extensions/gzip" + Middleman::Extensions::Gzip + end + + # AssetHash appends a hash of the file contents to the assets filename + # to avoid browser caches failing to update to your new content. + Middleman::Extensions.register(:asset_hash) do + require "middleman-more/extensions/asset_hash" + Middleman::Extensions::AssetHash + end + + # AssetHost allows you to setup multiple domains to host your static + # assets. Calls to asset paths in dynamic templates will then rotate + # through each of the asset servers to better spread the load. + Middleman::Extensions.register(:asset_host) do + require "middleman-more/extensions/asset_host" + Middleman::Extensions::AssetHost + end + + # Provide Apache-style index.html files for directories + Middleman::Extensions.register(:directory_indexes) do + require "middleman-more/extensions/directory_indexes" + Middleman::Extensions::DirectoryIndexes + end + + # Lorem provides a handful of helpful prototyping methods to generate + # words, paragraphs, fake images, names and email addresses. + require "middleman-more/extensions/lorem" + Middleman::Application.register Middleman::Extensions::Lorem + + # AutomaticImageSizes inspects the images used in your dynamic templates + # and automatically adds width and height attributes to their HTML + # elements. + Middleman::Extensions.register(:automatic_image_sizes) do + require "middleman-more/extensions/automatic_image_sizes" + Middleman::Extensions::AutomaticImageSizes + end + end + end +end + +Middleman::Application.register Middleman::More \ No newline at end of file diff --git a/middleman-more/lib/middleman-more/extensions/asset_hash.rb b/middleman-more/lib/middleman-more/extensions/asset_hash.rb index e40379e7..964963ca 100755 --- a/middleman-more/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-more/lib/middleman-more/extensions/asset_hash.rb @@ -1,106 +1,106 @@ -require 'digest/sha1' -module Middleman::Extensions - module AssetHash - class << self - def registered(app, options) - exts = options[:exts] || %w(.jpg .jpeg .png .gif .js .css) +module Middleman + module Extensions + module AssetHash + class << self + def registered(app, options) + require 'digest/sha1' + exts = options[:exts] || %w(.jpg .jpeg .png .gif .js .css) - # Allow specifying regexes to ignore, plus always ignore apple touch icons - ignore = Array(options[:ignore]) << /^apple-touch-icon/ + # Allow specifying regexes to ignore, plus always ignore apple touch icons + ignore = Array(options[:ignore]) << /^apple-touch-icon/ - app.ready do - sitemap.register_resource_list_manipulator( - :asset_hash, - AssetHashManager.new(self, exts, ignore) - ) - use Middleware, :exts => exts, :middleman_app => self + app.ready do + sitemap.register_resource_list_manipulator( + :asset_hash, + AssetHashManager.new(self, exts, ignore) + ) + use Middleware, :exts => exts, :middleman_app => self + end end + alias :included :registered end - alias :included :registered - end - class AssetHashManager - def initialize(app, exts, ignore) - @app = app - @exts = exts - @ignore = ignore - end + class AssetHashManager + def initialize(app, exts, ignore) + @app = app + @exts = exts + @ignore = ignore + end - # Update the main sitemap resource list - # @return [void] - def manipulate_resource_list(resources) - resources.each do |resource| - if @exts.include?(resource.ext) && @ignore.none? {|ignore| resource.path =~ ignore } - # figure out the path Sprockets would use for this asset - if resource.ext == '.js' - sprockets_path = resource.path.sub(@app.js_dir,'').sub(/^\//,'') - elsif resource.ext == '.css' - sprockets_path = resource.path.sub(@app.css_dir,'').sub(/^\//,'') - end - - # See if Sprockets knows about the file - asset = @app.sprockets.find_asset(sprockets_path) if sprockets_path - - if asset # if it's a Sprockets asset, ask sprockets for its digest - digest = asset.digest[0..7] - elsif resource.template? # if it's a template, render it out - digest = Digest::SHA1.hexdigest(resource.render)[0..7] - else # if it's a static file, just hash it - digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7] - end - - resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" } - end - end - end - end - - # The asset hash middleware is responsible for rewriting references to - # assets to include their new, hashed name. - class Middleware - def initialize(app, options={}) - @rack_app = app - @exts = options[:exts] - @exts_regex_text = @exts.map {|e| Regexp.escape(e) }.join('|') - @middleman_app = options[:middleman_app] - end - - def call(env) - status, headers, response = @rack_app.call(env) - - path = @middleman_app.full_path(env["PATH_INFO"]) - dirpath = Pathname.new(File.dirname(path)) - - if path =~ /(^\/$)|(\.(htm|html|php|css|js)$)/ - body = ::Middleman::Util.extract_response_text(response) - - if body - # TODO: This regex will change some paths in plan HTML (not in a tag) - is that OK? - body.gsub! /([=\'\"\(]\s*)([^\s\'\"\)]+(#{@exts_regex_text}))/ do |match| - asset_path = $2 - relative_path = Pathname.new(asset_path).relative? - - asset_path = dirpath.join(asset_path).to_s if relative_path - - if asset_page = @middleman_app.sitemap.find_resource_by_path(asset_path) - replacement_path = "/#{asset_page.destination_path}" - replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path - - "#{$1}#{replacement_path}" - else - match + # Update the main sitemap resource list + # @return [void] + def manipulate_resource_list(resources) + resources.each do |resource| + if @exts.include?(resource.ext) && @ignore.none? {|ignore| resource.path =~ ignore } + # figure out the path Sprockets would use for this asset + if resource.ext == '.js' + sprockets_path = resource.path.sub(@app.js_dir,'').sub(/^\//,'') + elsif resource.ext == '.css' + sprockets_path = resource.path.sub(@app.css_dir,'').sub(/^\//,'') end - end - status, headers, response = Rack::Response.new(body, status, headers).finish + # See if Sprockets knows about the file + asset = @app.sprockets.find_asset(sprockets_path) if sprockets_path + + if asset # if it's a Sprockets asset, ask sprockets for its digest + digest = asset.digest[0..7] + elsif resource.template? # if it's a template, render it out + digest = Digest::SHA1.hexdigest(resource.render)[0..7] + else # if it's a static file, just hash it + digest = Digest::SHA1.file(resource.source_file).hexdigest[0..7] + end + + resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" } + end end end - [status, headers, response] + end + + # The asset hash middleware is responsible for rewriting references to + # assets to include their new, hashed name. + class Middleware + def initialize(app, options={}) + @rack_app = app + @exts = options[:exts] + @exts_regex_text = @exts.map {|e| Regexp.escape(e) }.join('|') + @middleman_app = options[:middleman_app] + end + + def call(env) + status, headers, response = @rack_app.call(env) + + path = @middleman_app.full_path(env["PATH_INFO"]) + dirpath = Pathname.new(File.dirname(path)) + + if path =~ /(^\/$)|(\.(htm|html|php|css|js)$)/ + body = ::Middleman::Util.extract_response_text(response) + + if body + # TODO: This regex will change some paths in plan HTML (not in a tag) - is that OK? + body.gsub! /([=\'\"\(]\s*)([^\s\'\"\)]+(#{@exts_regex_text}))/ do |match| + asset_path = $2 + relative_path = Pathname.new(asset_path).relative? + + asset_path = dirpath.join(asset_path).to_s if relative_path + + if asset_page = @middleman_app.sitemap.find_resource_by_path(asset_path) + replacement_path = "/#{asset_page.destination_path}" + replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path + + "#{$1}#{replacement_path}" + else + match + end + end + + status, headers, response = Rack::Response.new(body, status, headers).finish + end + end + [status, headers, response] + end end end end - - register :asset_hash, AssetHash end diff --git a/middleman-more/lib/middleman-more/extensions/asset_host.rb b/middleman-more/lib/middleman-more/extensions/asset_host.rb new file mode 100644 index 00000000..770ed3c0 --- /dev/null +++ b/middleman-more/lib/middleman-more/extensions/asset_host.rb @@ -0,0 +1,46 @@ +# Extensions namespace +module Middleman + module Extensions + + # Asset Host module + module AssetHost + + # Setup extension + class << self + + # Once registered + def registered(app) + # Default to no host + app.set :asset_host, false + + # Include methods + app.send :include, InstanceMethods + end + + alias :included :registered + end + + # Asset Host Instance Methods + module InstanceMethods + + # Override default asset url helper to include asset hosts + # + # @param [String] path + # @param [String] prefix + # @return [String] + def asset_url(path, prefix="") + original_output = super + return original_output unless asset_host + + asset_prefix = if asset_host.is_a?(Proc) + asset_host.call(original_output) + elsif asset_host.is_a?(String) + asset_host + end + + File.join(asset_prefix, original_output) + end + end + end + end +end \ No newline at end of file diff --git a/middleman-more/lib/middleman-more/extensions/automatic_image_sizes.rb b/middleman-more/lib/middleman-more/extensions/automatic_image_sizes.rb new file mode 100755 index 00000000..ccc5a6c2 --- /dev/null +++ b/middleman-more/lib/middleman-more/extensions/automatic_image_sizes.rb @@ -0,0 +1,56 @@ +# Extensions namespace +module Middleman + module Extensions + + # Automatic Image Sizes extension + module AutomaticImageSizes + + # Setup extension + class << self + + # Once registered + def registered(app) + # Include 3rd-party fastimage library + require "middleman-more/extensions/automatic_image_sizes/fastimage" + + # Include methods + app.send :include, InstanceMethods + end + + alias :included :registered + end + + # Automatic Image Sizes Instance Methods + module InstanceMethods + + # Override default image_tag helper to automatically calculate and include + # image dimensions. + # + # @param [String] path + # @param [Hash] params + # @return [String] + def image_tag(path, params={}) + if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://") + params[:alt] ||= "" + http_prefix = http_images_path rescue images_dir + + begin + real_path = File.join(source, images_dir, path) + full_path = File.expand_path(real_path, root) + http_prefix = http_images_path rescue images_dir + if File.exists? full_path + dimensions = ::FastImage.size(full_path, :raise_on_failure => true) + params[:width] = dimensions[0] + params[:height] = dimensions[1] + end + rescue + # $stderr.puts params.inspect + end + end + + super(path, params) + end + end + end + end +end \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/extensions/automatic_image_sizes/fastimage.rb b/middleman-more/lib/middleman-more/extensions/automatic_image_sizes/fastimage.rb similarity index 100% rename from middleman-core/lib/middleman-core/extensions/automatic_image_sizes/fastimage.rb rename to middleman-more/lib/middleman-more/extensions/automatic_image_sizes/fastimage.rb diff --git a/middleman-more/lib/middleman-more/extensions/directory_indexes.rb b/middleman-more/lib/middleman-more/extensions/directory_indexes.rb new file mode 100644 index 00000000..373df9ec --- /dev/null +++ b/middleman-more/lib/middleman-more/extensions/directory_indexes.rb @@ -0,0 +1,56 @@ +# Extensions namespace +module Middleman + module Extensions + + # Directory Indexes extension + module DirectoryIndexes + + # Setup extension + class << self + + # Once registered + def registered(app) + app.ready do + sitemap.register_resource_list_manipulator( + :directory_indexes, + DirectoryIndexManager.new(self) + ) + end + end + + alias :included :registered + end + + class DirectoryIndexManager + def initialize(app) + @app = app + end + + # Update the main sitemap resource list + # @return [void] + def manipulate_resource_list(resources) + index_file = @app.index_file + new_index_path = "/#{index_file}" + + resources.each do |resource| + # Check if it would be pointless to reroute + next if resource.path == index_file || + resource.path.end_with?(new_index_path) || + File.extname(index_file) != resource.ext + + # Check if frontmatter turns directory_index off + d = resource.data + next if d && d["directory_index"] == false + + # Check if file metadata (options set by "page" in config.rb) turns directory_index off + if resource.metadata[:options] && resource.metadata[:options][:directory_index] == false + next + end + + resource.destination_path = resource.destination_path.chomp(File.extname(index_file)) + new_index_path + end + end + end + end + end +end \ No newline at end of file diff --git a/middleman-more/lib/middleman-more/extensions/lorem.rb b/middleman-more/lib/middleman-more/extensions/lorem.rb new file mode 100644 index 00000000..d1084898 --- /dev/null +++ b/middleman-more/lib/middleman-more/extensions/lorem.rb @@ -0,0 +1,197 @@ +# Extension namespace +module Middleman + module Extensions + + # Lorem helper + module Lorem + + # Setup extension + class << self + + # Once registered + def registered(app) + # Include methods + app.send :include, InstanceMethods + end + + alias :included :registered + end + + # Lorem extension instance methods + module InstanceMethods + # Access to the Lorem object + # @return [Middleman::Extensions::Lorem::LoremObject] + def lorem + @_lorem ||= LoremObject.new + end + + # Return a placeholder image using placekitten.com + # + # @param [String] size + # @param [Hash] options + # @return [String] + def placekitten(size, options={}) + options[:domain] = "http://placekitten.com" + lorem.image(size, options) + end + end + + # Adapted from Frank: + # https://github.com/blahed/frank/ + # Copyright (c) 2010 Travis Dunn + # + # Permission is hereby granted, free of charge, to any person + # obtaining a copy of this software and associated documentation + # files (the "Software"), to deal in the Software without + # restriction, including without limitation the rights to use, + # copy, modify, merge, publish, distribute, sublicense, and/or sell + # copies of the Software, and to permit persons to whom the + # Software is furnished to do so, subject to the following + # conditions: + # + # The above copyright notice and this permission notice shall be + # included in all copies or substantial portions of the Software. + # + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + # OTHER DEALINGS IN THE SOFTWARE. + class LoremObject + # Words for use in lorem text + WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat) + + # Get one placeholder word + # @return [String] + def word + words(1) + end + + # Get some number of placeholder words + # @param [Fixnum] total + # @return [String] + def words(total) + (1..total).map do + randm(WORDS) + end.join(' ') + end + + # Get one placeholder sentence + # @return [String] + def sentence + sentences(1) + end + + # Get some number of placeholder sentences + # @param [Fixnum] total + # @return [String] + def sentences(total) + (1..total).map do + words(randm(4..15)).capitalize + end.join('. ') + end + + # Get one placeholder paragraph + # @return [String] + def paragraph + paragraphs(1) + end + + # Get some number of placeholder paragraphs + # @param [Fixnum] total + # @return [String] + def paragraphs(total) + (1..total).map do + sentences(randm(3..7)).capitalize + end.join("\n\n") + end + + # Get a placeholder date + # @param [String] fmt + # @return [String] + def date(fmt = '%a %b %d, %Y') + y = rand(20) + 1990 + m = rand(12) + 1 + d = rand(31) + 1 + Time.local(y,m,d).strftime(fmt) + end + + # Get a placeholder name + # @return [String] + def name + "#{first_name} #{last_name}" + end + + # Get a placeholder first name + # @return [String] + def first_name + names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ") + names[rand(names.size)] + end + + # Get a placeholder last name + # @return [String] + def last_name + names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ") + names[rand(names.size)] + end + + # Get a placeholder 140 character tweet about Philip the Purple Otter + # Via http://www.kevadamson.com/talking-of-design/article/140-alternative-characters-to-lorem-ipsum + # @return [String] + def tweet + tweets = [ 'Far away, in a forest next to a river beneath the mountains, there lived a small purple otter called Philip. Philip likes sausages. The End.', + 'He liked the quality sausages from Marks & Spencer but due to the recession he had been forced to shop in a less desirable supermarket. End.', + 'He awoke one day to find his pile of sausages missing. Roger the greedy boar with human eyes, had skateboarded into the forest & eaten them!'] + tweets[rand(tweets.size)] + end + + # Get a placeholder email address + # @return [String] + def email + delimiters = [ '_', '-', '' ] + domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com) + username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)]) + "#{username}@#{domains[rand(domains.size)]}".downcase + end + + # Get a placeholder image, using placehold.it by default + # @param [String] size + # @param [Hash] options + # @return [String] + def image(size, options={}) + domain = options[:domain] || "http://placehold.it" + src = "#{domain}/#{size}" + hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9] + background_color = options[:background_color] + color = options[:color] + + if options[:random_color] + background_color = hex.shuffle[0...6].join + color = hex.shuffle[0...6].join + end + + src << "/#{background_color.sub(/^#/, '')}" if background_color + src << "/ccc" if background_color.nil? && color + src << "/#{color.sub(/^#/, '')}" if color + src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text] + + src + end + + private + + # Pick a random item from a given range + # @param [Range] range + # @return [Object] + def randm(range) + a = range.to_a + a[rand(a.length)] + end + end + end + end +end \ No newline at end of file diff --git a/middleman-more/lib/middleman-more/register_extensions.rb b/middleman-more/lib/middleman-more/register_extensions.rb deleted file mode 100644 index 25df708a..00000000 --- a/middleman-more/lib/middleman-more/register_extensions.rb +++ /dev/null @@ -1,82 +0,0 @@ -### -# Setup renderers -### - -# CoffeeScript Support -require "middleman-more/renderers/coffee_script" -Middleman::Application.register Middleman::Renderers::CoffeeScript - -# Haml Support -require "middleman-more/renderers/haml" -Middleman::Application.register Middleman::Renderers::Haml - -# Sass Support -require "middleman-more/renderers/sass" -Middleman::Application.register Middleman::Renderers::Sass - -# Markdown Support -require "middleman-more/renderers/markdown" -Middleman::Application.register Middleman::Renderers::Markdown - -# Liquid Support -require "middleman-more/renderers/liquid" -Middleman::Application.register Middleman::Renderers::Liquid - -# Slim Support -require "middleman-more/renderers/slim" -Middleman::Application.register Middleman::Renderers::Slim - -### -# Setup Core Extensions -### - -# Compass framework -require "middleman-more/core_extensions/compass" -Middleman::Application.register Middleman::CoreExtensions::Compass - -# Sprockets asset handling -require "middleman-more/core_extensions/sprockets" -Middleman::Application.register Middleman::CoreExtensions::Sprockets - -### -# Setup Optional Extensions -### - -# CacheBuster adds a query string to assets in dynamic templates to avoid -# browser caches failing to update to your new content. -Middleman::Extensions.register(:cache_buster) do - require "middleman-more/extensions/cache_buster" - Middleman::Extensions::CacheBuster -end - -# MinifyCss compresses CSS -Middleman::Extensions.register(:minify_css) do - require "middleman-more/extensions/minify_css" - Middleman::Extensions::MinifyCss -end - -# MinifyJavascript compresses JS -Middleman::Extensions.register(:minify_javascript) do - require "middleman-more/extensions/minify_javascript" - Middleman::Extensions::MinifyJavascript -end - -# RelativeAssets allow any asset path in dynamic templates to be either -# relative to the root of the project or use an absolute URL. -Middleman::Extensions.register(:relative_assets) do - require "middleman-more/extensions/relative_assets" - Middleman::Extensions::RelativeAssets -end - -# GZIP assets and pages during build -Middleman::Extensions.register(:gzip) do - require "middleman-more/extensions/gzip" - Middleman::Extensions::Gzip -end - -# AssetHash appends a hash of the file contents to the assets filename -# to avoid browser caches failing to update to your new content. -Middleman::Extensions.register(:asset_hash) do - require "middleman-more/extensions/asset_hash" - Middleman::Extensions::AssetHash -end \ No newline at end of file diff --git a/middleman-more/lib/middleman_extension.rb b/middleman-more/lib/middleman_extension.rb new file mode 100644 index 00000000..a9223146 --- /dev/null +++ b/middleman-more/lib/middleman_extension.rb @@ -0,0 +1 @@ +require "middleman-more" \ No newline at end of file