diff --git a/.gitignore b/.gitignore index 4e693d42..761c6d30 100755 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ pkg Gemfile.lock docs .rvmrc -fixtures/test-app/build \ No newline at end of file +fixtures/test-app/build +.*.swp \ No newline at end of file diff --git a/features/helpers_auto_javascript_include_tag.feature b/features/helpers_auto_javascript_include_tag.feature new file mode 100644 index 00000000..193f074d --- /dev/null +++ b/features/helpers_auto_javascript_include_tag.feature @@ -0,0 +1,27 @@ +Feature: Built-in auto_javascript_include_tag view helper + In order to simplify including javascript files + + Scenario: Viewing the root path + Given the Server is running + When I go to "/auto-js.html" + Then I should see "javascripts/auto-js.js" + + Scenario: Viewing a tier-1 path + Given the Server is running + When I go to "/auto-js/auto-js.html" + Then I should see "javascripts/auto-js/auto-js.js" + + Scenario: Viewing the index file of a tier-1 path, without filename + Given the Server is running + When I go to "/auto-js" + Then I should see "javascripts/auto-js/index.js" + + Scenario: Viewing the index file of a tier-1 path, without filename, with a trailing slash + Given the Server is running + When I go to "/auto-js/" + Then I should see "javascripts/auto-js/index.js" + + Scenario: Viewing a tier-2 path + Given the Server is running + When I go to "/auto-js/sub/auto-js.html" + Then I should see "javascripts/auto-js/sub/auto-js.js" diff --git a/features/helpers_auto_stylesheet_link_tag.feature b/features/helpers_auto_stylesheet_link_tag.feature index 8139662b..e4ef140b 100644 --- a/features/helpers_auto_stylesheet_link_tag.feature +++ b/features/helpers_auto_stylesheet_link_tag.feature @@ -8,10 +8,20 @@ Feature: Built-in auto_stylesheet_link_tag view helper Scenario: Viewing a tier-1 path Given the Server is running - When I go to "/sub1/auto-css.html" - Then I should see "stylesheets/sub1/auto-css.css" + When I go to "/auto-css/auto-css.html" + Then I should see "stylesheets/auto-css/auto-css.css" + + Scenario: Viewing the index file of a tier-1 path, without filename + Given the Server is running + When I go to "/auto-css" + Then I should see "stylesheets/auto-css/index.css" + + Scenario: Viewing the index file of a tier-1 path, without filename, with a trailing slash + Given the Server is running + When I go to "/auto-css/" + Then I should see "stylesheets/auto-css/index.css" Scenario: Viewing a tier-2 path Given the Server is running - When I go to "/sub1/sub2/auto-css.html" - Then I should see "stylesheets/sub1/sub2/auto-css.css" \ No newline at end of file + When I go to "/auto-css/sub/auto-css.html" + Then I should see "stylesheets/auto-css/sub/auto-css.css" diff --git a/fixtures/test-app/config.rb b/fixtures/test-app/config.rb index b91191ed..0d12818c 100644 --- a/fixtures/test-app/config.rb +++ b/fixtures/test-app/config.rb @@ -17,14 +17,27 @@ get "/sub1/sub2/page-class.html" do haml :"page-classes.html", :layout => false end -get "/auto-css.html" do - haml :"auto-css.html", :layout => false +%w{ + /auto-css.html + /auto-css + /auto-css/ + /auto-css/auto-css.html + /auto-css/sub/auto-css.html +}.each do |path| + get path do + haml :"auto-css.html", :layout => false + end end -get "/sub1/auto-css.html" do - haml :"auto-css.html", :layout => false +%w{ + /auto-js.html + /auto-js + /auto-js/ + /auto-js/auto-js.html + /auto-js/sub/auto-js.html +}.each do |path| + get path do + haml :"auto-js.html", :layout => false + end end -get "/sub1/sub2/auto-css.html" do - haml :"auto-css.html", :layout => false -end diff --git a/fixtures/test-app/source/auto-js.html.haml b/fixtures/test-app/source/auto-js.html.haml new file mode 100755 index 00000000..3bf0eb1e --- /dev/null +++ b/fixtures/test-app/source/auto-js.html.haml @@ -0,0 +1 @@ += auto_javascript_include_tag diff --git a/fixtures/test-app/source/javascripts/auto-js.js b/fixtures/test-app/source/javascripts/auto-js.js new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/fixtures/test-app/source/javascripts/auto-js.js @@ -0,0 +1 @@ + diff --git a/fixtures/test-app/source/javascripts/auto-js/auto-js.js b/fixtures/test-app/source/javascripts/auto-js/auto-js.js new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/fixtures/test-app/source/javascripts/auto-js/auto-js.js @@ -0,0 +1 @@ + diff --git a/fixtures/test-app/source/javascripts/auto-js/index.js b/fixtures/test-app/source/javascripts/auto-js/index.js new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/fixtures/test-app/source/javascripts/auto-js/index.js @@ -0,0 +1 @@ + diff --git a/fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js b/fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/fixtures/test-app/source/javascripts/auto-js/sub/auto-js.js @@ -0,0 +1 @@ + diff --git a/fixtures/test-app/source/stylesheets/sub1/auto-css.css b/fixtures/test-app/source/stylesheets/auto-css/auto-css.css similarity index 100% rename from fixtures/test-app/source/stylesheets/sub1/auto-css.css rename to fixtures/test-app/source/stylesheets/auto-css/auto-css.css diff --git a/fixtures/test-app/source/stylesheets/sub1/sub2/auto-css.css b/fixtures/test-app/source/stylesheets/auto-css/index.css old mode 100755 new mode 100644 similarity index 100% rename from fixtures/test-app/source/stylesheets/sub1/sub2/auto-css.css rename to fixtures/test-app/source/stylesheets/auto-css/index.css diff --git a/fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css b/fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css new file mode 100755 index 00000000..e69de29b diff --git a/lib/middleman/features/default_helpers.rb b/lib/middleman/features/default_helpers.rb index e431c8b7..283929c3 100644 --- a/lib/middleman/features/default_helpers.rb +++ b/lib/middleman/features/default_helpers.rb @@ -8,22 +8,36 @@ module Middleman::Features::DefaultHelpers module Helpers def auto_stylesheet_link_tag(separator="/") - path = request.path_info.dup - path << self.class.index_file if path.match(%r{/$}) - path = path.gsub(%r{^/}, '') - path = path.gsub(File.extname(path), '') - path = path.gsub("/", separator) - - css_file = File.join(self.class.views, self.class.css_dir, "#{path}.css") - sass_file = File.join(self.class.views, self.class.css_dir, "#{path}.css.sass") - scss_file = File.join(self.class.views, self.class.css_dir, "#{path}.css.scss") - less_file = File.join(self.class.views, self.class.css_dir, "#{path}.css.less") - - if File.exists?(css_file) || File.exists?(sass_file) || File.exists?(scss_file) || File.exists?(less_file) - stylesheet_link_tag "#{path}.css" + auto_tag(:css, separator) do |path| + stylesheet_link_tag path end end + def auto_javascript_include_tag(separator="/") + auto_tag(:js, separator) do |path| + javascript_include_tag path + end + end + + def auto_tag(asset_ext, separator="/", asset_dir=nil) + if asset_dir.nil? + asset_dir = case asset_ext + when :js then self.class.js_dir + when :css then self.class.css_dir + end + end + path = request.path_info.dup + # If the basename of the request as no extension, assume we are serving a + # directory and join index_file to the path. + path = File.join(path, self.class.index_file) if File.extname(path).empty? + path = path.gsub(%r{^/}, '') + path = path.gsub(File.extname(path), ".#{asset_ext}") + path = path.gsub("/", separator) + + view = File.join(self.class.views, asset_dir, path) + yield path if File.exists?(view) or Dir["#{view}.*"].any? + end + def page_classes path = request.path_info.dup path << settings.index_file if path.match(%r{/$}) @@ -58,4 +72,4 @@ module Middleman::Features::DefaultHelpers "#{result_path}#{timestamp}" end end -end \ No newline at end of file +end diff --git a/lib/middleman/version.rb b/lib/middleman/version.rb index d353e575..11a9c7e0 100644 --- a/lib/middleman/version.rb +++ b/lib/middleman/version.rb @@ -1,3 +1,3 @@ module Middleman - VERSION = "2.0.0.beta3" + VERSION = "2.0.0.beta4" end diff --git a/middleman.gemspec b/middleman.gemspec index f993b90c..c00ec2a4 100644 --- a/middleman.gemspec +++ b/middleman.gemspec @@ -36,6 +36,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency("coffee-script", ["~> 2.2.0"]) s.add_runtime_dependency("httparty", ["~> 0.7.0"]) s.add_development_dependency("cucumber", ["~> 0.10.0"]) + s.add_development_dependency("rake", ["0.8.7"]) s.add_development_dependency("rspec", [">= 0"]) s.add_development_dependency("rocco", [">= 0"]) unless defined?(JRUBY_VERSION) end