governor 0.4.0 → 0.5.0

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/Gemfile CHANGED
@@ -6,7 +6,9 @@ group :development, :test do
6
6
  gem 'jeweler', '~> 1.5.2'
7
7
  gem 'sqlite3'
8
8
  gem 'rspec-rails'
9
+ gem 'rcov'
9
10
  gem 'mocha'
11
+ gem 'webrat'
10
12
  gem 'factory_girl', '~> 2.0.0.beta'
11
13
  gem 'factory_girl_rails', '~> 1.1.beta'
12
14
  gem 'activerecord-nulldb-adapter'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor (0.3.1)
4
+ governor (0.4.0)
5
5
  rails (~> 3.0.5)
6
6
 
7
7
  GEM
@@ -63,6 +63,7 @@ GEM
63
63
  treetop (~> 1.4.8)
64
64
  mime-types (1.16)
65
65
  mocha (0.9.12)
66
+ nokogiri (1.4.4)
66
67
  polyglot (0.3.1)
67
68
  rack (1.2.1)
68
69
  rack-mount (0.6.13)
@@ -83,6 +84,7 @@ GEM
83
84
  rake (>= 0.8.7)
84
85
  thor (~> 0.14.4)
85
86
  rake (0.8.7)
87
+ rcov (0.9.9)
86
88
  rspec (2.5.0)
87
89
  rspec-core (~> 2.5.0)
88
90
  rspec-expectations (~> 2.5.0)
@@ -103,6 +105,10 @@ GEM
103
105
  tzinfo (0.3.24)
104
106
  warden (1.0.3)
105
107
  rack (>= 1.0.0)
108
+ webrat (0.7.3)
109
+ nokogiri (>= 1.2.0)
110
+ rack (>= 1.0)
111
+ rack-test (>= 0.5.3)
106
112
 
107
113
  PLATFORMS
108
114
  ruby
@@ -117,5 +123,7 @@ DEPENDENCIES
117
123
  jeweler (~> 1.5.2)
118
124
  mocha
119
125
  rails (~> 3.0.5)
126
+ rcov
120
127
  rspec-rails
121
128
  sqlite3
129
+ webrat
data/Rakefile CHANGED
@@ -35,6 +35,7 @@ end
35
35
  RSpec::Core::RakeTask.new(:rcov) do |spec|
36
36
  spec.pattern = 'spec/**/*_spec.rb'
37
37
  spec.rcov = true
38
+ spec.rcov_opts = %w{--exclude gems\/,spec\/}
38
39
  end
39
40
 
40
41
  task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -0,0 +1,24 @@
1
+ module GovernorApplicationHelper
2
+ # A navigation header for allowing an administrator to access
3
+ # Governor-related links. By default, it includes a link to all articles and
4
+ # a link to create a new article.
5
+ #
6
+ # The default separator between items is |, which can be customized to be a
7
+ # bullet, an image, or any other string. If you're using Governor with
8
+ # multiple resources, you'll want to specify which one as the second
9
+ # argument. It defaults to the first resource registered.
10
+ def governor_header(separator = '|', resource = Governor.default_resource.plural)
11
+ mapping = Governor.resources[resource.to_sym]
12
+ content_tag :div, :class => 'governor_header' do
13
+ concat(link_to t('governor.all_articles', :resource_type => mapping.humanize.pluralize), send("#{mapping.plural}_path"))
14
+ concat(" #{separator} ".html_safe)
15
+ concat(link_to t('governor.new_article', :resource_type => mapping.humanize), send("new_#{mapping.singular}_path"))
16
+ Governor::PluginManager.plugins.map{|p| p.navigation_hook }.each do |hook|
17
+ if hook.present?
18
+ concat(" #{separator} ".html_safe)
19
+ instance_exec(resource, &hook)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,8 +1,4 @@
1
1
  module GovernorHelper
2
- Governor::PluginManager.plugins.map{|p| p.helpers }.flatten.each do |mod|
3
- include mod.constantize # FIXME this feels pretty dirty, there has to be a better way
4
- end
5
-
6
2
  def render_plugin_partial(where, options = {})
