sinatra-effigy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +76 -0
- data/VERSION +1 -1
- data/lib/sinatra/effigy.rb +11 -4
- data/sinatra-effigy.gemspec +8 -2
- metadata +7 -4
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Dan Croak
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
Sinatra Effigy
|
2
|
+
==============
|
3
|
+
|
4
|
+
An Effigy extension for Sinatra. HTML in .html files. Ruby in .rb files.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Install the gem:
|
10
|
+
|
11
|
+
sudo gem install sinatra-effigy
|
12
|
+
|
13
|
+
Create your Sinatra app:
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'sinatra'
|
17
|
+
require 'sinatra/effigy'
|
18
|
+
|
19
|
+
get '/jobs/:id' do |id|
|
20
|
+
effigy :job, Job.find(id)
|
21
|
+
end
|
22
|
+
|
23
|
+
Create your template (fresh from a designer?) at /templates/job.html:
|
24
|
+
|
25
|
+
<!DOCTYPE html>
|
26
|
+
<html>
|
27
|
+
<head>
|
28
|
+
<title>Web Designer at thoughtbot</title>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<h1>Web Designer</h1>
|
32
|
+
<h2><a href="http://example.com">thoughtbot</a></h2>
|
33
|
+
<h3>Boston or New York</h3>
|
34
|
+
|
35
|
+
<p>Graphic design, typography, CSS, HTML.</p>
|
36
|
+
|
37
|
+
<h3>Apply</h3>
|
38
|
+
<p>Please contact jobs@example.com</p>
|
39
|
+
</body>
|
40
|
+
</html>
|
41
|
+
|
42
|
+
Create a view at /views/job.rb that responds to #transform:
|
43
|
+
|
44
|
+
class JobView < Effigy::View
|
45
|
+
attr_reader :job
|
46
|
+
|
47
|
+
def initialize(*locals)
|
48
|
+
@job = locals.first
|
49
|
+
end
|
50
|
+
|
51
|
+
def transform
|
52
|
+
f('title').text("#{job.position} at #{job.company}")
|
53
|
+
f('h1').text(job.position)
|
54
|
+
f('h2 a').attr(:href => job.company_url).
|
55
|
+
text(job.company)
|
56
|
+
f('#description').html(job.description)
|
57
|
+
f('#apply-at').text(job.apply_at)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Conventions
|
62
|
+
-----------
|
63
|
+
|
64
|
+
Assumes matching files at views/*.rb and templates/*.html.
|
65
|
+
|
66
|
+
Use a string if you need directories:
|
67
|
+
|
68
|
+
get '/jobs/edit/:id' do |id|
|
69
|
+
effigy 'jobs/edit', Job.find(id)
|
70
|
+
end
|
71
|
+
|
72
|
+
Resources
|
73
|
+
---------
|
74
|
+
|
75
|
+
* [Effigy](http://github.com/jferris/effigy)
|
76
|
+
* [Sinatra](http://sinatrarb.com)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/sinatra/effigy.rb
CHANGED
@@ -7,10 +7,17 @@ module Sinatra
|
|
7
7
|
Dir['views/*'].each {|view| require view }
|
8
8
|
end
|
9
9
|
|
10
|
-
def effigy(name)
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def effigy(name, *locals)
|
11
|
+
camel_name = "#{name}_view".
|
12
|
+
gsub(' ', '_').
|
13
|
+
gsub(/\/(.)/) { "::#{$1.upcase}" }.
|
14
|
+
gsub(/(?:^|_)(.)/) { $1.upcase }
|
15
|
+
if locals.any?
|
16
|
+
view = Object.const_get(camel_name).new(locals)
|
17
|
+
else
|
18
|
+
view = Object.const_get(camel_name).new
|
19
|
+
end
|
20
|
+
template = File.read(File.join(options.root, "templates", "#{name}.html"))
|
14
21
|
view.render(template)
|
15
22
|
end
|
16
23
|
end
|
data/sinatra-effigy.gemspec
CHANGED
@@ -5,15 +5,21 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-effigy}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan Croak"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-12}
|
13
13
|
s.description = %q{HTML in .html files. Ruby in .rb files.}
|
14
14
|
s.email = %q{dcroak@thoughtbot.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
15
19
|
s.files = [
|
16
20
|
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.md",
|
17
23
|
"Rakefile",
|
18
24
|
"VERSION",
|
19
25
|
"lib/sinatra/effigy.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-effigy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-12 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,10 +28,13 @@ executables: []
|
|
28
28
|
|
29
29
|
extensions: []
|
30
30
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
33
34
|
files:
|
34
35
|
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
35
38
|
- Rakefile
|
36
39
|
- VERSION
|
37
40
|
- lib/sinatra/effigy.rb
|