sinatra-effigy 0.0.8 → 0.0.9

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/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pkg
2
+ *.swp
data/README.md CHANGED
@@ -17,18 +17,26 @@ Install the gem:
17
17
 
18
18
  sudo gem install sinatra-effigy
19
19
 
20
- Create your Sinatra app:
20
+ Create your classic Sinatra app:
21
21
 
22
22
  require 'rubygems'
23
23
  require 'sinatra'
24
24
  require 'sinatra/effigy'
25
25
 
26
- set :app_file, __FILE__
27
-
28
26
  get '/jobs/:id' do |id|
29
27
  effigy :job, Job.find(id)
30
28
  end
31
29
 
30
+ Or, if you are using the modular style of Sinatra:
31
+
32
+ class App < Sinatra::Base
33
+ register Sinatra::Effigy
34
+
35
+ get '/jobs/:id' do |id|
36
+ effigy :job, Job.find(id)
37
+ end
38
+ end
39
+
32
40
  Create your template (fresh from a designer?) at /templates/job.html:
33
41
 
34
42
  <!DOCTYPE html>
@@ -100,3 +108,8 @@ Resources
100
108
 
101
109
  * [Effigy](http://github.com/jferris/effigy)
102
110
  * [Sinatra](http://sinatrarb.com)
111
+
112
+ Authors
113
+ -------
114
+
115
+ Dan Croak, Danny Tatom
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -5,13 +5,20 @@ module Sinatra
5
5
  module Effigy
6
6
  module Helpers
7
7
  def effigy(name, *locals)
8
- camel_name = "#{name}_view".
9
- gsub(' ', '_').
10
- gsub(/\/(.)/) { "::#{$1.upcase}" }.
11
- gsub(/(?:^|_)(.)/) { $1.upcase }
12
- view = Object.const_get(camel_name).new(*locals)
13
- template = File.read("#{options.templates}/#{name}.html")
14
- view.render(template)
8
+ view_file = "#{options.views}/#{name}.rb"
9
+ template_file = "#{options.templates}/#{name}.html"
10
+
11
+ if File.exists?(view_file)
12
+ camel_name = "#{name}_view".
13
+ gsub(' ', '_').
14
+ gsub(/\/(.)/) { "::#{$1.upcase}" }.
15
+ gsub(/(?:^|_)(.)/) { $1.upcase }
16
+ view = Object.const_get(camel_name).new(*locals)
17
+ template = File.read(template_file)
18
+ view.render(template)
19
+ else
20
+ File.read(template_file)
21
+ end
15
22
  end
16
23
  end
17
24
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-effigy}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
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-03-11}
12
+ s.date = %q{2010-03-20}
13
13
  s.description = %q{Ruby in .rb files. HTML in .html files.}
14
14
  s.email = %q{dcroak@thoughtbot.com}
15
15
  s.extra_rdoc_files = [
@@ -23,13 +23,27 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "lib/sinatra/effigy.rb",
26
- "sinatra-effigy.gemspec"
26
+ "sinatra-effigy.gemspec",
27
+ "spec/custom_templates/index.html",
28
+ "spec/custom_templates/job.html",
29
+ "spec/custom_views/job.rb",
30
+ "spec/extension_spec.rb",
31
+ "spec/spec_helper.rb",
32
+ "spec/templates/index.html",
33
+ "spec/templates/job.html",
34
+ "spec/views/job.rb"
27
35
  ]