7
3
  output = ''
8
4
  Governor::PluginManager.plugins.map{|p| p.partial_for(where) }.compact.each do |partial|
@@ -4,3 +4,6 @@ en:
4
4
  article_updated: "%{resource_type} was successfully updated."
5
5
  article_destroyed: "%{resource_type} was successfully deleted."
6
6
  unauthorized_edit: "You're not allowed to edit this %{resource_type}."
7
+
8
+ all_articles: "%{resource_type}"
9
+ new_article: "New %{resource_type}"
data/governor.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{governor}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Liam Morley"]
12
- s.date = %q{2011-04-28}
12
+ s.date = %q{2011-05-05}
13
13
  s.description = %q{Because Blogojevich would be too tough to remember. It's a pluggable blogging system for Rails 3.}
14
14
  s.email = %q{liam@carpeliam.com}
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "app/controllers/governor/articles_controller.rb",
29
+ "app/helpers/governor_application_helper.rb",
29
30
  "app/helpers/governor_helper.rb",
30
31
  "app/views/governor/articles/_article.html.erb",
31
32
  "app/views/governor/articles/_form.html.erb",
@@ -61,6 +62,7 @@ Gem::Specification.new do |s|
61
62
  "spec/governor/plugin_manager_spec.rb",
62
63
  "spec/governor/plugin_spec.rb",
63
64
  "spec/governor_spec.rb",
65
+ "spec/helpers/governor_application_helper_spec.rb",
64
66
  "spec/rails_app/.gitignore",
65
67
  "spec/rails_app/Gemfile",
66
68
  "spec/rails_app/Gemfile.lock",
@@ -115,7 +117,9 @@ Gem::Specification.new do |s|
115
117
  "spec/rails_app/script/rails",
116
118
  "spec/rails_app/spec/factories.rb",
117
119
  "spec/rails_app/vendor/plugins/.gitkeep",
118
- "spec/spec_helper.rb"
120
+ "spec/spec_helper.rb",
121
+ "spec/views/governor/articles/index.html.erb_spec.rb",
122
+ "spec/views/layouts/application.html.erb_spec.rb"
119
123
  ]
120
124
  s.homepage = %q{http://carpeliam.github.com/governor}
121
125
  s.licenses = ["MIT"]
@@ -129,6 +133,7 @@ Gem::Specification.new do |s|
129
133
  "spec/governor/plugin_manager_spec.rb",
130
134
  "spec/governor/plugin_spec.rb",
131
135
  "spec/governor_spec.rb",
136
+ "spec/helpers/governor_application_helper_spec.rb",
132
137
  "spec/rails_app/app/controllers/application_controller.rb",
133
138
  "spec/rails_app/app/controllers/home_controller.rb",
134
139
  "spec/rails_app/app/helpers/application_helper.rb",
@@ -155,7 +160,9 @@ Gem::Specification.new do |s|
155
160
  "spec/rails_app/db/schema.rb",
156
161
  "spec/rails_app/db/seeds.rb",
157
162
  "spec/rails_app/spec/factories.rb",
158
- "spec/spec_helper.rb"
163
+ "spec/spec_helper.rb",
164
+ "spec/views/governor/articles/index.html.erb_spec.rb",
165
+ "spec/views/layouts/application.html.erb_spec.rb"
159
166
  ]
160
167
 
161
168
  if s.respond_to? :specification_version then
@@ -167,7 +174,9 @@ Gem::Specification.new do |s|
167
174
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
168
175
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
169
176
  s.add_development_dependency(%q<rspec-rails>, [">= 0"])
177
+ s.add_development_dependency(%q<rcov>, [">= 0"])
170
178
  s.add_development_dependency(%q<mocha>, [">= 0"])
179
+ s.add_development_dependency(%q<webrat>, [">= 0"])
171
180
  s.add_development_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
172
181
  s.add_development_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
173
182
  s.add_development_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
@@ -179,7 +188,9 @@ Gem::Specification.new do |s|
179
188
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
180
189
  s.add_dependency(%q<sqlite3>, [">= 0"])
