sinatra-mustache 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWE3OGU0YjQxMTFmMGVmMGMzMWNhMzE1MzFiODJjMjEzYWM2MGVkOQ==
5
+ data.tar.gz: !binary |-
6
+ MmQzZjQ1ODFiZTFmOTc5ZjhiZjgyNmMxYzllZWM5NWU1OWQ4MTA3NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YjIzZTNjOTE3ZTcwYTJhYmEwYjYzMGU1YjBkZDgxMGFkN2ZiNWMwNjExYTZm
10
+ YjYwZjMzZDA3MTUzNGIwYTQ4MjIyNjEzN2IxZTI1OTA0MzFmMTI2ZDU0N2Zi
11
+ ZGJhNWM1MGMzNDdjNjU2MTYxNDk0NTQ5ZDY0NGNmNGUxMzNhOGM=
12
+ data.tar.gz: !binary |-
13
+ NzlhMGE5ZTc1ZDgyMzJlZGRlMjhiYjNmZTcxY2FiNTJhYTAzNWQ0MWU5OGNl
14
+ NTM0NDZhYzU3NzBjYTk5M2ExYmY2ZjA2MDg3ZDQxNDI1OTMyOTg4MzBjYzZi
15
+ NmZkY2M5M2M1YzgyNWRhMTkxZWI1MmM3MDZmZjI0MmNlMWU5YzE=
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,15 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
6
- - ree
7
- - rbx-18mode
4
+ - 2.0.0
8
5
  - rbx-19mode
9
- - jruby
6
+ - rbx-20mode
7
+ - jruby-19mode
8
+ - jruby-20mode
10
9
 
11
- script: bundle exec rspec
12
-
13
- matrix:
14
- allow_failures:
15
- - rvm: jruby
10
+ script: bundle exec rspec
@@ -1,3 +1,9 @@
1
+ 0.2.0
2
+ =====
3
+
4
+ - removed support for 1.8.7
5
+ - refactoring of mustache template class
6
+
1
7
  0.0.5
2
8
  =====
