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

Ruby2 & Rails4 support #2

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pkg/*
**/*/log/*
**/*/tmp/*
Gemfile.lock
.idea/*
2 changes: 1 addition & 1 deletion .rvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rvm use default@handlebars_assets
rvm use --create ruby-head@slim
34 changes: 11 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# Use slim to write your Javascript templates

*ALPHA*
This is a fork of the wonderful slim_assets (https://github.com/crowdint/slim_assets) to work with Rails 4 & Ruby 2.

[![Build Status](https://secure.travis-ci.org/crowdint/slim_assets.png)](http://travis-ci.org/crowdint/slim_assets)

Writing Javascript templates for Backbone.js (or other frameworks) in your app? Would you like to use slim and the asset pipeline?

This gem adds slim templating support to the Rails 3.1 asset pipeline. This gem works with the EJS gem and JST asset engine to make your slim available as a compiled Javascript template.
Use this to write Backbone.js or AngularJS templates in Slim and let the Rails asset pipeline take over.

## Installing

Add this to your `Gemfile`

gem 'slim_assets'
gem 'ejs'
gem 'slim_assets', github: 'jigyasam/slim_assets, branch: 'jigyasam/rail4'
gem 'slim'

# Using slim for your Javascript templates
Expand All @@ -28,32 +23,25 @@ You should locate your templates under `app/assets`; we suggest `app/assets/temp

Inside your templates directory, add your template file. The file should be named as follows

your_template_name.jst.ejs.slim
your_template_name.html.slim

The asset pipeline will then generate the actual Javascript asset

1. Convert your slim to HTML
1. Compile the HTML to an EJS Javascript template
1. Add the template to the JST global under the templates name

**Important!** The asset pipeline is not invoking a controller to generate the templates. If you are using existing view templates, you may have to edit templates to remove some references to controller helpers.

## EJS
### Helpers

In your template file you can use the EJS delimiters as you would normally. If you want to use them in attributes mark the attribute html_safe.
All the ActionView and route helpers are available in your template. Eg:

= f.text_field :email, class: 'text', value: '<%= email %>'.html_safe
ul
li = link_to "Home", home_path

### Helpers
### Angular template variables & directives work. Eg:

All the ActionView and route helpers are available in your template. If you use `form_for` and the related helpers, you should use the *new* object form, even if you are writing an *edit* form, for example
div.items data-ng-repeat="item in items" {{ item }}

= form_for :contact, url: "javascript_not_working", html: {:class => :edit_contact, :method => :put} do |f|
%p
= f.label :name, "Name"
= f.text_field :name, class: 'text required', autofocus: true, value: '<%= name %>'.html_safe

# Credits
# Original Credits

* Les Hill : @leshill
* Wes Gibbs : @wgibbs
Expand Down
2 changes: 1 addition & 1 deletion lib/slim_assets/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SlimAssets
VERSION = "0.0.2"
VERSION = "0.0.3"
end
2 changes: 1 addition & 1 deletion slim_assets.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "slim"
s.add_runtime_dependency "tilt"

s.add_development_dependency 'rails', '~> 3.1.0'
s.add_development_dependency 'rails', '4.0.0.beta1'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rspec-rails'
Expand Down