181
190
  s.add_dependency(%q<rspec-rails>, [">= 0"])
191
+ s.add_dependency(%q<rcov>, [">= 0"])
182
192
  s.add_dependency(%q<mocha>, [">= 0"])
193
+ s.add_dependency(%q<webrat>, [">= 0"])
183
194
  s.add_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
184
195
  s.add_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
185
196
  s.add_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
@@ -192,7 +203,9 @@ Gem::Specification.new do |s|
192
203
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
193
204
  s.add_dependency(%q<sqlite3>, [">= 0"])
194
205
  s.add_dependency(%q<rspec-rails>, [">= 0"])
206
+ s.add_dependency(%q<rcov>, [">= 0"])
195
207
  s.add_dependency(%q<mocha>, [">= 0"])
208
+ s.add_dependency(%q<webrat>, [">= 0"])
196
209
  s.add_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
197
210
  s.add_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
198
211
  s.add_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
@@ -1,10 +1,9 @@
1
1
  module Governor
2
2
  class Plugin
3
- attr_reader :name, :migrations, :routes, :resources, :helpers, :mimes
3
+ attr_reader :name, :migrations, :routes, :resources, :mimes, :navigation_hook
4
4
  def initialize(name)
5
5
  @name = name
6
6
  @migrations = []
7
- @helpers = []
8
7
  @resources = {}
9
8
  @partials = {}
10
9
  @mimes = []
@@ -51,19 +50,6 @@ module Governor
51
50
  @partials[type.to_sym]
52
51
  end
53
52
 
54
- # Associates a helper for this plugin, to be included into the controller
55
- # and view.
56
- #
57
- # Currently this requires a string. This will be refactored soon.
58
- #
59
- # Example:
60
- #
61
- # comments.add_helper "GovernorCommentsHelper"
62
- #
63
- def add_helper(mod)
64
- @helpers << mod
65
- end
66
-
67
53
  def include_in_model(base) #:nodoc:
68
54
  instance_exec(base, &@model_callback) if @model_callback
69
55
  end
@@ -88,8 +74,40 @@ module Governor
88
74
  @model_callback = block
89
75
  end
90
76
 
77
+ # Defines mime types that this plugin responds to. These mime types will
78
+ # be passed on to the controller.
79
+ #
80
+ # Example:
81
+ #
82
+ # plugin.responds_to :xml, :json
83
+ #
84
+ # Specifies that this plugin can deliver a view for XML documents as well
85
+ # as JSON.
86
+ #
87
+ # Any arguments that can be passed to +respond_to+ in the controller can
88
+ # be passed here:
89
+ #
90
+ # plugin.responds_to :atom, :only => :index
91
+ #
92
+ # This specifies that the :index action responds to :atom, but no others.
91
93
  def responds_to(*mimes)
92
94
  @mimes << mimes
93
95
  end
96
+
97
+ # Adds the given block to the Governor navigation header in
98
+ # GovernorApplicationHeader#governor_header.
99
+ #
100
+ # Example:
101
+ #
102
+ # plugin.add_to_navigation do
103
+ # concat(link_to("Rod's favorite movie?", 'http://www.imdb.com/title/tt0031679/'))
104
+ # end
105
+ #
106
+ # This would add a link to Rod's favorite movie in the Governor navigation
107
+ # header. You're responsible for wrapping any content you want included
108
+ # with concat().
109
+ def add_to_navigation(&block)
110
+ @navigation_hook = block
111
+ end
94
112
  end
95
113
  end
@@ -3,6 +3,8 @@ require 'governor/rails/routes'
3
3
  module Governor
4
4
  # Standard <code>Rails::Engine</code>.
5
5
  class Engine < ::Rails::Engine
6
-
6
+ config.to_prepare do
7
+ ActionController::Base.helper(GovernorApplicationHelper)
8
+ end
7
9
  end