28
36
  s.homepage = %q{http://github.com/dancroak/sinatra-effigy}
29
37
  s.rdoc_options = ["--charset=UTF-8"]
30
38
  s.require_paths = ["lib"]
31
39
  s.rubygems_version = %q{1.3.6}
32
40
  s.summary = %q{An Effigy extension for Sinatra.}
41
+ s.test_files = [
42
+ "spec/custom_views/job.rb",
43
+ "spec/extension_spec.rb",
44
+ "spec/spec_helper.rb",
45
+ "spec/views/job.rb"
46
+ ]
33
47
 
34
48
  if s.respond_to? :specification_version then
35
49
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1 @@
1
+ <html>pure</html>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head lang="en">
4
+ <meta charset="utf-8">
5
+ <title>Web Designer at thoughtbot</title>
6
+ </head>
7
+ <body>
8
+ <header>
9
+ <hgroup>
10
+ <h1>Web Designer</h1>
11
+ <h2><a href="http://example.com">thoughtbot</a></h2>
12
+ <h3>Boston or New York</h3>
13
+ </hgroup>
14
+ </header>
15
+
16
+ <div id="description">
17
+ <p>Graphic design, typography, CSS, HTML.</p>
18
+ </div>
19
+ </body>
20
+ </html>
@@ -0,0 +1,11 @@
1
+ class JobView < Effigy::View
2
+ attr_reader :job
3
+
4
+ def initialize(job)
5
+ @job = job
6
+ end
7
+
8
+ def transform
9
+ f('title').text("#{job.position} at #{job.company}")
10
+ end
11
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'effigy-enabled sinatra app' do
4
+ it 'returns pure HTML template when no Ruby view exists' do
5
+ get '/'
6
+
7
+ last_response.should be_ok
8
+ last_response.body.should include("<html>pure</html>")
9
+ end
10
+
11
+ it 'returns HTML that has been set by a Ruby view' do
12
+ get '/job'
13
+
14
+ last_response.should be_ok
15
+ last_response.body.should include("<title>President at USA</title>")
16
+ end
17
+ end
18
+
19
+ shared_examples_for 'default install' do
20
+ it 'knows where the template and view directories are' do
21
+ app.views.should == 'views'
22
+ app.templates.should == 'templates'
23
+ end
24
+ end
25
+
26
+ shared_examples_for 'custom install' do
27
+ it 'knows where the template and view directories are' do
28
+ app.views.should == 'custom_views'
29
+ app.templates.should == 'custom_templates'
30
+ end
31
+ end
32
+
33
+ Job = Struct.new(:position, :company)
34
+
35
+ describe 'classic app with default Sinatra::Effigy install' do
36
+ def app
37
+ Sinatra::Application
38
+ end
39
+
40
+ before do
41
+ Sinatra::Application.instance_eval do
42
+ get '/' do
43
+ effigy :index
44
+ end
45
+
46
+ get '/job' do
47
+ effigy :job, Job.new("President", "USA")
48
+ end
49
+ end
50
+
51
+ @app = Sinatra::Application
52
+ end
53
+
54
+ it_should_behave_like 'effigy-enabled sinatra app'
55
+ it_should_behave_like 'default install'
56
+ end
57
+
58
+ describe 'classic app with custom Sinatra::Effigy install' do
59
+ def app
60
+ Sinatra::Application
61
+ end
62
+
63
+ before do
64
+ Sinatra::Application.instance_eval do
65
+ set :views, Proc.new { 'custom_views' }
66
+ set :templates, Proc.new { 'custom_templates' }
67
+
68
+ get '/' do
69
+ effigy :index
70
+ end
71
+
72
+ get '/job' do
73
+ effigy :job, Job.new("President", "USA")
74
+ end
75
+ end
76
+
77
+ @app = Sinatra::Application
78
+ end
79
+
80
+ it_should_behave_like 'effigy-enabled sinatra app'
81
+ it_should_behave_like 'custom install'
82
+ end
83
+
84
+ class DefaultApp < Sinatra::Base
85
+ register Sinatra::Effigy
86
+
87
+ set :environment, :test
88
+
89
+ get '/' do
90
+ effigy :index
91
+ end
92
+
93
+ get '/job' do
94
+ Job = Struct.new(:position, :company)
95
+ effigy :job, Job.new("President", "USA")
96
+ end
97
+ end
98
+
99
+ describe 'modular app with default Sinatra::Effigy install' do
100
+ def app
101
+ DefaultApp
102
+ end
103
+
104
+ it_should_behave_like 'effigy-enabled sinatra app'
105
+ it_should_behave_like 'default install'
106
+ end
107
+
108
+ class CustomApp < Sinatra::Base
109
+ register Sinatra::Effigy
110
+
111
+ set :environment, :test
112
+ set :views, Proc.new { 'custom_views' }
113
+ set :templates, Proc.new { 'custom_templates' }
114
+
115
+ get '/' do
116
+ effigy :index
117
+ end
118
+
119
+ get '/job' do
120
+ Job = Struct.new(:position, :company)
121
+ effigy :job, Job.new("President", "USA")
122
+ end
123
+ end
124
+
125
+ describe 'modular app with custom Sinatra::Effigy install' do
126
+ def app
127
+ CustomApp
128
+ end
129
+
130
+ it_should_behave_like 'effigy-enabled sinatra app'
131
+ it_should_behave_like 'custom install'
132
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+ require 'spec'
4
+ require 'rack/test'
5
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sinatra', 'effigy')
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.include Rack::Test::Methods
9
+ end
@@ -0,0 +1 @@
1
+ <html>pure</html>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head lang="en">
4
+ <meta charset="utf-8">
5
+ <title>Web Designer at thoughtbot</title>
6
+ </head>
7
+ <body>
8
+ <header>
9
+ <hgroup>
10
+ <h1>Web Designer</h1>
11
+ <h2><a href="http://example.com">thoughtbot</a></h2>
12
+ <h3>Boston or New York</h3>
13
+ </hgroup>
14
+ </header>
15
+
16
+ <div id="description">
17
+ <p>Graphic design, typography, CSS, HTML.</p>
18
+ </div>
19
+ </body>
20
+ </html>
@@ -0,0 +1,11 @@
1
+ class JobView < Effigy::View
2
+ attr_reader :job
3
+
4
+ def initialize(job)
5
+ @job = job
6
+ end
7
+
8
+ def transform
9
+ f('title').text("#{job.position} at #{job.company}")
10
+ end
11
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dan Croak
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-11 00:00:00 -05:00
17
+ date: 2010-03-20 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -58,6 +58,14 @@ files:
58
58
  - VERSION
59
59
  - lib/sinatra/effigy.rb
60
60
  - sinatra-effigy.gemspec
61
+ - spec/custom_templates/index.html
62
+ - spec/custom_templates/job.html
63
+ - spec/custom_views/job.rb
64
+ - spec/extension_spec.rb
65
+ - spec/spec_helper.rb
66
+ - spec/templates/index.html
67
+ - spec/templates/job.html
68
+ - spec/views/job.rb
61
69
  has_rdoc: true
62
70
  homepage: http://github.com/dancroak/sinatra-effigy
63
71
  licenses: []
@@ -88,5 +96,8 @@ rubygems_version: 1.3.6
88
96
  signing_key:
89
97
  specification_version: 3
90
98
  summary: An Effigy extension for Sinatra.
91
- test_files: []
92
-
99
+ test_files:
100
+ - spec/custom_views/job.rb
101
+ - spec/extension_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/views/job.rb