this_town 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in this_town.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeremy Stephens
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # this_town
2
+
3
+ `this_town` is a RubyGem generator for Sinatra applications that use the
4
+ following libraries:
5
+
6
+ * database: [sequel](http://sequel.rubyforge.org/)
7
+ * templates: [mustache](https://github.com/defunkt/mustache)
8
+ * testing: [test-unit](http://test-unit.rubyforge.org/) and [rack-test](https://github.com/brynary/rack-test)
9
+ * mocking: [mocha](http://gofreerange.com/mocha/docs/)
10
+ * automation: [guard](https://github.com/guard/guard)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'this_town'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install this_town
25
+
26
+ ## Usage
27
+
28
+ this_town foo # Generates project called foo
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
37
+
38
+ > This town is a quiet town<br/>
39
+ > Or a riot town like this town<br/>
40
+ > This town is a love-you town<br/>
41
+ > And a shove-you-down and push-you-'round town<br/>
42
+ > -- Frank Sinatra
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/this_town ADDED
@@ -0,0 +1,12 @@
1
+ # vim: set filetype=ruby:
2
+ require 'this_town'
3
+
4
+ if ARGV.length != 1
5
+ $stderr.puts "Syntax: #{File.basename($0)} <path>"
6
+ $stderr.puts " #{File.basename($0)} --version"
7
+ elsif %w{-v --version}.include? ARGV.first
8
+ puts "#{File.basename($0)} #{ThisTown::VERSION}"
9
+ exit(0)
10
+ else
11
+ ThisTown::Generator.new(ARGV.first).run
12
+ end
@@ -0,0 +1,122 @@
1
+ module ThisTown
2
+ class Generator
3
+ TEMPLATES_PATH = File.expand_path(File.join(File.dirname(__FILE__),
4
+ "..", "..", "templates"))
5
+
6
+ def initialize(destination_root)
7
+ @destination_root = destination_root
8
+ base_name = File.basename(@destination_root)
9
+
10
+ @gem_name = base_name
11
+ constant_name = base_name.split('_').map { |p|
12
+ p[0..0].upcase + p[1..-1]
13
+ }.join
14
+ if constant_name =~ /-/
15
+ constant_name = constant_name.split('-').map { |q|
16
+ q[0..0].upcase + q[1..-1]
17
+ }.join('::')
18
+ end
19
+ constant_array = constant_name.split('::')
20
+
21
+ git_user_name = `git config user.name`.chomp
22
+ git_user_email = `git config user.email`.chomp
23
+ author =
24
+ if git_user_name.empty?
25
+ "TODO: Write your name"
26
+ else
27
+ git_user_name
28
+ end
29
+ email =
30
+ if git_user_email.empty?
31
+ "TODO: Write your email address"
32
+ else
33
+ git_user_email
34
+ end
35
+
36
+ @template_options = {
37
+ :gem_name => @gem_name, :constant_name => constant_name,
38
+ :constant_array => constant_array, :author => author,
39
+ :email => email
40
+ }
41
+ end
42
+
43
+ def run
44
+ directory "db/migrate"
45
+ directory "templates"
46
+
47
+ # root
48
+ root_templates = %w{Gemfile LICENSE.txt README.md Rakefile config.ru}
49
+ root_templates.each do |template_path|
50
+ template(template_path)
51
+ end
52
+ template "newgem.gemspec", "#{@gem_name}.gemspec"
53
+ file "Guardfile"
54
+ file "gitignore", ".gitignore"
55
+
56
+ # lib
57
+ template "lib/newgem.rb", "lib/#{@gem_name}.rb"
58
+ template "lib/newgem/version.rb", "lib/#{@gem_name}/version.rb"
59
+ template "lib/newgem/application.rb", "lib/#{@gem_name}/application.rb"
60
+ directory "lib/#{@gem_name}/views"
61
+
62
+ # config
63
+ template "config/database.yml"
64
+
65
+ # test
66
+ template "test/helper.rb"
67
+ template "test/unit/test_application.rb"
68
+
69
+ # public
70
+ fetch "http://code.jquery.com/jquery-latest.min.js", "public/jquery.min.js"
71
+ file "public/jquery.mustache.min.js"
72
+
73
+ Dir.chdir(@destination_root) do
74
+ `git init && git add .`
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def template(template_path, destination_path = template_path)
81
+ out_path = prepare_destination(destination_path)
82
+ in_path = full_template_path("#{template_path}.erb")
83
+
84
+ template = Template.new(in_path, @template_options)
85
+ output = template.result
86
+ File.open(out_path, 'w') { |f| f.write(output) }
87
+ end
88
+
89
+ def file(template_path, destination_path = template_path)
90
+ out_path = prepare_destination(destination_path)
91
+ in_path = full_template_path(template_path)
92
+
93
+ FileUtils.cp(in_path, out_path)
94
+ end
95
+
96
+ def fetch(url, destination_path)
97
+ out_path = prepare_destination(destination_path)
98
+ open(url) do |u|
99
+ File.open(out_path, 'w') do |f|
100
+ f.write(u.read)
101
+ end
102
+ end
103
+ end
104
+
105
+ def full_template_path(template_path)
106
+ File.expand_path(template_path, TEMPLATES_PATH)
107
+ end
108
+
109
+ def prepare_destination(destination_path)
110
+ out_path = File.expand_path(destination_path, @destination_root)
111
+ if File.exists?(out_path)
112
+ raise "file already exists: #{out_path}"
113
+ end
114
+ directory(File.dirname(out_path))
115
+ out_path
116
+ end
117
+
118
+ def directory(path)
119
+ FileUtils.mkdir_p(File.expand_path(path, @destination_root))
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,43 @@
1
+ module ThisTown
2
+ class Template
3
+ def initialize(path, options)
4
+ @erb = ERB.new(File.read(path), nil, "-", "@output")
5
+ @options = options
6
+ end
7
+
8
+ def result
9
+ @erb.result(binding)
10
+ end
11
+
12
+ def code
13
+ constant_array.each_with_index do |constant, i|
14
+ @output << ((' ' * i) + "module #{constant}\n")
15
+ end
16
+
17
+ # Pull a switcheroo to get the content
18
+ old_output = @output
19
+ @output = ""
20
+ yield
21
+ content = @output
22
+ @output = old_output
23
+
24
+ # Indent each line of content
25
+ indent_num = constant_array.size - 1
26
+ content.each_line do |line|
27
+ @output << ((' ' * indent_num) + line)
28
+ end
29
+
30
+ (constant_array.size - 1).downto(0) do |i|
31
+ @output << ((' ' * i) + "end\n")
32
+ end
33
+ end
34
+
35
+ def method_missing(name, *args, &block)
36
+ if @options.has_key?(name)
37
+ @options[name]
38
+ else
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module ThisTown
2
+ VERSION = "0.0.1"
3
+ end
data/lib/this_town.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+ require 'open-uri'
4
+
5
+ module ThisTown
6
+ end
7
+
8
+ require 'this_town/version'
9
+ require 'this_town/template'
10
+ require 'this_town/generator'
@@ -0,0 +1,23 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in <%= gem_name %>.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'sqlite3'
8
+ gem 'test-unit'
9
+ gem 'rack-test'
10
+ gem 'mocha'
11
+ gem 'rake'
12
+
13
+ # Guard gems
14
+ gem 'guard'
15
+ gem 'guard-test'
16
+ gem 'guard-rack'
17
+ gem 'guard-bundler'
18
+ gem 'guard-shell'
19
+ gem 'rb-inotify', '~> 0.8.8', :require => false
20
+ gem 'rb-fsevent', :require => false
21
+ gem 'rb-fchange', :require => false
22
+ gem 'wdm', :platforms => [:mswin, :mingw], :require => false
23
+ end
@@ -0,0 +1,33 @@
1
+ guard 'rack' do
2
+ watch('Gemfile.lock')
3
+ watch(%r{^(?:lib|db/migrate)/(?:[^/]+/)*[^.][^/]*\.rb$})
4
+ watch('config/database.yml')
5
+ watch('config.ru')
6
+ end
7
+
8
+ guard 'test' do
9
+ watch(%r{^lib/((?:[^/]+\/)*)(.+)\.rb$}) do |m|
10
+ "test/unit/#{m[1]}test_#{m[2]}.rb"
11
+ end
12
+ watch(%r{^test/((?:[^/]+\/)*)test.+\.rb$})
13
+ watch('test/helper.rb') { 'test' }
14
+ watch(%r{^templates/(?:([^/]+)\/)?.+\.mustache}) do |m|
15
+ if m[1]
16
+ "test/unit/extensions/test_#{m[1]}.rb"
17
+ else
18
+ 'test/unit/test_application.rb'
19
+ end
20
+ end
21
+ end
22
+
23
+ guard 'bundler' do
24
+ watch('Gemfile')
25
+ watch(/^.+\.gemspec/)
26
+ end
27
+
28
+ guard 'shell' do
29
+ watch(%r{db/migrate/\d+_.+.rb}) do |m|
30
+ `bundle exec rake db:migrate[test]`
31
+ `bundle exec rake db:migrate[development]`
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) <%= Time.now.year %> <%= author %>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # <%= constant_name %>
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem '<%= gem_name %>'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install <%= gem_name %>
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,51 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :environment, :env do |cmd, args|
5
+ ENV["RACK_ENV"] = args[:env] || "development"
6
+ require "./lib/<%= gem_name %>"
7
+ end
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.libs << "test"
11
+ t.pattern = 'test/**/test*.rb'
12
+ end
13
+ task :default => :test
14
+
15
+ namespace :db do
16
+ desc "Run database migrations"
17
+ task :migrate, :env do |cmd, args|
18
+ env = args[:env] || "development"
19
+ Rake::Task['environment'].invoke(env)
20
+
21
+ unless Dir.glob("db/migrate/*.rb").empty?
22
+ require 'sequel/extensions/migration'
23
+ Sequel::Migrator.apply(<%= constant_name %>::Database, "db/migrate")
24
+ end
25
+ end
26
+
27
+ desc "Rollback the database"
28
+ task :rollback, :env do |cmd, args|
29
+ env = args[:env] || "development"
30
+ Rake::Task['environment'].invoke(env)
31
+
32
+ unless Dir.glob("db/migrate/*.rb").empty?
33
+ require 'sequel/extensions/migration'
34
+ version = (row = <%= constant_name %>::Database[:schema_info].first) ? row[:version] : nil
35
+ Sequel::Migrator.apply(<%= constant_name %>::Database, "db/migrate", version - 1)
36
+ end
37
+ end
38
+
39
+ desc "Nuke the database (drop all tables)"
40
+ task :nuke, :env do |cmd, args|
41
+ env = args[:env] || "development"
42
+ Rake::Task['environment'].invoke(env)
43
+
44
+ <%= constant_name %>::Database.tables.each do |table|
45
+ <%= constant_name %>::Database.run("DROP TABLE #{table}")
46
+ end
47
+ end
48
+
49
+ desc "Reset the database"
50
+ task :reset, [:env] => [:nuke, :migrate]
51
+ end
@@ -0,0 +1,8 @@
1
+ test:
2
+ adapter: sqlite
3
+ database: <%%= <%= constant_name %>::Root %>/db/test.db
4
+
5
+ development:
6
+ adapter: sqlite
7
+ database: <%%= <%= constant_name %>::Root %>/db/development.db
8
+ logger: _stderr_
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
5
+
6
+ require './lib/<%= gem_name %>'
7
+ run <%= constant_name %>::Application
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,17 @@
1
+ <%- code do -%>
2
+ class Application < Sinatra::Base
3
+ register Mustache::Sinatra
4
+
5
+ set :root, Root.to_s
6
+ set :mustache, {
7
+ :templates => (Root + 'templates').to_s,
8
+ :views => (Root + 'lib' + '<%= gem_name %>' + 'views').to_s,
9
+ :namespace => <%= constant_name %>
10
+ }
11
+ enable :reload_templates if development?
12
+
13
+ get "/" do
14
+ "sup?"
15
+ end
16
+ end
17
+ <%- end -%>
@@ -0,0 +1,3 @@
1
+ <%- code do -%>
2
+ VERSION = "0.0.1"
3
+ <%- end -%>
@@ -0,0 +1,25 @@
1
+ require 'sinatra/base'
2
+ require 'mustache/sinatra'
3
+ require 'sequel'
4
+ require 'erb'
5
+ require 'yaml'
6
+ require 'pathname'
7
+ require 'logger'
8
+
9
+ <%- code do -%>
10
+ Root = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path
11
+ Env = ENV['RACK_ENV'] || 'development'
12
+
13
+ config_path = Root + 'config' + 'database.yml'
14
+ config_tmpl = ERB.new(File.read(config_path))
15
+ config_tmpl.filename = config_path.to_s
16
+ config = YAML.load(config_tmpl.result(binding))[Env]
17
+ if config['logger']
18
+ file = config['logger']
19
+ config['logger'] = Logger.new(file == '_stderr_' ? STDERR : file)
20
+ end
21
+ Database = Sequel.connect(config)
22
+ <%- end -%>
23
+
24
+ require "<%= gem_name %>/version"
25
+ require "<%= gem_name %>/application"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require '<%= gem_name %>/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = <%= gem_name.inspect %>
8
+ gem.version = <%= constant_name %>::VERSION
9
+ gem.authors = [<%= author.inspect %>]
10
+ gem.email = [<%= email.inspect %>]
11
+ gem.description = %q{TODO: Write a gem description}
12
+ gem.summary = %q{TODO: Write a gem summary}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'sinatra'
21
+ gem.add_dependency 'sequel'
22
+ gem.add_dependency 'mustache'
23
+ end
@@ -0,0 +1,6 @@
1
+ /*
2
+ Shameless port of a shameless port
3
+ @defunkt => @janl => @aq
4
+
5
+ See http://github.com/defunkt/mustache for more info.
6
+ */(function(e){(function(e,t){typeof exports=="object"&&exports?module.exports=t:typeof define=="function"&&define.amd?define(t):e.Mustache=t})(this,function(){function f(e,t){return u.call(e,t)}function l(e){return!f(r,e)}function h(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function d(e){return String(e).replace(/[&<>"'\/]/g,function(e){return p[e]})}function v(e){this.string=e,this.tail=e,this.pos=0}function m(e,t){this.view=e,this.parent=t,this._cache={}}function g(){this.clearCache()}function y(t,n,r,i){var s="",o,u,a;for(var f=0,l=t.length;f<l;++f){o=t[f],u=o[1];switch(o[0]){case"#":a=r.lookup(u);if(typeof a=="object")if(c(a))for(var h=0,p=a.length;h<p;++h)s+=y(o[4],n,r.push(a[h]),i);else a&&(s+=y(o[4],n,r.push(a),i));else if(typeof a=="function"){var d=i==null?null:i.slice(o[3],o[5]);a=a.call(r.view,d,function(e){return n.render(e,r)}),a!=null&&(s+=a)}else a&&(s+=y(o[4],n,r,i));break;case"^":a=r.lookup(u);if(!a||c(a)&&a.length===0)s+=y(o[4],n,r,i);break;case">":a=n.getPartial(u),typeof a=="function"&&(s+=a(r));break;case"&":a=r.lookup(u),a!=null&&(s+=a);break;case"name":a=r.lookup(u),a!=null&&(s+=e.escape(a));break;case"text":s+=u}}return s}function b(e){var t=[],n=t,r=[],i;for(var s=0,o=e.length;s<o;++s){i=e[s];switch(i[0]){case"#":case"^":r.push(i),n.push(i),n=i[4]=[];break;case"/":var u=r.pop();u[5]=i[2],n=r.length>0?r[r.length-1][4]:t;break;default:n.push(i)}}return t}function w(e){var t=[],n,r;for(var i=0,s=e.length;i<s;++i)n=e[i],n&&(n[0]==="text"&&r&&r[0]==="text"?(r[1]+=n[1],r[3]=n[3]):(r=n,t.push(n)));return t}function E(e){return[new RegExp(h(e[0])+"\\s*"),new RegExp("\\s*"+h(e[1]))]}var e={};e.name="mustache.js",e.version="0.7.2",e.tags=["{{","}}"],e.Scanner=v,e.Context=m,e.Writer=g;var t=/\s*/,n=/\s+/,r=/\S/,i=/\s*=/,s=/\s*\}/,o=/#|\^|\/|>|\{|&|=|!/,u=RegExp.prototype.test,a=Object.prototype.toString,c=Array.isArray||function(e){return a.call(e)==="[object Array]"},p={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};e.escape=d,v.prototype.eos=function(){return this.tail===""},v.prototype.scan=function(e){var t=this.tail.match(e);return t&&t.index===0?(this.tail=this.tail.substring(t[0].length),this.pos+=t[0].length,t[0]):""},v.prototype.scanUntil=function(e){var t,n=this.tail.search(e);switch(n){case-1:t=this.tail,this.pos+=this.tail.length,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,n),this.tail=this.tail.substring(n),this.pos+=n}return t},m.make=function(e){return e instanceof m?e:new m(e)},m.prototype.push=function(e){return new m(e,this)},m.prototype.lookup=function(e){var t=this._cache[e];if(!t){if(e==".")t=this.view;else{var n=this;while(n){if(e.indexOf(".")>0){t=n.view;var r=e.split("."),i=0;while(t&&i<r.length)t=t[r[i++]]}else t=n.view[e];if(t!=null)break;n=n.parent}}this._cache[e]=t}return typeof t=="function"&&(t=t.call(this.view)),t},g.prototype.clearCache=function(){this._cache={},this._partialCache={}},g.prototype.compile=function(t,n){var r=this._cache[t];if(!r){var i=e.parse(t,n);r=this._cache[t]=this.compileTokens(i,t)}return r},g.prototype.compilePartial=function(e,t,n){var r=this.compile(t,n);return this._partialCache[e]=r,r},g.prototype.getPartial=function(e){return!(e in this._partialCache)&&this._loadPartial&&this.compilePartial(e,this._loadPartial(e)),this._partialCache[e]},g.prototype.compileTokens=function(e,t){var n=this;return function(r,i){if(i)if(typeof i=="function")n._loadPartial=i;else for(var s in i)n.compilePartial(s,i[s]);return y(e,n,m.make(r),t)}},g.prototype.render=function(e,t,n){return this.compile(e)(t,n)},e.parse=function(r,u){function y(){if(m&&!g)while(d.length)delete p[d.pop()];else d=[];m=!1,g=!1}r=r||"",u=u||e.tags,typeof u=="string"&&(u=u.split(n));if(u.length!==2)throw new Error("Invalid tags: "+u.join(", "));var a=E(u),f=new v(r),c=[],p=[],d=[],m=!1,g=!1,S,x,T,N,C;while(!f.eos()){S=f.pos,T=f.scanUntil(a[0]);if(T)for(var k=0,L=T.length;k<L;++k)N=T.charAt(k),l(N)?d.push(p.length):g=!0,p.push(["text",N,S,S+1]),S+=1,N=="\n"&&y();if(!f.scan(a[0]))break;m=!0,x=f.scan(o)||"name",f.scan(t),x==="="?(T=f.scanUntil(i),f.scan(i),f.scanUntil(a[1])):x==="{"?(T=f.scanUntil(new RegExp("\\s*"+h("}"+u[1]))),f.scan(s),f.scanUntil(a[1]),x="&"):T=f.scanUntil(a[1]);if(!f.scan(a[1]))throw new Error("Unclosed tag at "+f.pos);C=[x,T,S,f.pos],p.push(C);if(x==="#"||x==="^")c.push(C);else if(x==="/"){if(c.length===0)throw new Error('Unopened section "'+T+'" at '+S);var A=c.pop();if(A[1]!==T)throw new Error('Unclosed section "'+A[1]+'" at '+S)}else if(x==="name"||x==="{"||x==="&")g=!0;else if(x==="="){u=T.split(n);if(u.length!==2)throw new Error("Invalid tags at "+S+": "+u.join(", "));a=E(u)}}var A=c.pop();if(A)throw new Error('Unclosed section "'+A[1]+'" at '+f.pos);return p=w(p),b(p)};var S=new g;return e.clearCache=function(){return S.clearCache()},e.compile=function(e,t){return S.compile(e,t)},e.compilePartial=function(e,t,n){return S.compilePartial(e,t,n)},e.compileTokens=function(e,t){return S.compileTokens(e,t)},e.render=function(e,t,n){return S.render(e,t,n)},e.to_html=function(t,n,r,i){var s=e.render(t,n,r);if(typeof i!="function")return s;i(s)},e}()),e.mustache=function(e,t,n){return Mustache.render(e,t,n)},e.fn.mustache=function(t,n){return e(this).map(function(r,i){var s=e.trim(e(i).html()),o=e.mustache(s,t,n);return e(o).get()})}})(jQuery);
@@ -0,0 +1,27 @@
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
+
11
+ require 'test/unit'
12
+ require 'mocha/setup'
13
+ require 'rack/test'
14
+
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+ require '<%= gem_name %>'
18
+
19
+ class SequenceHelper
20
+ def initialize(name)
21
+ @seq = sequence(name)
22
+ end
23
+
24
+ def <<(expectation)
25
+ expectation.in_sequence(@seq)
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ class TestApplication < Test::Unit::TestCase
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ <%= constant_name %>::Application
8
+ end
9
+
10
+ test "index" do
11
+ get '/'
12
+ assert last_response.ok?
13
+ assert_equal "sup?", last_response.body
14
+ end
15
+ end
data/this_town.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'this_town/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "this_town"
8
+ gem.version = ThisTown::VERSION
9
+ gem.authors = ["Jeremy Stephens"]
10
+ gem.email = ["jeremy.f.stephens@vanderbilt.edu"]
11
+ gem.description = %q{Gem generator for Sinatra applications that use the following libraries: sequel, mustache, test-unit, rack-test, mocha, guard}
12
+ gem.summary = %q{Gem generator for Sinatra applications}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: this_town
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Stephens
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Gem generator for Sinatra applications that use the following libraries:
15
+ sequel, mustache, test-unit, rack-test, mocha, guard'
16
+ email:
17
+ - jeremy.f.stephens@vanderbilt.edu
18
+ executables:
19
+ - this_town
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/this_town
29
+ - lib/this_town.rb
30
+ - lib/this_town/generator.rb
31
+ - lib/this_town/template.rb
32
+ - lib/this_town/version.rb
33
+ - templates/Gemfile.erb
34
+ - templates/Guardfile
35
+ - templates/LICENSE.txt.erb
36
+ - templates/README.md.erb
37
+ - templates/Rakefile.erb
38
+ - templates/config.ru.erb
39
+ - templates/config/database.yml.erb
40
+ - templates/gitignore
41
+ - templates/lib/newgem.rb.erb
42
+ - templates/lib/newgem/application.rb.erb
43
+ - templates/lib/newgem/version.rb.erb
44
+ - templates/newgem.gemspec.erb
45
+ - templates/public/jquery.mustache.min.js
46
+ - templates/test/helper.rb.erb
47
+ - templates/test/unit/test_application.rb.erb
48
+ - this_town.gemspec
49
+ homepage: ''
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Gem generator for Sinatra applications
73
+ test_files: []