8
10
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe GovernorApplicationHelper do
4
+ describe "#governor_header" do
5
+ it "includes a link to a new article" do
6
+ governor_header.should have_selector('a', :href => new_article_path, :content => "New Article")
7
+ end
8
+ it "includes a link to all articles" do
9
+ governor_header.should have_selector('a', :href => articles_path, :content => "Article")
10
+ end
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- governor (0.3.1)
4
+ governor (0.4.0)
5
5
  rails (~> 3.0.5)
6
6
 
7
7
  GEM
@@ -8,6 +8,7 @@
8
8
  </head>
9
9
  <body>
10
10
  <% if user_signed_in? %>
11
+ <%= governor_header %>
11
12
  <%= link_to 'new article', new_article_path %> |
12
13
  <%= link_to 'sign out', destroy_user_session_path %>
13
14
  <% else %>
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Governor
4
+ describe "governor/articles/index.html.erb" do
5
+ it "can render plugin partials" do
6
+ view.should respond_to(:render_plugin_partial)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe "layouts/application.html.erb" do
4
+ include Devise::TestHelpers
5
+
6
+ before(:each) do
7
+ sign_in Factory(:user)
8
+ end
9
+
10
+ it "includes the helper" do
11
+ view.should respond_to(:governor_header)
12
+ end
13
+
14
+ it "links to articles page" do
15
+ render
16
+ rendered.should have_selector('a', :href => articles_path, :content => 'Articles')
17
+ end
18
+
19
+ it "links to new article page" do
20
+ render
21
+ rendered.should have_selector('a', :href => new_article_path, :content => 'New Article')
22
+ end
23
+
24
+ context "with a plugin that adds a hook" do
25
+ before do
26
+ @test = Governor::Plugin.new('test')
27
+ @test.add_to_navigation do
28
+ concat(link_to('Google', 'http://www.google.com'))
29
+ end
30
+ Governor::PluginManager.register @test
31
+ end
32
+ it "shows any plugin's hooks" do
33
+ render
34
+ rendered.should have_selector('a', :href => 'http://www.google.com', :content => 'Google')
35
+ end
36
+ after do
37
+ Governor::PluginManager.remove_plugin(@test)
38
+ end
39
+ end
40
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: governor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Liam Morley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-28 00:00:00 -04:00
18
+ date: 2011-05-05 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Dependency
82
82
  type: :development
83
83
  prerelease: false
84
- name: mocha
84
+ name: rcov
85
85
  version_requirements: &id005 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
@@ -95,8 +95,36 @@ dependencies:
95
95
  - !ruby/object:Gem::Dependency
96
96
  type: :development
97
97
  prerelease: false
98
- name: factory_girl
98
+ name: mocha
99
99
  version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirement: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ type: :development
111
+ prerelease: false
112
+ name: webrat
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirement: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ type: :development
125
+ prerelease: false
126
+ name: factory_girl
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
100
128
  none: false
101
129
  requirements:
102
130
  - - ~>
@@ -108,12 +136,12 @@ dependencies:
108
136
  - 0
109
137
  - beta
110
138
  version: 2.0.0.beta
111
- requirement: *id006
139
+ requirement: *id008
112
140
  - !ruby/object:Gem::Dependency
113
141
  type: :development
114
142
  prerelease: false
115
143
  name: factory_girl_rails
116
- version_requirements: &id007 !ruby/object:Gem::Requirement
144
+ version_requirements: &id009 !ruby/object:Gem::Requirement
117
145
  none: false
118
146
  requirements:
119
147
  - - ~>
@@ -124,12 +152,12 @@ dependencies:
124
152
  - 1
125
153
  - beta
126
154
  version: 1.1.beta
127
- requirement: *id007
155
+ requirement: *id009
128
156
  - !ruby/object:Gem::Dependency
129
157
  type: :development
130
158
  prerelease: false
131
159
  name: activerecord-nulldb-adapter
132
- version_requirements: &id008 !ruby/object:Gem::Requirement
160
+ version_requirements: &id010 !ruby/object:Gem::Requirement
133
161
  none: false
134
162
  requirements:
135
163
  - - ">="
@@ -138,12 +166,12 @@ dependencies:
138
166
  segments:
139
167
  - 0
140
168
  version: "0"
