sinatra-mustache 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sinatra-mustache (0.0.1)
5
+ mustache (~> 0.11.2)
6
+ sinatra (~> 1.1.0)
7
+ tilt (= 1.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ mustache (0.11.2)
13
+ rack (1.2.1)
14
+ sinatra (1.1.0)
15
+ rack (~> 1.1)
16
+ tilt (~> 1.1)
17
+ tilt (1.1)
18
+ unicorn (1.0.0)
19
+ rack
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ mustache (~> 0.11.2)
26
+ sinatra (~> 1.1.0)
27
+ sinatra-mustache!
28
+ tilt (= 1.1)
29
+ unicorn
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Jason Campbell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ sinatra-mustache
2
+ ================
3
+
4
+ To simplify setting up [Sinatra][1] to use [Mustache][2] for it's templates
5
+
6
+ [Sinatra][1] is a pretty amazing little web framework, if you don't know much
7
+ about it you should take some time to [get to know it][4].
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.
12
+
13
+ Why?
14
+ ====
15
+
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..
19
+
20
+ Usage
21
+ =====
22
+
23
+ Try this on:
24
+
25
+ require 'sinatra/mustache'
26
+
27
+ class App < Sinatra::Base
28
+ set :views, 'templates' # totally optional
29
+ end
30
+
31
+ And then put your .mustache files in your app's views folder
32
+
33
+ Instance variables and locals are available to the template as well as yaml
34
+ front matter.
35
+
36
+ Caveat
37
+ ======
38
+
39
+ If you need the extra support of the ruby views used in the official Mustache
40
+ for Sinatra example this gem probably isn't for you.
41
+
42
+ [1]: http://www.sinatrarb.com/
43
+ [2]: http://mustache.github.com/
44
+ [3]: https://github.com/defunkt/mustache-sinatra-example
45
+ [4]: http://sinatra-book.gittr.com/
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/TODO.md ADDED
@@ -0,0 +1,3 @@
1
+ Soon:
2
+
3
+ * Tests
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Mustache
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'tilt/mustache_template'
2
+
3
+ module Sinatra
4
+ module Templates
5
+ def mustache(template, options={}, locals={})
6
+ render :mustache, template, options, locals
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'tilt'
2
+ require 'mustache'
3
+ require 'yaml'
4
+
5
+ module Tilt
6
+ class MustacheTemplate < Template
7
+ def initialize_engine
8
+ return if defined? ::Mustache
9
+ require_template_library 'mustache'
10
+ end
11
+
12
+ def prepare
13
+ ::Mustache.template_path = file.gsub(File.basename(file), '')
14
+ @engine = ::Mustache.new
15
+ @output = nil
16
+ end
17
+
18
+ def evaluate(scope, locals, &block)
19
+ if data =~ /^(\s*---(.+)---\s*)/m
20
+ yaml = $2.strip
21
+ template = data.sub($1, '')
22
+
23
+ YAML.each_document(yaml) do |front_matter|
24
+ # allows partials to override locals defined higher up
25
+ front_matter.delete_if { |key,value| locals.has_key?(key)}
26
+ locals.merge!(front_matter)
27
+ end
28
+ else
29
+ template = data
30
+ end
31
+
32
+ scope.instance_variables.each do |instance_variable|
33
+ locals[instance_variable.to_s.gsub('@','').to_sym] = scope.instance_variable_get(instance_variable)
34
+ end
35
+
36
+ locals[:yield] = block.nil? ? '' : yield
37
+ locals[:content] = locals[:yield]
38
+
39
+ @output ||= ::Mustache.render(template, locals)
40
+ end
41
+ end
42
+ register 'mustache', MustacheTemplate
43
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sinatra-mustache/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sinatra-mustache"
7
+ s.version = Sinatra::Mustache::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Jason Campbell']
10
+ s.email = ['jason@greatergood.cc']
11
+ s.homepage = 'http://github.com/jxson/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}
14
+
15
+ s.rubyforge_project = "sinatra-mustache"
16
+
17
+ s.files = `git ls-files`.split("\n")
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) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'sinatra', '~> 1.1.0'
23
+ s.add_dependency 'mustache', '~> 0.11.2'
24
+ s.add_dependency 'tilt', '1.1'
25
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-mustache
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jason Campbell
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-01 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: sinatra
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 0
34
+ version: 1.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: mustache
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 55
46
+ segments:
47
+ - 0
48
+ - 11
49
+ - 2
50
+ version: 0.11.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: tilt
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - "="
60
+ - !ruby/object:Gem::Version
61
+ hash: 13
62
+ segments:
63
+ - 1
64
+ - 1
65
+ version: "1.1"
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ description: Use Mustache in your Sinatra app without the extra view classes
69
+ email:
70
+ - jason@greatergood.cc
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LISCENSE
82
+ - README.md
83
+ - Rakefile
84
+ - TODO.md
85
+ - lib/sinatra-mustache/version.rb
86
+ - lib/sinatra/mustache.rb
87
+ - lib/tilt/mustache_template.rb
88
+ - sinatra-mustache.gemspec
89
+ has_rdoc: true
90
+ homepage: http://github.com/jxson/sinatra-mustache
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project: sinatra-mustache
119
+ rubygems_version: 1.3.7
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Use Mustache in your Sinatra app without the extra view classes
123
+ test_files: []
124
+