smt_rails 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,6 +36,24 @@ The same template you can render in JavaScript:
36
36
 
37
37
  var content = SMT['tests/test']({msg: "Test"});
38
38
 
39
+ ## Mustache Partials
40
+
41
+ File: "app/templates/people/_list.mustache"
42
+
43
+ {{#people}}{{>people/item}}{{/people}}
44
+
45
+ File: "app/templates/people/_item.mustache"
46
+
47
+ Name: {{name}}<br>
48
+
49
+ In view you can render this template by this way:
50
+
51
+ <%= render "people/list", :mustache => {people: [{name: 'Alex'}, {name: 'John'}]} %>
52
+
53
+ The same template you can render in JavaScript:
54
+
55
+ var content = SMT['people/list']({people: [{name: 'Alex'}, {name: 'John'}]});
56
+
39
57
  ## Configuration
40
58
 
41
59
  SmtRails.configure do |config|
@@ -47,9 +65,9 @@ The same template you can render in JavaScript:
47
65
 
48
66
  ## Demo
49
67
 
50
- Site: [http://smt-rails-example.herokuapp.com/](http://smt-rails-example.herokuapp.com/)
68
+ Site: [http://st-rails-example.herokuapp.com/](http://st-rails-example.herokuapp.com/)
51
69
 
52
- Source code: [https://github.com/le0pard/smt_rails_example](https://github.com/le0pard/smt_rails_example)
70
+ Source code: [https://github.com/le0pard/st_rails_example](https://github.com/le0pard/st_rails_example)
53
71
 
54
72
  ## Contributing
55
73
 
@@ -1,8 +1,14 @@
1
1
  require "mustache"
2
2
  require "active_support"
3
3
 
4
- module SmtRails
4
+ # Monkey patch mustache to render {{>partial}}
5
+ class Mustache
6
+ def self.partial(name)
7
+ File.read("#{template_path}/#{File.dirname(name.to_s)}/_#{File.basename(name.to_s)}.#{template_extension}")
8
+ end
9
+ end
5
10
 
11
+ module SmtRails
6
12
  module Mustache
7
13
  def self.call(template)
8
14
  if template.locals.include?(SmtRails.action_view_key.to_s) || template.locals.include?(SmtRails.action_view_key.to_sym)
@@ -17,4 +23,4 @@ end
17
23
 
18
24
  ActiveSupport.on_load(:action_view) do
19
25
  ActionView::Template.register_template_handler(::SmtRails.template_extension.to_sym, ::SmtRails::Mustache)
20
- end
26
+ end
@@ -17,14 +17,15 @@ module SmtRails
17
17
  <<-MustacheTemplate
18
18
  (function() {
19
19
  #{namespace} || (#{namespace} = {});
20
- #{namespace}[#{template_key.inspect}] = function(object, partials) {
21
- if (partials == null) {
22
- partials = {};
23
- }
20
+ #{namespace}[#{template_key.inspect}] = function(object) {
24
21
  var template = #{data.inspect};
25
22
  if (object == null){
26
23
  return template;
27
24
  } else {
25
+ var partials = {};
26
+ for (var key in #{SmtRails.template_namespace}) {
27
+ partials[key] = #{SmtRails.template_namespace}[key]();
28
+ }
28
29
  return Mustache.render(template, object, partials);
29
30
  }
30
31
  };
@@ -38,4 +39,4 @@ module SmtRails
38
39
  path.join('/')
39
40
  end
40
41
  end
41
- end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module SmtRails
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smt_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-17 00:00:00.000000000 Z
13
+ date: 2012-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70110400376840 !ruby/object:Gem::Requirement
17
+ requirement: &70352412062460 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70110400376840
25
+ version_requirements: *70352412062460
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: tilt
28
- requirement: &70110400376260 !ruby/object:Gem::Requirement
28
+ requirement: &70352412061900 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.3.3
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70110400376260
36
+ version_requirements: *70352412061900
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sprockets
39
- requirement: &70110400373740 !ruby/object:Gem::Requirement
39
+ requirement: &70352412061420 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.0.3
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70110400373740
47
+ version_requirements: *70352412061420
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: mustache
50
- requirement: &70110400372360 !ruby/object:Gem::Requirement
50
+ requirement: &70352412060940 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 0.99.4
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70110400372360
58
+ version_requirements: *70352412060940
59
59
  description: Shared mustache templates for rails 3
60
60
  email:
61
61
  - contacts@railsware.com