141
- requirement: *id008
169
+ requirement: *id010
142
170
  - !ruby/object:Gem::Dependency
143
171
  type: :development
144
172
  prerelease: false
145
173
  name: devise
146
- version_requirements: &id009 !ruby/object:Gem::Requirement
174
+ version_requirements: &id011 !ruby/object:Gem::Requirement
147
175
  none: false
148
176
  requirements:
149
177
  - - ">="
@@ -152,12 +180,12 @@ dependencies:
152
180
  segments:
153
181
  - 0
154
182
  version: "0"
155
- requirement: *id009
183
+ requirement: *id011
156
184
  - !ruby/object:Gem::Dependency
157
185
  type: :development
158
186
  prerelease: false
159
187
  name: governor
160
- version_requirements: &id010 !ruby/object:Gem::Requirement
188
+ version_requirements: &id012 !ruby/object:Gem::Requirement
161
189
  none: false
162
190
  requirements:
163
191
  - - ">="
@@ -166,12 +194,12 @@ dependencies:
166
194
  segments:
167
195
  - 0
168
196
  version: "0"
169
- requirement: *id010
197
+ requirement: *id012
170
198
  - !ruby/object:Gem::Dependency
171
199
  type: :development
172
200
  prerelease: false
173
201
  name: dynamic_form
174
- version_requirements: &id011 !ruby/object:Gem::Requirement
202
+ version_requirements: &id013 !ruby/object:Gem::Requirement
175
203
  none: false
176
204
  requirements:
177
205
  - - ">="
@@ -180,7 +208,7 @@ dependencies:
180
208
  segments:
181
209
  - 0
182
210
  version: "0"
183
- requirement: *id011
211
+ requirement: *id013
184
212
  description: Because Blogojevich would be too tough to remember. It's a pluggable blogging system for Rails 3.
185
213
  email: liam@carpeliam.com
186
214
  executables: []
@@ -200,6 +228,7 @@ files:
200
228
  - Rakefile
201
229
  - VERSION
202
230
  - app/controllers/governor/articles_controller.rb
231
+ - app/helpers/governor_application_helper.rb
203
232
  - app/helpers/governor_helper.rb
204
233
  - app/views/governor/articles/_article.html.erb
205
234
  - app/views/governor/articles/_form.html.erb
@@ -235,6 +264,7 @@ files:
235
264
  - spec/governor/plugin_manager_spec.rb
236
265
  - spec/governor/plugin_spec.rb
237
266
  - spec/governor_spec.rb
267
+ - spec/helpers/governor_application_helper_spec.rb
238
268
  - spec/rails_app/.gitignore
239
269
  - spec/rails_app/Gemfile
240
270
  - spec/rails_app/Gemfile.lock
@@ -290,6 +320,8 @@ files:
290
320
  - spec/rails_app/spec/factories.rb
291
321
  - spec/rails_app/vendor/plugins/.gitkeep
292
322
  - spec/spec_helper.rb
323
+ - spec/views/governor/articles/index.html.erb_spec.rb
324
+ - spec/views/layouts/application.html.erb_spec.rb
293
325
  has_rdoc: true
294
326
  homepage: http://carpeliam.github.com/governor
295
327
  licenses:
@@ -331,6 +363,7 @@ test_files:
331
363
  - spec/governor/plugin_manager_spec.rb
332
364
  - spec/governor/plugin_spec.rb
333
365
  - spec/governor_spec.rb
366
+ - spec/helpers/governor_application_helper_spec.rb
334
367
  - spec/rails_app/app/controllers/application_controller.rb
335
368
  - spec/rails_app/app/controllers/home_controller.rb
336
369
  - spec/rails_app/app/helpers/application_helper.rb
@@ -358,3 +391,5 @@ test_files:
358
391
  - spec/rails_app/db/seeds.rb
359
392
  - spec/rails_app/spec/factories.rb
360
393
  - spec/spec_helper.rb
394
+ - spec/views/governor/articles/index.html.erb_spec.rb
395
+ - spec/views/layouts/application.html.erb_spec.rb