Merge in pull 65
This commit is contained in:
commit
02158cb96a
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,3 +9,4 @@ Gemfile.lock
|
|||
docs
|
||||
.rvmrc
|
||||
fixtures/test-app/build
|
||||
.*.swp
|
27
features/helpers_auto_javascript_include_tag.feature
Normal file
27
features/helpers_auto_javascript_include_tag.feature
Normal 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"
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
1
fixtures/test-app/source/auto-js.html.haml
Executable file
1
fixtures/test-app/source/auto-js.html.haml
Executable file
|
@ -0,0 +1 @@
|
|||
= auto_javascript_include_tag
|
1
fixtures/test-app/source/javascripts/auto-js.js
Normal file
1
fixtures/test-app/source/javascripts/auto-js.js
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
fixtures/test-app/source/javascripts/auto-js/auto-js.js
Normal file
1
fixtures/test-app/source/javascripts/auto-js/auto-js.js
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
fixtures/test-app/source/javascripts/auto-js/index.js
Normal file
1
fixtures/test-app/source/javascripts/auto-js/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
0
fixtures/test-app/source/stylesheets/sub1/sub2/auto-css.css → fixtures/test-app/source/stylesheets/auto-css/index.css
Executable file → Normal file
0
fixtures/test-app/source/stylesheets/sub1/sub2/auto-css.css → fixtures/test-app/source/stylesheets/auto-css/index.css
Executable file → Normal file
0
fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css
Executable file
0
fixtures/test-app/source/stylesheets/auto-css/sub/auto-css.css
Executable file
|
@ -8,20 +8,34 @@ module Middleman::Features::DefaultHelpers
|
|||
|
||||
module Helpers
|
||||
def auto_stylesheet_link_tag(separator="/")
|
||||
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
|
||||
path << self.class.index_file if path.match(%r{/$})
|
||||
# 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), '')
|
||||
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
||||
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"
|
||||
end
|
||||
view = File.join(self.class.views, asset_dir, path)
|
||||
yield path if File.exists?(view) or Dir["#{view}.*"].any?
|
||||
end
|
||||
|
||||
def page_classes
|
||||
|
|
Loading…
Reference in a new issue