diff --git a/Gemfile b/Gemfile index 2520b275..2c06b4c0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source "http://www.rubygems.org" +source :rubygems gemspec \ No newline at end of file diff --git a/features/sprockets.feature b/features/sprockets.feature index 943fc273..0d233aa9 100644 --- a/features/sprockets.feature +++ b/features/sprockets.feature @@ -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" \ No newline at end of file + 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" \ No newline at end of file diff --git a/features/sprockets_gems.feature b/features/sprockets_gems.feature index 300b39ad..7fd9b1b0 100644 --- a/features/sprockets_gems.feature +++ b/features/sprockets_gems.feature @@ -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" \ No newline at end of file + Given the Server is running at "sprockets-app" + When I go to "/javascripts/jquery_include.js" + Then I should see "var jQuery =" \ No newline at end of file diff --git a/fixtures/sprockets-app/source/jquery_include.js b/fixtures/sprockets-app/source/jquery_include.js new file mode 100644 index 00000000..28bf206d --- /dev/null +++ b/fixtures/sprockets-app/source/jquery_include.js @@ -0,0 +1 @@ +//= require "jquery" \ No newline at end of file diff --git a/fixtures/test-app/source/javascripts/multiple_engines.js.coffee.erb b/fixtures/test-app/source/javascripts/multiple_engines.js.coffee.erb new file mode 100644 index 00000000..360022a5 --- /dev/null +++ b/fixtures/test-app/source/javascripts/multiple_engines.js.coffee.erb @@ -0,0 +1 @@ +alert "Hello <%= data.test[0].title %>" \ No newline at end of file diff --git a/lib/middleman/core_extensions/data.rb b/lib/middleman/core_extensions/data.rb index d6d3f3d4..ce00f9b9 100755 --- a/lib/middleman/core_extensions/data.rb +++ b/lib/middleman/core_extensions/data.rb @@ -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) diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index fb4653a0..3ac38039 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -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 diff --git a/lib/middleman/core_extensions/sprockets.rb b/lib/middleman/core_extensions/sprockets.rb index 5b4537b6..41dcd387 100644 --- a/lib/middleman/core_extensions/sprockets.rb +++ b/lib/middleman/core_extensions/sprockets.rb @@ -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 diff --git a/lib/middleman/renderers/markdown.rb b/lib/middleman/renderers/markdown.rb index 6ebece27..d7d7bf47 100644 --- a/lib/middleman/renderers/markdown.rb +++ b/lib/middleman/renderers/markdown.rb @@ -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 diff --git a/middleman.gemspec b/middleman.gemspec index 83544f9e..3e7367cb 100644 --- a/middleman.gemspec +++ b/middleman.gemspec @@ -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"])