kelredd-sinatra-helpers 0.1.1 → 0.1.2
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/README.rdoc +23 -0
- data/Rakefile +2 -2
- data/bin/sinatra +11 -0
- data/lib/sinatra_helpers.rb +1 -0
- data/lib/sinatra_helpers/generator.rb +3 -0
- data/lib/sinatra_helpers/generator/app.rb +53 -0
- data/lib/sinatra_helpers/generator/file_templates/Capfile.erb +2 -0
- data/lib/sinatra_helpers/generator/file_templates/Rakefile.erb +4 -0
- data/lib/sinatra_helpers/generator/file_templates/app.js.erb +1 -0
- data/lib/sinatra_helpers/generator/file_templates/app.rb.erb +27 -0
- data/lib/sinatra_helpers/generator/file_templates/app_controller.rb.erb +5 -0
- data/lib/sinatra_helpers/generator/file_templates/app_helpers.rb.erb +11 -0
- data/lib/sinatra_helpers/generator/file_templates/app_initializer.rb.erb +16 -0
- data/lib/sinatra_helpers/generator/file_templates/deploy.rb.erb +4 -0
- data/lib/sinatra_helpers/generator/file_templates/deploy_live.rb.erb +0 -0
- data/lib/sinatra_helpers/generator/file_templates/deploy_staging.rb.erb +0 -0
- data/lib/sinatra_helpers/generator/file_templates/gems.rb.erb +19 -0
- data/lib/sinatra_helpers/generator/file_templates/gitignore.erb +1 -0
- data/lib/sinatra_helpers/generator/file_templates/index.html.erb +0 -0
- data/lib/sinatra_helpers/generator/file_templates/initializers.rb.erb +6 -0
- data/lib/sinatra_helpers/generator/file_templates/layout +24 -0
- data/lib/sinatra_helpers/generator/file_templates/production.ru.erb +24 -0
- data/lib/sinatra_helpers/generator/file_templates/sprockets.yml.erb +7 -0
- data/lib/sinatra_helpers/generator/file_templates/web.css.erb +82 -0
- data/lib/sinatra_helpers/generator/template.rb +64 -0
- data/lib/sinatra_helpers/version.rb +1 -1
- metadata +26 -4
data/README.rdoc
CHANGED
@@ -4,6 +4,29 @@
|
|
4
4
|
|
5
5
|
This is a ruby gem with a bunch of helpers to make Sinatra more useful.
|
6
6
|
|
7
|
+
=== A Generator
|
8
|
+
|
9
|
+
I've written a generator for new Sinatra apps. Please note: I've written this generator suited for my needs and paradigms in writing Sinatra apps. It is written for me and comes AS IS. Use if you wish, but know that it conforms to what I like using in Sinatra apps, including:
|
10
|
+
|
11
|
+
* Most, if not all, of the helpers in this gem
|
12
|
+
* Gem configuration (via gemsconfig: http://github.com/kelredd/gemsconfig)
|
13
|
+
* Sprockets (via sprockets-sinatra: http://github.com/kelredd/sprockets-sinatra)
|
14
|
+
* Less (coming)
|
15
|
+
* Capistrano deployment scheme
|
16
|
+
* Source control with Git
|
17
|
+
* Erb (with generators from useful: http://github.com/kelredd/useful/tree/master/lib/useful/erb_helpers/)
|
18
|
+
* an App directory structure similar to Rails'
|
19
|
+
* Default layout that I like
|
20
|
+
* Rack::Cache using my configuration (see admin/production.ru)
|
21
|
+
* Rack::Flash
|
22
|
+
* Unit testing with Test::Unit (coming)
|
23
|
+
* BDD using Cucumber (coming)
|
24
|
+
|
25
|
+
If you don't like/want to use something that this generates, don't use the generator, or back out some generated code manually. Ok, enough about that. On to usage:
|
26
|
+
|
27
|
+
$ sinatra path/to/app
|
28
|
+
# will create the app structure in path/to/app
|
29
|
+
|
7
30
|
=== Environment Tests
|
8
31
|
|
9
32
|
Have environment tests like development? and production? available in your app code
|
data/Rakefile
CHANGED
@@ -14,8 +14,8 @@ spec = Gem::Specification.new do |s|
|
|
14
14
|
s.author = 'Kelly Redding'
|
15
15
|
s.email = 'kelly@kelredd.com'
|
16
16
|
s.homepage = 'http://github.com/kelredd/sinatra-helpers'
|
17
|
-
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
|
18
|
-
|
17
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{bin,lib}/**/*")
|
18
|
+
s.executables = ['sinatra']
|
19
19
|
|
20
20
|
s.add_dependency('kelredd-useful', '>= 0.2.0')
|
21
21
|
end
|
data/bin/sinatra
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sinatra_helpers/generator'
|
4
|
+
|
5
|
+
if ARGV[0]
|
6
|
+
app_path = ARGV[0].slice(0,1) == File::Separator ? ARGV[0] : File.join(%x{pwd}.strip, ARGV[0])
|
7
|
+
app = SinatraHelpers::Generator::App.new(app_path)
|
8
|
+
app.generate
|
9
|
+
else
|
10
|
+
puts "Please specify a name for your gem"
|
11
|
+
end
|
data/lib/sinatra_helpers.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module SinatraHelpers; end
|
4
|
+
|
5
|
+
module SinatraHelpers::Generator
|
6
|
+
|
7
|
+
class App
|
8
|
+
|
9
|
+
attr_reader :root_path, :name
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@root_path = File.dirname(path)
|
13
|
+
self.name = File.basename(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def name=(name)
|
17
|
+
@name = name.gsub(/([A-Z])([a-z])/, '-\1\2').sub(/^-/, '').downcase
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate
|
21
|
+
build_template(File.join(self.root_path, self.name), SinatraHelpers::Generator::TEMPLATE)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_template(root_path, dir_hash)
|
27
|
+
FileUtils.mkdir_p(root_path)
|
28
|
+
dir_hash.each do |k, v|
|
29
|
+
if v.kind_of?(::Hash)
|
30
|
+
build_template(File.join(root_path,k.to_s), v)
|
31
|
+
elsif v.kind_of?(::String)
|
32
|
+
build_template_file(root_path, k.to_s, v.to_s)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_template_file(root_path, erb_name, file_name)
|
38
|
+
source_file = File.join(File.dirname(__FILE__), "file_templates", erb_name)
|
39
|
+
output_file = File.join(root_path, file_name)
|
40
|
+
|
41
|
+
unless File.exists?(output_file)
|
42
|
+
if ['.erb'].include?(File.extname(source_file))
|
43
|
+
erb = ERB.new(File.read(source_file))
|
44
|
+
File.open(output_file, 'w') {|f| f << erb.result(binding) }
|
45
|
+
else
|
46
|
+
FileUtils.cp(source_file, output_file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
// TODO: put any application javascript code here
|
@@ -0,0 +1,27 @@
|
|
1
|
+
%w(yaml erb rubygems sinatra config/gems).each do |lib|
|
2
|
+
require lib
|
3
|
+
end
|
4
|
+
|
5
|
+
Gemsconfig::load if defined?(Gemsconfig)
|
6
|
+
require 'config/initializers'
|
7
|
+
|
8
|
+
# TODO: set your session cookie name here
|
9
|
+
use Rack::Session::Cookie, :key => '_sess'
|
10
|
+
use Rack::Flash
|
11
|
+
|
12
|
+
# Load in helpers
|
13
|
+
Dir[File.join(File.dirname(__FILE__), "app/helpers" ,"*.rb")].each do |file|
|
14
|
+
require "app/helpers/#{File.basename(file, ".rb")}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Load in models
|
18
|
+
Dir[File.join(File.dirname(__FILE__), "app/models" ,"*.rb")].each do |file|
|
19
|
+
require "app/models/#{File.basename(file, ".rb")}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Load in controllers
|
23
|
+
Dir[File.join(File.dirname(__FILE__), "app/controllers" ,"*.rb")].each do |file|
|
24
|
+
load File.join(File.dirname(__FILE__), 'app/controllers', File.basename(file))
|
25
|
+
end
|
26
|
+
|
27
|
+
set :views, File.join(File.dirname(__FILE__), 'app', 'views')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Config; end
|
2
|
+
module Config::Initializers; end
|
3
|
+
|
4
|
+
module Config::Initializers::App
|
5
|
+
def self.registered(app)
|
6
|
+
|
7
|
+
app.configure do
|
8
|
+
|
9
|
+
# TODO: put some initializer code in here
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Sinatra::Application.register Config::Initializers::App
|
File without changes
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require 'gemsconfig'
|
3
|
+
rescue LoadError => err
|
4
|
+
p " ** can't load gemsconfig. gem install kelredd-gemsconfig --source http://gems.github.com **"
|
5
|
+
end
|
6
|
+
|
7
|
+
Gemsconfig::init do |config|
|
8
|
+
|
9
|
+
config.gem 'kelredd-useful', :lib => 'useful/ruby_extensions', :source => 'http://gemcutter.org'
|
10
|
+
|
11
|
+
config.gem 'rack-flash', :lib => 'rack-flash', :source => 'http://gemcutter.org'
|
12
|
+
config.gem 'rack-cache', :lib => false, :source => 'http://gemcutter.org'
|
13
|
+
|
14
|
+
config.gem 'kelredd-sinatra-helpers', :lib => 'sinatra_helpers', :source => 'http://gemcutter.org'
|
15
|
+
|
16
|
+
config.gem 'sprockets'
|
17
|
+
config.gem 'kelredd-sprockets-sinatra', :lib => 'sprockets_sinatra', :source => 'http://gems.github.com'
|
18
|
+
|
19
|
+
end if defined?(Gemsconfig)
|
@@ -0,0 +1 @@
|
|
1
|
+
/log/*.log
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<title><%= @page_title %></title>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<% if @meta_description %>
|
8
|
+
<meta name="description" content="<%= @meta_description %>" />
|
9
|
+
<% end %>
|
10
|
+
<% if @meta_norobots %>
|
11
|
+
<meta name="robots" content="noindex,nofollow" />
|
12
|
+
<% end %>
|
13
|
+
<link rel="icon" type="image/png" href="/favicon.png"></link>
|
14
|
+
<%= stylesheet_link_tag :web, :media => "all" %>
|
15
|
+
<% unless @noscript %>
|
16
|
+
<%= sprockets_include_tag %>
|
17
|
+
<% end %>
|
18
|
+
</head>
|
19
|
+
<body class="body">
|
20
|
+
<%= yield %>
|
21
|
+
<% if production? %>
|
22
|
+
<% end %>
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
FileUtils.mkdir_p 'log' unless File.exists?('log')
|
2
|
+
log = File.new("log/production.log", "a+")
|
3
|
+
$stdout.reopen(log)
|
4
|
+
$stderr.reopen(log)
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'sinatra'
|
8
|
+
require 'app'
|
9
|
+
|
10
|
+
root_dir = File.dirname(__FILE__)
|
11
|
+
|
12
|
+
set :root, root_dir
|
13
|
+
set :app_file, File.join(root_dir, 'app.rb')
|
14
|
+
set :environment, :production
|
15
|
+
disable :run
|
16
|
+
|
17
|
+
require 'rack/cache'
|
18
|
+
|
19
|
+
use Rack::Cache,
|
20
|
+
:verbose => true,
|
21
|
+
:metastore => "file:#{File.join(root_dir, 'cache-rack', 'meta')}",
|
22
|
+
:entitystore => "file:#{File.join(root_dir, 'cache-rack', 'body')}"
|
23
|
+
|
24
|
+
run Sinatra::Application
|
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
/* some base styles */
|
15
|
+
UL {
|
16
|
+
margin: 0;
|
17
|
+
padding: 0;
|
18
|
+
list-style-image: none;
|
19
|
+
list-style-position: inside;
|
20
|
+
list-style-type:none;
|
21
|
+
}
|
22
|
+
UL.bulleted {
|
23
|
+
list-style-type: disc !important;
|
24
|
+
}
|
25
|
+
OL {
|
26
|
+
display: block;
|
27
|
+
list-style-type: decimal;
|
28
|
+
margin: 1em 0;
|
29
|
+
}
|
30
|
+
|
31
|
+
HTML {
|
32
|
+
font-size:10pt;
|
33
|
+
}
|
34
|
+
BODY {
|
35
|
+
width: 100%;
|
36
|
+
font-family: "Lucida Grande", Verdana, sans-serif;
|
37
|
+
font-size: 1em;
|
38
|
+
font-size-adjust:none;
|
39
|
+
font-variant: normal;
|
40
|
+
}
|
41
|
+
A, IMG, FORM, FIELDSET {
|
42
|
+
border: 0px none;
|
43
|
+
padding: 0;
|
44
|
+
margin: 0;
|
45
|
+
}
|
46
|
+
INPUT, SELECT, TEXTAREA, BUTTON {
|
47
|
+
margin: 0;
|
48
|
+
padding: .2em .3em;
|
49
|
+
font-family : 'Lucida Grande', sans-serif;
|
50
|
+
font-size: 9px;
|
51
|
+
font-size-adjust: none;
|
52
|
+
font-variant: normal;
|
53
|
+
}
|
54
|
+
INPUT[type="submit"],
|
55
|
+
INPUT[type="checkbox"], DIV.checkbox LABEL,
|
56
|
+
INPUT[type="radiobutton"] {
|
57
|
+
cursor: pointer;
|
58
|
+
vertical-align: middle;
|
59
|
+
}
|
60
|
+
INPUT[type="checkbox"] {
|
61
|
+
margin-right: .2em;
|
62
|
+
}
|
63
|
+
SELECT {
|
64
|
+
padding: 0;
|
65
|
+
}
|
66
|
+
|
67
|
+
/* IE fixes */
|
68
|
+
HTML, BODY {
|
69
|
+
height:100%;
|
70
|
+
}
|
71
|
+
|
72
|
+
/* Add the style below to a container element that contains floats - will cause the container
|
73
|
+
to expand to the height of the floats */
|
74
|
+
.clearfix:after {
|
75
|
+
content: ".";
|
76
|
+
display: block;
|
77
|
+
height: 0;
|
78
|
+
clear: both;
|
79
|
+
visibility: hidden;
|
80
|
+
}
|
81
|
+
/* Hides from IE-mac \*/
|
82
|
+
* html .clearfix {height: 1%;}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module SinatraHelpers; end
|
2
|
+
|
3
|
+
module SinatraHelpers::Generator
|
4
|
+
|
5
|
+
TEMPLATE = {
|
6
|
+
'app.rb.erb' => 'app.rb',
|
7
|
+
'Capfile.erb' => 'Capfile',
|
8
|
+
'Rakefile.erb' => 'Rakefile',
|
9
|
+
'gitignore.erb' => '.gitignore',
|
10
|
+
|
11
|
+
:admin => {
|
12
|
+
'production.ru.erb' => 'production.ru'
|
13
|
+
},
|
14
|
+
|
15
|
+
:app => {
|
16
|
+
:controllers => {
|
17
|
+
'app_controller.rb.erb' => 'app.rb'
|
18
|
+
},
|
19
|
+
:helpers => {
|
20
|
+
'app_helpers.rb.erb' => 'app_helpers.rb'
|
21
|
+
},
|
22
|
+
:javascripts => {
|
23
|
+
'app.js.erb' => 'app.js'
|
24
|
+
},
|
25
|
+
:models => {},
|
26
|
+
:stylesheets => {},
|
27
|
+
:views => {
|
28
|
+
'layout' => 'layout.erb',
|
29
|
+
:app => {
|
30
|
+
'index.html.erb' => 'index.html.erb'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
},
|
34
|
+
|
35
|
+
:config => {
|
36
|
+
:deploy => {
|
37
|
+
'deploy_live.rb.erb' => 'live.rb',
|
38
|
+
'deploy_staging.rb.erb' => 'staging.rb'
|
39
|
+
},
|
40
|
+
'deploy.rb.erb' => 'deploy.rb',
|
41
|
+
'gems.rb.erb' => 'gems.rb',
|
42
|
+
:initializers => {
|
43
|
+
'app_initializer.rb.erb' => 'app.rb'
|
44
|
+
},
|
45
|
+
'initializers.rb.erb' => 'initializers.rb',
|
46
|
+
'sprockets.yml.erb' => 'sprockets.yml'
|
47
|
+
},
|
48
|
+
|
49
|
+
:log => {},
|
50
|
+
|
51
|
+
:public => {
|
52
|
+
:images => {},
|
53
|
+
:javascripts => {},
|
54
|
+
:stylesheets => {
|
55
|
+
'web.css.erb' => 'web.css'
|
56
|
+
}
|
57
|
+
},
|
58
|
+
|
59
|
+
:vendor => {
|
60
|
+
:javascripts => {}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kelredd-sinatra-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-11 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
version:
|
25
25
|
description:
|
26
26
|
email: kelly@kelredd.com
|
27
|
-
executables:
|
28
|
-
|
27
|
+
executables:
|
28
|
+
- sinatra
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
@@ -33,9 +33,31 @@ extra_rdoc_files:
|
|
33
33
|
files:
|
34
34
|
- README.rdoc
|
35
35
|
- Rakefile
|
36
|
+
- bin/sinatra
|
36
37
|
- lib/sinatra_helpers/environment_tests.rb
|
37
38
|
- lib/sinatra_helpers/erb/partials.rb
|
38
39
|
- lib/sinatra_helpers/erb.rb
|
40
|
+
- lib/sinatra_helpers/generator/app.rb
|
41
|
+
- lib/sinatra_helpers/generator/file_templates/app.js.erb
|
42
|
+
- lib/sinatra_helpers/generator/file_templates/app.rb.erb
|
43
|
+
- lib/sinatra_helpers/generator/file_templates/app_controller.rb.erb
|
44
|
+
- lib/sinatra_helpers/generator/file_templates/app_helpers.rb.erb
|
45
|
+
- lib/sinatra_helpers/generator/file_templates/app_initializer.rb.erb
|
46
|
+
- lib/sinatra_helpers/generator/file_templates/Capfile.erb
|
47
|
+
- lib/sinatra_helpers/generator/file_templates/deploy.rb.erb
|
48
|
+
- lib/sinatra_helpers/generator/file_templates/deploy_live.rb.erb
|
49
|
+
- lib/sinatra_helpers/generator/file_templates/deploy_staging.rb.erb
|
50
|
+
- lib/sinatra_helpers/generator/file_templates/gems.rb.erb
|
51
|
+
- lib/sinatra_helpers/generator/file_templates/gitignore.erb
|
52
|
+
- lib/sinatra_helpers/generator/file_templates/index.html.erb
|
53
|
+
- lib/sinatra_helpers/generator/file_templates/initializers.rb.erb
|
54
|
+
- lib/sinatra_helpers/generator/file_templates/layout
|
55
|
+
- lib/sinatra_helpers/generator/file_templates/production.ru.erb
|
56
|
+
- lib/sinatra_helpers/generator/file_templates/Rakefile.erb
|
57
|
+
- lib/sinatra_helpers/generator/file_templates/sprockets.yml.erb
|
58
|
+
- lib/sinatra_helpers/generator/file_templates/web.css.erb
|
59
|
+
- lib/sinatra_helpers/generator/template.rb
|
60
|
+
- lib/sinatra_helpers/generator.rb
|
39
61
|
- lib/sinatra_helpers/version.rb
|
40
62
|
- lib/sinatra_helpers.rb
|
41
63
|
has_rdoc: true
|