mustache_wax 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+ group :development do
3
+ gem "rspec", "~> 2.1.0"
4
+ gem "bundler", "~> 1.0.0"
5
+ gem "jeweler", "~> 1.5.1"
6
+ gem "rcov", ">= 0"
7
+ gem 'fakefs'
8
+ gem 'activesupport'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.0)
5
+ diff-lcs (1.1.2)
6
+ fakefs (0.3.1)
7
+ git (1.2.5)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.8.7)
13
+ rcov (0.9.9)
14
+ rspec (2.1.0)
15
+ rspec-core (~> 2.1.0)
16
+ rspec-expectations (~> 2.1.0)
17
+ rspec-mocks (~> 2.1.0)
18
+ rspec-core (2.1.0)
19
+ rspec-expectations (2.1.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.1.0)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ activesupport
28
+ bundler (~> 1.0.0)
29
+ fakefs
30
+ jeweler (~> 1.5.1)
31
+ rcov
32
+ rspec (~> 2.1.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Steven Soroka
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,71 @@
1
+ = mustache_wax
2
+
3
+ Automatically compiles *.html.mustache view files in app/views to /javascripts/mustache_templates.js so that you can easily access them from javascript.
4
+
5
+ == Installation with bundler
6
+
7
+ In your Gemfile:
8
+
9
+ gem 'mustache_wax'
10
+
11
+ Then
12
+
13
+ $ bundle install
14
+
15
+ in your application layout:
16
+
17
+ <%= javascript_include_tag 'mustache_templates' %>
18
+
19
+ If you are using Rails 3, it should automatically share the rake task
20
+ (as long as you're allowing bundler to require the gem, like above),
21
+ if you're using an older version of Rails, or don't want to require the gem in Gemfile,
22
+ then edit your Rakefile and add:
23
+
24
+ Dir["#{Gem.searcher.find('mustache_wax').full_gem_path}/lib/tasks/*.rake"].each { |ext| load ext }
25
+
26
+ If you are using capistrano for deployment, in your deploy.rb, add:
27
+
28
+ require 'mustache_wax/capistrano'
29
+
30
+ This will automatically compile your .html.mustache files on deploy.
31
+
32
+ If you are not using capistrano, you'll need to modify your deploy script to run:
33
+
34
+ rake mustache:generate_templates
35
+
36
+ == Usage
37
+
38
+ Anywhere in javascript, you can now use the mustache_templates variable to reference any template.
39
+
40
+ If you have a mustache view file named app/views/users/user_profile.html.mustache, you can now reference it
41
+ in javascript using:
42
+
43
+ mustache_templates['users/user_profile']
44
+
45
+ eg:
46
+
47
+ // render the user object with the template
48
+ var html = Mustache.to_html(mustache_templates['users/user_profile'], user_object);
49
+
50
+ == Compiling in development
51
+
52
+ You can trigger this manually with "rake mustache:generate_templates", but that shouldn't be necessary. Rails 2 & 3 will automatically recompile the templates on server start.
53
+ With passenger you'll need to touch tmp/restart.txt, or touch tmp/always_restart.txt to always restart on every request; it's slower, but perhaps useful if you're doing a lot of template changes.
54
+
55
+ == Contributing to mustache_wax
56
+
57
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
58
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
59
+ * Fork the project
60
+ * Start a feature/bugfix branch
61
+ * write specs to describe the bug or feature. This is important so I don't break it in a future version unintentionally.
62
+ * get specs passing
63
+ * Commit with a message that explains _why_ the change was necessary, not just what was changed.
64
+ * push and send me a pull request
65
+ * Please do not to mess with the Rakefile, or version.
66
+
67
+ == Copyright
68
+
69
+ Copyright (c) 2011 Steven Soroka. See LICENSE.txt for
70
+ further details.
71
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "mustache_wax"
16
+ gem.homepage = "http://github.com/ssoroka/mustache_wax"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Automatically compiles .html.mustache view files to /javascripts/mustache_templates.js}
19
+ gem.description = %Q{Automatically compiles *.html.mustache view files in app/views to /javascripts/mustache_templates.js}
20
+ gem.email = "ssoroka78@gmail.com"
21
+ gem.authors = ["Steven Soroka"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "mustache_wax #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,23 @@
1
+ load 'tasks/mustache_wax.rake' if defined?(Rake)
2
+
3
+ class MustacheWax
4
+ def self.generate_templates
5
+ templates = {}
6
+ template_files = Dir[File.join(%w(app views), '**', '*.html.mustache')]
7
+ template_files.each{|template_file|
8
+ template_name = template_file.gsub(/^.*app\/views\//, '').gsub(/\.html\.mustache$/, '')
9
+ template = File.read(template_file)
10
+ templates[template_name] = template
11
+ }
12
+
13
+ templates_json = ActiveSupport::JSON.encode(templates)
14
+ template_script = %(var mustache_templates = #{templates_json};)
15
+
16
+ File.open('public/javascripts/mustache_templates.js', 'w') do |f|
17
+ f.write template_script
18
+ end
19
+ end
20
+ end
21
+
22
+ # call immediately! :)
23
+ MustacheWax.generate_templates
@@ -0,0 +1,21 @@
1
+ require 'rubygems' unless defined?(Rubygems)
2
+ require 'capistrano' unless defined?(Capistrano)
3
+
4
+ unless Capistrano::Configuration.respond_to?(:instance)
5
+ abort "capistrano/mustache_wax requires Capistrano 2"
6
+ end
7
+
8
+ require 'mustache_wax' unless defined?(MustacheWax)
9
+
10
+ Capistrano::Configuration.instance(:must_exist).load do
11
+ after "deploy", "deploy:generate_templates"
12
+ after "deploy:migrations", "deploy:generate_templates"
13
+
14
+ namespace :deploy do
15
+ desc "generate mustache templates on the remote server"
16
+ task :generate_templates, :except => { :no_release => true } do
17
+ run "cd #{release_path} && rake mustache:generate_templates"
18
+ puts "Wrote new public/javascripts/mustache_templates.js from #{template_files.size} template(s)"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ namespace :mustache do
2
+ desc "Generate mustache_templates.js from .html.mustache view files"
3
+ task :generate_templates => [:environment] do
4
+ MustacheWax.generate_templates
5
+ end
6
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mustache_wax}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Steven Soroka"]
12
+ s.date = %q{2011-04-14}
13
+ s.description = %q{Automatically compiles *.html.mustache view files in app/views to /javascripts/mustache_templates.js}
14
+ s.email = %q{ssoroka78@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/mustache_wax.rb",
27
+ "lib/mustache_wax/capistrano.rb",
28
+ "lib/tasks/mustache_wax.rake",
29
+ "mustache_wax.gemspec",
30
+ "spec/mustache_wax_spec.rb",
31
+ "spec/spec_helper.rb",
32
+ "tasks/mustache/generate_templates.rake"
33
+ ]
34
+ s.homepage = %q{http://github.com/ssoroka/mustache_wax}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.7.2}
38
+ s.summary = %q{Automatically compiles .html.mustache view files to /javascripts/mustache_templates.js}
39
+ s.test_files = [
40
+ "spec/mustache_wax_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_development_dependency(%q<fakefs>, [">= 0"])
53
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ s.add_dependency(%q<fakefs>, [">= 0"])
60
+ s.add_dependency(%q<activesupport>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ s.add_dependency(%q<fakefs>, [">= 0"])
68
+ s.add_dependency(%q<activesupport>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MustacheWax" do
4
+ include FakeFS::SpecHelpers
5
+ before(:each) do
6
+ FileUtils.mkdir_p('app/views/something')
7
+ # create an example template that will be picked up by the generate_templates method
8
+ File.open('app/views/something/example.html.mustache', 'w') do |f|
9
+ f.write(%(<div>{{example}}</div>))
10
+ end
11
+ end
12
+
13
+ it 'should generate a mustache_templates.js from templates in app/views' do
14
+ MustacheWax.generate_templates
15
+ js_content = File.read('public/javascripts/mustache_templates.js')
16
+
17
+ js_content.should include %(<div>{{example}}</div>)
18
+ js_content.should =~ /^var mustache_templates = \{/
19
+ end
20
+
21
+ it 'should generate an empty template if there are no mustache files' do
22
+ FileUtils.rm 'app/views/something/example.html.mustache'
23
+ MustacheWax.generate_templates
24
+ js_content = File.read('public/javascripts/mustache_templates.js')
25
+
26
+ js_content.should == "var mustache_templates = {};"
27
+ end
28
+
29
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'mustache_wax'
5
+ require 'fakefs/spec_helpers'
6
+ require 'active_support'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+
14
+ end
@@ -0,0 +1,6 @@
1
+ namespace :mustache do
2
+ desc "Generate mustache_templates.js from .html.mustache view files"
3
+ task :generate_templates => [:environment] do
4
+ MustacheWax.generate_templates
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mustache_wax
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Steven Soroka
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 11
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 0
31
+ version: 2.1.0
32
+ version_requirements: *id001
33
+ name: rspec
34
+ prerelease: false
35
+ type: :development
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ version_requirements: *id002
49
+ name: bundler
50
+ prerelease: false
51
+ type: :development
52
+ - !ruby/object:Gem::Dependency
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 1
59
+ segments:
60
+ - 1
61
+ - 5
62
+ - 1
63
+ version: 1.5.1
64
+ version_requirements: *id003
65
+ name: jeweler
66
+ prerelease: false
67
+ type: :development
68
+ - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ version_requirements: *id004
79
+ name: rcov
80
+ prerelease: false
81
+ type: :development
82
+ - !ruby/object:Gem::Dependency
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ version_requirements: *id005
93
+ name: fakefs
94
+ prerelease: false
95
+ type: :development
96
+ - !ruby/object:Gem::Dependency
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ version_requirements: *id006
107
+ name: activesupport
108
+ prerelease: false
109
+ type: :development
110
+ description: Automatically compiles *.html.mustache view files in app/views to /javascripts/mustache_templates.js
111
+ email: ssoroka78@gmail.com
112
+ executables: []
113
+
114
+ extensions: []
115
+
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README
119
+ files:
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README
124
+ - Rakefile
125
+ - VERSION
126
+ - lib/mustache_wax.rb
127
+ - lib/mustache_wax/capistrano.rb
128
+ - lib/tasks/mustache_wax.rake
129
+ - mustache_wax.gemspec
130
+ - spec/mustache_wax_spec.rb
131
+ - spec/spec_helper.rb
132
+ - tasks/mustache/generate_templates.rake
133
+ homepage: http://github.com/ssoroka/mustache_wax
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.7.2
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Automatically compiles .html.mustache view files to /javascripts/mustache_templates.js
166
+ test_files:
167
+ - spec/mustache_wax_spec.rb
168
+ - spec/spec_helper.rb