3
9
 
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2010 Jason Campbell
3
+ Copyright (c) 2010 Jason Campbell, Beat Richartz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,24 +1,20 @@
1
- sinatra-mustache [![Build Status](https://travis-ci.org/beatrichartz/sinatra-mustache.png?branch=master)](https://travis-ci.org/beatrichartz/sinatra-mustache) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/beatrichartz/sinatra-mustache)
1
+ sinatra-mustache [![Build Status](https://travis-ci.org/beatrichartz/sinatra-mustache.png?branch=master)](https://travis-ci.org/beatrichartz/sinatra-mustache) [![Code Climate](https://codeclimate.com/github/beatrichartz/sinatra-mustache.png)](https://codeclimate.com/github/beatrichartz/sinatra-mustache) [![Dependency Status](https://gemnasium.com/beatrichartz/sinatra-mustache.png)](https://gemnasium.com/beatrichartz/sinatra-mustache)
2
2
  ================
3
3
 
4
- To simplify setting up [Sinatra][1] to use [Mustache][2] for it's templates
4
+ To simplify setting up [Sinatra][1] to use [Mustache][2] for it's templates. Supports MRI 1.9, 2.0 as well as Rubinius and JRuby in 1.9 and 2.0 mode.
5
5
 
6
- [Sinatra][1] is a pretty amazing little web framework, if you don't know much
6
+ [Sinatra][1] is a amazing little web framework, if you don't know much
7
7
  about it you should take some time to [get to know it][4].
8
8
 
9
- [Mustache][2] is also another favorite of mine; a really great and simple
10
- templating system. I have been slowly converting all my old views in various
11
- projects over to it.
9
+ [Mustache][2] is a really great and simple templating system.
12
10
 
13
- Why?
14
- ====
11
+ Without extra view classes
12
+ ----
15
13
 
16
- There is already an [official][3] way to get Mustache to work with Sinatra, which
17
- involves some work and requires separate view classes to accompany your
18
- mustache templates. While I see the power in that it seems a bit complex..
14
+ There is already an [official][3] way to get Mustache to work with Sinatra, which involves some work and requires separate view classes to accompany your mustache templates. There's power in that for sure, but for some implementations it is a bit complex.
19
15
 
20
16
  Usage
21
- =====
17
+ ----
22
18
 
23
19
  Try this on:
24
20
 
@@ -28,13 +24,12 @@ Try this on:
28
24
  set :views, 'templates' # totally optional
29
25
  end
30
26
 
31
- And then put your .mustache files in your app's views folder
27
+ And then put your .mustache files in your app's views folder.
32
28
 
33
- Instance variables and locals are available to the template as well as yaml
34
- front matter.
29
+ Instance variables and locals are available to the template as well as YAML front matter.
35
30
 
36
31
  Helpers
37
- ======
32
+ ----
38
33
 
39
34
  Use the helpers you defined in your app by passing their names to mustache_helper:
40
35
 
@@ -77,12 +72,29 @@ Now, this is possible:
77
72
  Passing arguments to helper methods via dot notation is limited to Strings only.
78
73
 
79
74
  Caveat
80
- ======
75
+ ----
81
76
 
82
- If you need the extra support of the ruby views used in the official Mustache
83
- for Sinatra example this gem probably isn't for you.
77
+ If you need the extra support of the ruby views used in the official Mustache for Sinatra example this gem probably isn't for you.
84
78
 
85
79
  [1]: http://www.sinatrarb.com/
86
80
  [2]: http://mustache.github.com/
87
81
  [3]: https://github.com/defunkt/mustache-sinatra-example
88
82
  [4]: http://sinatra-book.gittr.com/
83
+
84
+ Contributing to sinatra-mustache
85
+ ----
86
+
87
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
88
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
89
+ * Fork the project.
90
+ * Start a feature/bugfix branch.
91
+ * Commit and push until you are happy with your contribution.
92
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
93
+ * Make sure to add documentation for it. This is important so everyone else can see what your code can do.
94
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
95
+
96
+ Copyright
97
+ ----
98
+
99
+ Copyright (c) 2013 Beat Richartz. See LICENSE.txt for
100
+ further details.
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Mustache
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
@@ -2,12 +2,12 @@ module Sinatra
2
2
  module MustacheHelper
3
3
  METHODS = {}
4
4
 
5
- def mustache_helper *args
5
+ def mustache_helper *args
6
6
  args.each do |arg|
7
7
  if arg.is_a? Symbol
8
- add_to_mustache_helper_methods(arg, instance_method(arg).bind(self.new!))
8
+ add_to_mustache_helper_methods(arg)
9
9
  elsif arg.is_a? Module
10
- arg.instance_methods.each { |m| add_to_mustache_helper_methods(m, arg.instance_method(m).bind(self.new!)) }
10
+ add_to_mustache_helper_methods(*arg.instance_methods, arg)
11
11
  else
12
12
  raise ArgumentError.new("#{arg.class} can not be used with mustache_helper, please provide a symbol or a Module")
13
13
  end
@@ -15,8 +15,17 @@ module Sinatra
15
15
  end
16
16
  alias :mustache_helpers :mustache_helper
17
17
 
18
- def add_to_mustache_helper_methods name, meth
19
- METHODS[name] = Proxies::Currystache.new(meth)
18
+ private
19
+
20
+ def add_to_mustache_helper_methods *meths
21
+ scope = meths.last.is_a?(Module) ? meths.pop : self
22
+ meths.each do |meth|
23
+ METHODS[meth] = Proxies::Currystache.new(rebind_method!(meth, scope))
24
+ end
25
+ end
26
+
27
+ def rebind_method! meth,scope=self
28
+ scope.instance_method(meth).bind(self.new!)
20
29
  end
21
30
 
22
31
  end
@@ -11,41 +11,48 @@ module Tilt
11
11
  end
12
12
 
13
13
  def prepare
14
- ::Mustache.template_path = file.gsub(File.basename(file), '') if file
14
+ ::Mustache.template_path = file.sub File.basename(file), '' if file
15
15
  @engine = ::Mustache.new
16
16
  @output = nil
17
17
  end
18
18
 
19
- def evaluate(scope, locals, &block)
19
+ def evaluate scope, locals, &block
20
20
  mustache_locals = locals.dup
21
21
 
22
- if data =~ /^(\s*---(.+)---\s*)/m
23
- yaml = $2.strip
24
- template = data.sub($1, '')
22
+ template = assign_template_and_front_matter! mustache_locals, data
23
+ assign_instance_variables! mustache_locals, scope
24
+ assign_helper_methods! mustache_locals
25
25
 
26
- YAML.load_documents(yaml) do |front_matter|
27
- # allows partials to override locals defined higher up
28
- front_matter.delete_if { |key,value| mustache_locals.has_key?(key)}
29
- mustache_locals.merge!(front_matter)
26
+ mustache_locals[:yield] = yield if block_given?
27
+ mustache_locals[:content] = mustache_locals.fetch(:yield, '')
28
+
29
+ @output = ::Mustache.render(template, mustache_locals)
30
+ end
31
+
32
+ private
33
+
34
+ def assign_helper_methods! mustache_locals
35
+ mustache_locals.merge! Sinatra::MustacheHelper::METHODS.dup.delete_if{|k,v| mustache_locals.member?(k) }
36
+ end
37
+
38
+ def assign_instance_variables! mustache_locals, scope
39
+ scope.instance_variables.each do |instance_variable|
40
+ symbol = instance_variable.to_s.delete('@').to_sym
41
+ mustache_locals[symbol] = scope.instance_variable_get(instance_variable) unless mustache_locals.member?(symbol)
42
+ end
43
+ end
44
+
45
+ def assign_template_and_front_matter! mustache_locals, data
46
+ if yaml = data.match(/\A(\s*-{3}(.+)-{3}\s*)/m)
47
+ template = data.sub(yaml[1], '')
48
+ YAML.load_documents(yaml[2].strip) do |front_matter|
49
+ mustache_locals.merge! front_matter.delete_if{|k,v| mustache_locals.member?(k) }
30
50
  end
31
51
  else
32
52
  template = data
33
53
  end
34
-
35
- scope.instance_variables.each do |instance_variable|
36
- symbol = instance_variable.to_s.gsub('@','').to_sym
37
-
38
- unless mustache_locals.member?(symbol)
39
- mustache_locals[symbol] = scope.instance_variable_get(instance_variable)
40
- end
41
- end
42
-
43
- mustache_locals = Sinatra::MustacheHelper::METHODS.dup.merge(mustache_locals)
44
-
45
- mustache_locals[:yield] = block.nil? ? '' : yield
46
- mustache_locals[:content] = mustache_locals[:yield]
47
54
 
48
- @output = ::Mustache.render(template, mustache_locals)
55
+ template
49
56
  end
50
57
  end
51
58
 
@@ -9,14 +9,14 @@ Gem::Specification.new do |s|
9
9
  s.authors = ['Jason Campbell', 'Beat Richartz']
10
10
  s.email = ['attraccessor@gmail.com']
11
11
  s.homepage = 'http://github.com/beatrichartz/sinatra-mustache'
12
- s.summary = %q{Use Mustache in your Sinatra app without the extra view classes}
13
- s.description = %q{Use Mustache in your Sinatra app without the extra view classes}
12
+ s.summary = %q{Use Mustache in your Sinatra app without extra view classes}
13
+ s.description = %q{Use Mustache in your Sinatra app without extra view classes}
14
14
 
15
15
  s.rubyforge_project = "sinatra-mustache"
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.licenses = ["MIT"]
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency 'sinatra', '~> 1'
@@ -37,7 +37,7 @@ describe Tilt::MustacheTemplate do
37
37
 
38
38
  context 'methods of the scope' do
39
39
  let(:template) do
40
- Tilt::MustacheTemplate.new do |t|
40
+ Tilt::MustacheTemplate.new do |t|
41
41
  'Hello, I am {{ name.Moto.Tantra }} and these are my friends {{ friends.Hazy.Lazy.Crazy }}! Come and join us for a {{ sour_drink.Whiskey }} or just a {{ random_drink }}'
42
42
  end
43
43
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-mustache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jason Campbell
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-27 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: sinatra
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: mustache
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ~>
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ~>
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: tilt
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ~>
53
47
  - !ruby/object:Gem::Version
@@ -58,7 +52,6 @@ dependencies:
58
52
  type: :runtime
59
53
  prerelease: false
60
54
  version_requirements: !ruby/object:Gem::Requirement
61
- none: false
62
55
  requirements:
63
56
  - - ~>
64
57
  - !ruby/object:Gem::Version
@@ -69,7 +62,6 @@ dependencies:
69
62
  - !ruby/object:Gem::Dependency
70
63
  name: rspec
71
64
  requirement: !ruby/object:Gem::Requirement
72
- none: false
73
65
  requirements:
74
66
  - - ~>
75
67
  - !ruby/object:Gem::Version
@@ -77,7 +69,6 @@ dependencies:
77
69
  type: :development
78
70
  prerelease: false
79
71
  version_requirements: !ruby/object:Gem::Requirement
80
- none: false
81
72
  requirements:
82
73
  - - ~>
83
74
  - !ruby/object:Gem::Version
@@ -85,7 +76,6 @@ dependencies:
85
76
  - !ruby/object:Gem::Dependency
86
77
  name: rack-test
87
78
  requirement: !ruby/object:Gem::Requirement
88
- none: false
89
79
  requirements:
90
80
  - - ~>
91
81
  - !ruby/object:Gem::Version
@@ -93,12 +83,11 @@ dependencies:
93
83
  type: :development
94
84
  prerelease: false
95
85
  version_requirements: !ruby/object:Gem::Requirement
96
- none: false
97
86
  requirements:
98
87
  - - ~>
99
88
  - !ruby/object:Gem::Version
100
89
  version: '0'
101
- description: Use Mustache in your Sinatra app without the extra view classes
90
+ description: Use Mustache in your Sinatra app without extra view classes
102
91
  email:
103
92
  - attraccessor@gmail.com
104
93
  executables: []
@@ -106,10 +95,11 @@ extensions: []
106
95
  extra_rdoc_files: []
107
96
  files:
108
97
  - .gitignore
98
+ - .rspec
109
99
  - .travis.yml
110
100
  - Changelog.md
111
101
  - Gemfile
112
- - LISCENSE
102
+ - License.txt
113
103
  - README.md
114
104
  - Rakefile
115
105
  - lib/proxies/currystache.rb
@@ -129,29 +119,29 @@ files:
129
119
  - spec/views/needs_partial.mustache
130
120
  - spec/views/yaml.mustache
131
121
  homepage: http://github.com/beatrichartz/sinatra-mustache
132
- licenses: []
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
133
125
  post_install_message:
134
126
  rdoc_options: []
135
127
  require_paths:
136
128
  - lib
137
129
  required_ruby_version: !ruby/object:Gem::Requirement
138
- none: false
139
130
  requirements:
140
131
  - - ! '>='
141
132
  - !ruby/object:Gem::Version
142
133
  version: '0'
143
134
  required_rubygems_version: !ruby/object:Gem::Requirement
144
- none: false
145
135
  requirements:
146
136
  - - ! '>='
147
137
  - !ruby/object:Gem::Version
148
138
  version: '0'
149
139
  requirements: []
150
140
  rubyforge_project: sinatra-mustache
151
- rubygems_version: 1.8.25
141
+ rubygems_version: 2.1.11
152
142
  signing_key:
153
- specification_version: 3
154
- summary: Use Mustache in your Sinatra app without the extra view classes
143
+ specification_version: 4
144
+ summary: Use Mustache in your Sinatra app without extra view classes
155
145
  test_files:
156
146
  - spec/fake_template_helper.rb
157
147
  - spec/mustache_spec.rb