Merge in pull 65

i18n_v4
Thomas Reynolds 2011-06-24 11:04:16 -07:00
commit 02158cb96a
13 changed files with 96 additions and 26 deletions

3
.gitignore vendored
View File

@ -8,4 +8,5 @@ pkg
Gemfile.lock
docs
.rvmrc
fixtures/test-app/build
fixtures/test-app/build
.*.swp

View File

@ -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"

View File

@ -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"
When I go to "/auto-css/sub/auto-css.html"
Then I should see "stylesheets/auto-css/sub/auto-css.css"

View File

@ -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

View File

@ -0,0 +1 @@
= auto_javascript_include_tag

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -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
end