jquery-tmpl-rails 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source :rubygems
2
2
 
3
3
  gemspec
4
+
5
+ gem 'sqlite3'
6
+ gem 'jquery-rails'
data/README.md CHANGED
@@ -40,6 +40,12 @@ That would change the previous example to this:
40
40
  $.tmpl("author", { name: "Jimmy" }).appendTo("#author");
41
41
  ```
42
42
 
43
+ The prefix can also be a regular expression. For example, to use only the name of the file for the template name, regardless of directory structure:
44
+
45
+ ```ruby
46
+ config.jquery_templates.prefix = %r{([^/]*/)*}
47
+ ```
48
+
43
49
  Happy templating!
44
50
 
45
51
  ## Acknowledgements
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "jquery-tmpl-rails"
5
- s.version = "1.0.1"
5
+ s.version = "1.1.0"
6
6
  s.authors = ["Jimmy Cuadra"]
7
7
  s.email = ["jimmy@jimmycuadra.com"]
8
8
  s.homepage = ""
@@ -16,4 +16,6 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency 'rails', '>= 3.1.0'
18
18
  s.add_development_dependency 'rspec'
19
+ s.add_development_dependency 'capybara'
20
+ s.add_development_dependency 'poltergeist'
19
21
  end
@@ -2,12 +2,12 @@ require "active_support/ordered_options"
2
2
 
3
3
  module JqueryTmplRails
4
4
  class Railtie < Rails::Engine
5
+ config.jquery_templates = ActiveSupport::OrderedOptions.new
6
+ config.jquery_templates.prefix = ""
7
+
5
8
  initializer "sprockets.jquery_templates", :after => "sprockets.environment", :group => :all do |app|
6
9
  next unless app.assets
7
-
8
10
  app.assets.register_engine(".tmpl", JqueryTemplate)
9
- app.config.jquery_templates = ActiveSupport::OrderedOptions.new
10
- app.config.jquery_templates.prefix = ""
11
11
  end
12
12
  end
13
13
  end
@@ -1,4 +1,5 @@
1
1
  require 'sprockets'
2
+ require 'tilt'
2
3
  require 'action_view'
3
4
  require 'action_view/helpers'
4
5
 
@@ -21,7 +22,7 @@ module JqueryTmplRails
21
22
  private
22
23
 
23
24
  def normalize_prefix(prefix)
24
- if prefix.length > 0
25
+ if prefix.respond_to?(:length) && prefix.length > 0
25
26
  prefix = prefix[1, prefix.length - 1] if prefix.start_with?("/")
26
27
  prefix += "/" unless prefix.end_with?("/")
27
28
  end
@@ -1,15 +1,3 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
1
  //= require jquery
14
- //= require jquery_ujs
15
- //= require_tree .
2
+ //= require jquery-tmpl
3
+ //= require_tree ./templates
@@ -1 +1 @@
1
- <div class="test">{{test}}</div>
1
+ <div class="test">${test}</div>
@@ -0,0 +1,4 @@
1
+ class MainController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -2,13 +2,11 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
5
+ <%= stylesheet_link_tag "application" %>
6
6
  <%= javascript_include_tag "application" %>
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
-
11
- <%= yield %>
12
-
10
+ <%= yield %>
13
11
  </body>
14
12
  </html>
@@ -0,0 +1,5 @@
1
+ <script>
2
+ $(function () {
3
+ $.tmpl("templates/test", { test: "Jimmy" }).appendTo("body");
4
+ });
5
+ </script>
@@ -0,0 +1,5 @@
1
+ <script>
2
+ $(function () {
3
+ $.tmpl("test", { test: "Jimmy" }).appendTo("body");
4
+ });
5
+ </script>
@@ -1,58 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation:
3
- # first created -> highest priority.
4
-
5
- # Sample of regular route:
6
- # match 'products/:id' => 'catalog#view'
7
- # Keep in mind you can assign values other than :controller and :action
8
-
9
- # Sample of named route:
10
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
- # This route can be invoked with purchase_url(:id => product.id)
12
-
13
- # Sample resource route (maps HTTP verbs to controller actions automatically):
14
- # resources :products
15
-
16
- # Sample resource route with options:
17
- # resources :products do
18
- # member do
19
- # get 'short'
20
- # post 'toggle'
21
- # end
22
- #
23
- # collection do
24
- # get 'sold'
25
- # end
26
- # end
27
-
28
- # Sample resource route with sub-resources:
29
- # resources :products do
30
- # resources :comments, :sales
31
- # resource :seller
32
- # end
33
-
34
- # Sample resource route with more complex sub-resources
35
- # resources :products do
36
- # resources :comments
37
- # resources :sales do
38
- # get 'recent', :on => :collection
39
- # end
40
- # end
41
-
42
- # Sample resource route within a namespace:
43
- # namespace :admin do
44
- # # Directs /admin/products/* to Admin::ProductsController
45
- # # (app/controllers/admin/products_controller.rb)
46
- # resources :products
47
- # end
48
-
49
- # You can have the root of your site routed with "root"
50
- # just remember to delete public/index.html.
51
- # root :to => 'welcome#index'
52
-
53
- # See how all your routes lay out with "rake routes"
54
-
55
- # This is a legacy wild controller route that's not recommended for RESTful applications.
56
- # Note: This route will make all actions in every controller accessible via GET requests.
57
- # match ':controller(/:action(/:id))(.:format)'
2
+ match "prefix" => "main#prefix"
3
+ root to: "main#index"
58
4
  end
File without changes
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ feature "Using jquery-tmpl-rails", js: true do
4
+ after do
5
+ Rails.application.config.jquery_templates.prefix = ''
6
+ end
7
+
8
+ scenario "Loading a page using a jQuery template" do
9
+ visit "/"
10
+ page.should have_content("Jimmy")
11
+ end
12
+
13
+ scenario "Using a template prefix", js: true do
14
+ Rails.application.config.jquery_templates.prefix = 'templates'
15
+ visit "/prefix"
16
+ page.should have_content("Jimmy")
17
+ end
18
+
19
+ scenario "Using a regular expression as a template prefix", js: true do
20
+ Rails.application.config.jquery_templates.prefix = %r{([^/]*/)*}
21
+ visit "/prefix"
22
+ page.should have_content("Jimmy")
23
+ end
24
+ end
@@ -9,7 +9,7 @@ describe JqueryTmplRails::JqueryTemplate do
9
9
 
10
10
  it "compiles templates with the .tmpl extension" do
11
11
  template = Rails.application.assets["templates/test"]
12
- template.to_s.should == %{jQuery.template("templates/test", "<div class=\\\"test\\\">{{test}}<\\/div>\\n");}
12
+ template.to_s.should == %{jQuery.template("templates/test", "<div class=\\\"test\\\">${test}<\\/div>\\n");}
13
13
  end
14
14
 
15
15
  context "when config.template_prefix is set" do
@@ -3,3 +3,9 @@ ENV["RAILS_ENV"] = "test"
3
3
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
4
 
5
5
  Rails.backtrace_cleaner.remove_silencers!
6
+
7
+ require "capybara/rails"
8
+ require "capybara/rspec"
9
+ require "capybara/poltergeist"
10
+
11
+ Capybara.javascript_driver = :poltergeist
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-tmpl-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-23 00:00:00.000000000 Z
12
+ date: 2012-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70282947797020 !ruby/object:Gem::Requirement
16
+ requirement: &70313071249060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70282947797020
24
+ version_requirements: *70313071249060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70282947796620 !ruby/object:Gem::Requirement
27
+ requirement: &70313071248660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,29 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70282947796620
35
+ version_requirements: *70313071248660
36
+ - !ruby/object:Gem::Dependency
37
+ name: capybara
38
+ requirement: &70313071248200 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70313071248200
47
+ - !ruby/object:Gem::Dependency
48
+ name: poltergeist
49
+ requirement: &70313071247780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70313071247780
36
58
  description: Adds the jQuery Templates plugin and a corresponding Sprockets engine
37
59
  to the asset pipeline in Rails applications.
38
60
  email:
@@ -57,10 +79,13 @@ files:
57
79
  - spec/dummy/app/assets/javascripts/templates/test.tmpl
58
80
  - spec/dummy/app/assets/stylesheets/application.css
59
81
  - spec/dummy/app/controllers/application_controller.rb
82
+ - spec/dummy/app/controllers/main_controller.rb
60
83
  - spec/dummy/app/helpers/application_helper.rb
61
84
  - spec/dummy/app/mailers/.gitkeep
62
85
  - spec/dummy/app/models/.gitkeep
63
86
  - spec/dummy/app/views/layouts/application.html.erb
87
+ - spec/dummy/app/views/main/index.html.erb
88
+ - spec/dummy/app/views/main/prefix.html.erb
64
89
  - spec/dummy/config.ru
65
90
  - spec/dummy/config/application.rb
66
91
  - spec/dummy/config/boot.rb
@@ -77,6 +102,7 @@ files:
77
102
  - spec/dummy/config/initializers/wrap_parameters.rb
78
103
  - spec/dummy/config/locales/en.yml
79
104
  - spec/dummy/config/routes.rb
105
+ - spec/dummy/db/test.sqlite3
80
106
  - spec/dummy/lib/assets/.gitkeep
81
107
  - spec/dummy/log/.gitkeep
82
108
  - spec/dummy/public/404.html
@@ -84,6 +110,7 @@ files:
84
110
  - spec/dummy/public/500.html
85
111
  - spec/dummy/public/favicon.ico
86
112
  - spec/dummy/script/rails
113
+ - spec/integration_spec.rb
87
114
  - spec/jquery-tmpl-rails/jquery_template_spec.rb
88
115
  - spec/spec_helper.rb
89
116
  - vendor/assets/javascripts/jquery-tmpl.js
@@ -118,10 +145,13 @@ test_files:
118
145
  - spec/dummy/app/assets/javascripts/templates/test.tmpl
119
146
  - spec/dummy/app/assets/stylesheets/application.css
120
147
  - spec/dummy/app/controllers/application_controller.rb
148
+ - spec/dummy/app/controllers/main_controller.rb
121
149
  - spec/dummy/app/helpers/application_helper.rb
122
150
  - spec/dummy/app/mailers/.gitkeep
123
151
  - spec/dummy/app/models/.gitkeep
124
152
  - spec/dummy/app/views/layouts/application.html.erb
153
+ - spec/dummy/app/views/main/index.html.erb
154
+ - spec/dummy/app/views/main/prefix.html.erb
125
155
  - spec/dummy/config.ru
126
156
  - spec/dummy/config/application.rb
127
157
  - spec/dummy/config/boot.rb
@@ -138,6 +168,7 @@ test_files:
138
168
  - spec/dummy/config/initializers/wrap_parameters.rb
139
169
  - spec/dummy/config/locales/en.yml
140
170
  - spec/dummy/config/routes.rb
171
+ - spec/dummy/db/test.sqlite3
141
172
  - spec/dummy/lib/assets/.gitkeep
142
173
  - spec/dummy/log/.gitkeep
143
174
  - spec/dummy/public/404.html
@@ -145,6 +176,7 @@ test_files:
145
176
  - spec/dummy/public/500.html
146
177
  - spec/dummy/public/favicon.ico
147
178
  - spec/dummy/script/rails
179
+ - spec/integration_spec.rb
148
180
  - spec/jquery-tmpl-rails/jquery_template_spec.rb
149
181
  - spec/spec_helper.rb
150
182
  has_rdoc: