Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application helpers are now availible to slim templates #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/slim_assets/slim_sprockets_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ module ViewContext

def self.included(klass)
klass.instance_eval do
include ActiveSupport::Configurable
include Rails.application.routes.url_helpers
include Rails.application.routes.mounted_helpers
include ActionView::Helpers
include SimpleForm::ActionViewExtensions::FormHelper if defined?(SimpleForm)
include ActionController::Helpers

self.helpers_path = Rails.application.config.helpers_paths
modules_for_helpers([:all]).each {|m| include m }
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1
= test_helper("App helpers work")
1 change: 0 additions & 1 deletion spec/rails_app/app/assets/javascripts/link_to.jst.ejs.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
h1
.text Render works

5 changes: 5 additions & 0 deletions spec/rails_app/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ApplicationHelper
def test_helper(string)
string
end
end
4 changes: 4 additions & 0 deletions spec/render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ class Post < ActiveRecord::Base
it "should use rails helpers" do
RailsApp::Application.assets['helpers.jst.ejs.slim'].to_s.should == "(function() {\n this.JST || (this.JST = {});\n this.JST[\"helpers\"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<h1>Form</h1><form accept-charset=\"UTF-8\" action=\"/\" class=\"new_post\" id=\"new_post\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><input id=\"post_title\" name=\"post[title]\" size=\"30\" type=\"text\" /></form>');}return __p.join('');};\n}).call(this);\n"
end

it "should use application helpers" do
RailsApp::Application.assets['app_helpers.jst.ejs.slim'].to_s.should == "(function() {\n this.JST || (this.JST = {});\n this.JST[\"app_helpers\"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<h1>App helpers work</h1>');}return __p.join('');};\n}).call(this);\n"
end
end