give sprockets access to middleman environment scope (variables, data, etc)
This commit is contained in:
parent
af9e4989e3
commit
cc577c0c73
10 changed files with 53 additions and 29 deletions
2
Gemfile
2
Gemfile
|
@ -1,3 +1,3 @@
|
|||
source "http://www.rubygems.org"
|
||||
source :rubygems
|
||||
|
||||
gemspec
|
|
@ -8,4 +8,9 @@ Feature: Sprockets
|
|||
Scenario: Sprockets require with custom :js_dir
|
||||
Given the Server is running at "sprockets-app"
|
||||
When I go to "/library/javascripts/sprockets_base.js"
|
||||
Then I should see "sprockets_sub_function"
|
||||
Then I should see "sprockets_sub_function"
|
||||
|
||||
Scenario: Sprockets should have access to yaml data
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/javascripts/multiple_engines.js"
|
||||
Then I should see "Hello One"
|
|
@ -2,6 +2,6 @@
|
|||
Feature: Sprockets Gems
|
||||
|
||||
Scenario: Sprockets can pull jQuery from gem
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/javascripts/jquery_base.js"
|
||||
# Then I should see "sprockets_sub_function"
|
||||
Given the Server is running at "sprockets-app"
|
||||
When I go to "/javascripts/jquery_include.js"
|
||||
Then I should see "var jQuery ="
|
1
fixtures/sprockets-app/source/jquery_include.js
vendored
Normal file
1
fixtures/sprockets-app/source/jquery_include.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
//= require "jquery"
|
|
@ -0,0 +1 @@
|
|||
alert "Hello <%= data.test[0].title %>"
|
|
@ -13,7 +13,7 @@ module Middleman::CoreExtensions::Data
|
|||
|
||||
module Helpers
|
||||
def data
|
||||
@@data ||= DataObject.new(self)
|
||||
self.class.data
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,7 @@ module Middleman::CoreExtensions::Data
|
|||
elsif @@callback_sources.has_key?(path.to_s)
|
||||
response = @@callback_sources[path.to_s].call()
|
||||
else
|
||||
file_path = File.join(@app.class.root, @app.class.data_dir, "#{path}.yml")
|
||||
file_path = File.join(@app.root, @app.data_dir, "#{path}.yml")
|
||||
if File.exists? file_path
|
||||
response = YAML.load_file(file_path)
|
||||
end
|
||||
|
@ -74,6 +74,10 @@ module Middleman::CoreExtensions::Data
|
|||
end
|
||||
|
||||
module ClassMethods
|
||||
def data
|
||||
@data ||= DataObject.new(self)
|
||||
end
|
||||
|
||||
# Makes a hash available on the data var with a given name
|
||||
def data_content(name, content)
|
||||
DataObject.data_content(name, content)
|
||||
|
|
|
@ -6,23 +6,23 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
def registered(app)
|
||||
app.extend ClassMethods
|
||||
|
||||
Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
|
||||
Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
||||
Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
|
||||
Tilt::register KramdownTemplate, 'markdown', 'mkd', 'md'
|
||||
app.set :markdown_engine_prefix, Middleman::CoreExtensions::FrontMatter
|
||||
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register KramdownTemplate, 'markdown', 'mkd', 'md'
|
||||
app.set :markdown_engine_prefix, ::Middleman::CoreExtensions::FrontMatter
|
||||
|
||||
Tilt::register RedClothTemplate, 'textile'
|
||||
Tilt.prefer(RedClothTemplate)
|
||||
::Tilt::register RedClothTemplate, 'textile'
|
||||
::Tilt.prefer(RedClothTemplate)
|
||||
|
||||
Tilt::register ERBTemplate, 'erb', 'rhtml'
|
||||
Tilt.prefer(ERBTemplate)
|
||||
::Tilt::register ERBTemplate, 'erb', 'rhtml'
|
||||
::Tilt.prefer(ERBTemplate)
|
||||
|
||||
Tilt::register SlimTemplate, 'slim'
|
||||
Tilt.prefer(SlimTemplate)
|
||||
::Tilt::register SlimTemplate, 'slim'
|
||||
::Tilt.prefer(SlimTemplate)
|
||||
|
||||
Tilt::register HamlTemplate, 'haml'
|
||||
Tilt.prefer(HamlTemplate)
|
||||
::Tilt::register HamlTemplate, 'haml'
|
||||
::Tilt.prefer(HamlTemplate)
|
||||
|
||||
app.after_configuration do
|
||||
app.before_processing do
|
||||
|
@ -82,27 +82,27 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
end
|
||||
end
|
||||
|
||||
class RDiscountTemplate < Tilt::RDiscountTemplate
|
||||
class RDiscountTemplate < ::Tilt::RDiscountTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
class RedcarpetTemplate < Tilt::RedcarpetTemplate
|
||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
class MarukuTemplate < Tilt::MarukuTemplate
|
||||
class MarukuTemplate < ::Tilt::MarukuTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
class RedClothTemplate < Tilt::RedClothTemplate
|
||||
class RedClothTemplate < ::Tilt::RedClothTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
class KramdownTemplate < Tilt::KramdownTemplate
|
||||
class KramdownTemplate < ::Tilt::KramdownTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class ERBTemplate < Tilt::ERBTemplate
|
||||
class ERBTemplate < ::Tilt::ERBTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class HamlTemplate < Tilt::HamlTemplate
|
||||
class HamlTemplate < ::Tilt::HamlTemplate
|
||||
include Middleman::CoreExtensions::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
|
|
|
@ -36,6 +36,18 @@ module Middleman::CoreExtensions::Sprockets
|
|||
full_path = File.join(app.root, app.views) unless app.views.include?(app.root)
|
||||
|
||||
super File.expand_path(full_path)
|
||||
|
||||
# Make the app context available to Sprockets
|
||||
context_class.send(:define_method, :app) { app }
|
||||
context_class.class_eval do
|
||||
def method_missing(name)
|
||||
if app.respond_to?(name)
|
||||
app.send(name)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ module Middleman::Renderers::Markdown
|
|||
app.set :markdown_engine, :maruku
|
||||
|
||||
if !app.respond_to? :markdown_engine_prefix
|
||||
app.set :markdown_engine_prefix, Tilt
|
||||
app.set :markdown_engine_prefix, ::Tilt
|
||||
end
|
||||
|
||||
app.after_configuration do
|
||||
|
@ -18,7 +18,7 @@ module Middleman::Renderers::Markdown
|
|||
engine = app.tilt_template_from_symbol(engine)
|
||||
end
|
||||
|
||||
Tilt.prefer(engine)
|
||||
::Tilt.prefer(engine)
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
|
|
|
@ -73,6 +73,7 @@ eos
|
|||
s.add_dependency("middleman-livereload", ["~> 0.2.0"])
|
||||
|
||||
# Development and test
|
||||
# s.add_development_dependency("jquery-rails")
|
||||
s.add_development_dependency("coffee-filter", ["~> 0.1.1"])
|
||||
s.add_development_dependency("cucumber", ["~> 1.0.2"])
|
||||
s.add_development_dependency("rake", ["0.8.7"])
|
||||
|
|
Loading…
Reference in a new issue