sinatra-effigy 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -10
- data/VERSION +1 -1
- data/lib/sinatra/effigy.rb +3 -5
- data/sinatra-effigy.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -23,6 +23,8 @@ Create your Sinatra app:
|
|
23
23
|
require 'sinatra'
|
24
24
|
require 'sinatra/effigy'
|
25
25
|
|
26
|
+
set :app_file, __FILE__
|
27
|
+
|
26
28
|
get '/jobs/:id' do |id|
|
27
29
|
effigy :job, Job.find(id)
|
28
30
|
end
|
@@ -31,20 +33,22 @@ Create your template (fresh from a designer?) at /templates/job.html:
|
|
31
33
|
|
32
34
|
<!DOCTYPE html>
|
33
35
|
<html>
|
34
|
-
<head>
|
36
|
+
<head lang="en">
|
37
|
+
<meta charset="utf-8">
|
35
38
|
<title>Web Designer at thoughtbot</title>
|
36
39
|
</head>
|
37
40
|
<body>
|
38
|
-
<
|
39
|
-
|
40
|
-
|
41
|
+
<header>
|
42
|
+
<hgroup>
|
43
|
+
<h1>Web Designer</h1>
|
44
|
+
<h2><a href="http://example.com">thoughtbot</a></h2>
|
45
|
+
<h3>Boston or New York</h3>
|
46
|
+
</hgroup>
|
47
|
+
</header>
|
41
48
|
|
42
49
|
<div id="description">
|
43
50
|
<p>Graphic design, typography, CSS, HTML.</p>
|
44
51
|
</div>
|
45
|
-
|
46
|
-
<h3>Apply</h3>
|
47
|
-
<p>Please contact <span id="apply-at">jobs@example.com</span>.</p>
|
48
52
|
</body>
|
49
53
|
</html>
|
50
54
|
|
@@ -60,10 +64,8 @@ Create a view at /views/job.rb that responds to #transform:
|
|
60
64
|
def transform
|
61
65
|
f('title').text("#{job.position} at #{job.company}")
|
62
66
|
f('h1').text(job.position)
|
63
|
-
f('h2 a').attr(:href => job.company_url).
|
64
|
-
text(job.company)
|
67
|
+
f('h2 a').attr(:href => job.company_url).text(job.company)
|
65
68
|
f('#description').html(job.description)
|
66
|
-
f('#apply-at').text(job.apply_at)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -78,6 +80,13 @@ Use a string if you need directories:
|
|
78
80
|
effigy 'jobs/edit', Job.find(id)
|
79
81
|
end
|
80
82
|
|
83
|
+
Gotchas
|
84
|
+
-------
|
85
|
+
|
86
|
+
If you use Gem Bundler, set the app_file option in your Sinatra app:
|
87
|
+
|
88
|
+
set :app_file, __FILE__
|
89
|
+
|
81
90
|
Resources
|
82
91
|
---------
|
83
92
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/sinatra/effigy.rb
CHANGED
@@ -3,17 +3,15 @@ require 'effigy'
|
|
3
3
|
|
4
4
|
module Sinatra
|
5
5
|
module EffigyHelper
|
6
|
-
|
7
|
-
Dir['views/*'].each {|view| require view }
|
8
|
-
end
|
6
|
+
Dir['views/*'].each {|view| require view }
|
9
7
|
|
10
8
|
def effigy(name, *locals)
|
11
9
|
camel_name = "#{name}_view".
|
12
10
|
gsub(' ', '_').
|
13
11
|
gsub(/\/(.)/) { "::#{$1.upcase}" }.
|
14
12
|
gsub(/(?:^|_)(.)/) { $1.upcase }
|
15
|
-
view
|
16
|
-
template = File.read(
|
13
|
+
view = Object.const_get(camel_name).new(*locals)
|
14
|
+
template = File.read("templates/#{name}.html")
|
17
15
|
view.render(template)
|
18
16
|
end
|
19
17
|
end
|
data/sinatra-effigy.gemspec
CHANGED