governor 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor (0.1.1)
4
+ governor (0.2.0)
5
5
  rails (~> 3.0.5)
6
6
 
7
7
  GEM
@@ -1,7 +1,6 @@
1
- Governor
2
- ========
1
+ = Governor
3
2
 
4
- **Governor** (named after Rod Blagojevich) is the pluggable blogging platform
3
+ *Governor* (named after Rod Blagojevich) is the pluggable blogging platform
5
4
  for Rails, built for people who want to build their blog into their website,
6
5
  not build their website into their blog.
7
6
 
@@ -9,17 +8,15 @@ I'm just getting started, but feel free to poke around. I'm sure that when
9
8
  this starts getting functional, I'll write some setup documentation here. And
10
9
  try the specs, they're fresh!
11
10
 
12
- Dependencies
13
- ------------
11
+ == Dependencies
14
12
 
15
13
  * ActiveRecord
16
- * [will_paginate](https://github.com/mislav/will_paginate)
14
+ * will_paginate[https://github.com/mislav/will_paginate]
17
15
 
18
16
  At some point (at least by v1.0), these dependencies will be removed. Sorry
19
17
  about the meantime.
20
18
 
21
- Setting Up
22
- ----------
19
+ == Setting Up
23
20
 
24
21
  Governor is a gem, so the first thing to do is to add Governor to your
25
22
  Gemfile.
@@ -40,8 +37,7 @@ you're ready to add a model:
40
37
  like Post, Blog, whatever. This will add a model, migration, and route to your
41
38
  app.
42
39
 
43
- Usage
44
- -----
40
+ == Usage
45
41
 
46
42
  Now that you have an article model and a set of routes, you're ready to plug
47
43
  it into your app. I'd recommend running `rake routes` to see what routes have
@@ -51,8 +47,7 @@ The Governor initialization will check if Devise is installed, and will try to
51
47
  Do The Right Thing if it is. If not, it'll yell at you, so be sure to set up
52
48
  your authorization rules in this file.
53
49
 
54
- Authentication/Authorization
55
- ----------------------------
50
+ == Authentication/Authorization
56
51
 
57
52
  For now, Governor checks with Devise to make sure someone's logged in before
58
53
  creating an article, and verifies that the logged in user is an article's
@@ -60,8 +55,7 @@ author before allowing them to edit. You might have your own rules that you'd
60
55
  rather apply. You'll have to wait until a future version if you want something
61
56
  different, sorry.
62
57
 
63
- Roadmap
64
- -------
58
+ == Roadmap
65
59
 
66
60
  Less of a roadmap as a politician's promise of what will exist in future
67
61
  versions of Governor:
@@ -77,8 +71,7 @@ anything regarding backwards compatibility. Please let me know if something
77
71
  you were relying on breaks, and I'll do my best to steer you in the right
78
72
  direction or repair functionality.
79
73
 
80
- Contributing to Governor
81
- ------------------------
74
+ == Contributing to Governor
82
75
 
83
76
  Governor is just getting off the ground now, so while there's a lot to
84
77
  implement, the infrastructure might be too shaky to support multiple
@@ -92,9 +85,8 @@ developers. Still, if you're interested in improving this, let's talk.
92
85
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
93
86
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
94
87
 
95
- Copyright
96
- ---------
88
+ == Copyright
97
89
 
98
- Copyright © 2011 Liam Morley. See LICENSE.txt for
90
+ Copyright (C) 2011 Liam Morley. See LICENSE.txt for
99
91
  further details.
100
92
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require 'jeweler'
13
13
  Jeweler::Tasks.new do |gem|
14
14
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
15
  gem.name = "governor"
16
- gem.homepage = "http://github.com/carpeliam/governor"
16
+ gem.homepage = "http://carpeliam.github.com/governor"
17
17
  gem.license = "MIT"
18
18
  gem.summary = %Q{A pluggable blogging system for Rails 3.}
19
19
  gem.description = %Q{Because Blogojevich would be too tough to remember. It's a pluggable blogging system for Rails 3.}
@@ -44,7 +44,8 @@ Rake::RDocTask.new do |rdoc|
44
44
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
45
 
46
46
  rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = "governor #{version}"
47
+ rdoc.title = "Governor #{version}"
48
48
  rdoc.rdoc_files.include('README*')
49
49
  rdoc.rdoc_files.include('lib/**/*.rb')
50
+ rdoc.rdoc_files.exclude('lib/generators/**/*.rb')
50
51
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/governor.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{governor}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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"]
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.email = %q{liam@carpeliam.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.markdown"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  "Gemfile",
23
23
  "Gemfile.lock",
24
24
  "LICENSE.txt",
25
- "README.markdown",
25
+ "README.rdoc",
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "app/controllers/governor/articles_controller.rb",
@@ -113,7 +113,7 @@ Gem::Specification.new do |s|
113
113
  "spec/rails_app/vendor/plugins/.gitkeep",
114
114
  "spec/spec_helper.rb"
115
115
  ]
116
- s.homepage = %q{http://github.com/carpeliam/governor}
116
+ s.homepage = %q{http://carpeliam.github.com/governor}
117
117
  s.licenses = ["MIT"]
118
118
  s.require_paths = ["lib"]
119
119
  s.rubygems_version = %q{1.3.7}
data/lib/governor.rb CHANGED
@@ -10,14 +10,67 @@ require 'governor/rails'
10
10
 
11
11
 
12
12
  module Governor
13
-
14
- mattr_reader :resources, :authorization_rules, :default_resource
15
- mattr_accessor :if_not_allowed, :author
16
13
  @@resources = {}
14
+ mattr_reader :resources, :default_resource, :authorization_rules
15
+
16
+ # Specifies the action that should occur if an unpermitted action is
17
+ # attempted. Usually specified within the initializer, though evaluated in
18
+ # the scope of a Rails session.
19
+ #
20
+ # Example:
21
+ #
22
+ # Governor.if_not_allowed do
23
+ # if respond_to?(Devise)
24
+ # send("authenticate_#{Devise.default_scope}!")
25
+ # else
26
+ # raise ArgumentError.new("Set up Governor.if_not_allowed in #{File.expand_path(__FILE__)}")
27
+ # end
28
+ # end
29
+ #
30
+ mattr_accessor :if_not_allowed
31
+
32
+ # Specifies how to reference the author of an article. Usually specified
33
+ # within the initializer, though evaluated in the scope of a Rails session.
34
+ #
35
+ # Example:
36
+ #
37
+ # Governor.author = Proc.new do
38
+ # if respond_to?(:current_user)
39
+ # current_user
40
+ # else
41
+ # raise "Set up Governor.author in #{File.expand_path(__FILE__)}"
42
+ # end
43
+ # end
44
+ #
45
+ mattr_accessor :author
46
+
47
+ # Maps a given resource name with a pair of options, to be supplied as
48
+ # arguments to the routes. Usually called from within +governate+.
17
49
  def self.map(resource, options = {})
18
50
  @@default_resource ||= self.resources[resource] = Governor::Mapping.new(resource, options)
19
51
  end
20
52
 
53
+ # Supply a set of rules that describe what the requirements are to perform a
54
+ # given Governor-related action on a given article. Usually specified within
55
+ # the initializer, though evaluated in the scope of a Rails session.
56
+ #
57
+ # Example (from the generated initialization file):
58
+ #
59
+ # Governor.authorize_if do |action, article|
60
+ # case action.to_sym
61
+ # when :new, :create
62
+ # if respond_to?(:user_signed_in?)
63
+ # user_signed_in?
64
+ # else
65
+ # raise "Set up Governor.authorize_if in #{File.expand_path(__FILE__)}"
66
+ # end
67
+ # when :edit, :update, :destroy
68
+ # article.author == instance_eval(&Governor.author)
69
+ # else
70
+ # raise ArgumentError.new('action must be new, create, edit, update, or destroy')
71
+ # end
72
+ # end
73
+ #
21
74
  def self.authorize_if(&blk)
22
75
  @@authorization_rules = blk
23
76
  end
@@ -1,11 +1,17 @@
1
1
  module Governor
2
+ # Include this module into any class that will represent a blog article
3
+ # post.
2
4
  module Article
3
- def self.included(base)
5
+ def self.included(base) #:nodoc:
4
6
  base.belongs_to :author, :polymorphic => true
5
7
  Governor::PluginManager.resources(:child_resources).each_key do |resource|
6
8
  base.has_many resource
7
9
  end
8
10
 
11
+ # Will retrieve all of the articles with a given year, month, or day. If
12
+ # day is not specified, it will find all of the posts for a given month;
13
+ # if month is not specified, then it will find all of the posts for a
14
+ # given year. Specifying a page will work with will_paginate.
9
15
  def base.find_all_by_date(year, month = nil, day = nil, page = 1)
10
16
  from, to = self.time_delta(year, month, day)
11
17
  conditions = ['created_at BETWEEN ? AND ?', from, to]
@@ -1,18 +1,27 @@
1
1
  module Governor
2
- module Controllers
2
+ module Controllers #:nodoc:
3
3
  module Helpers
4
+ # Represents the article for this session. Can also be accessed as an
5
+ # instance variable, for example <code>@article</code> if the Mapping
6
+ # class is Article.
4
7
  def resource
5
8
  instance_variable_get("@#{mapping.singular}")
6
9
  end
7
10
 
11
+ # Returns a symbol representation of this resource, for example
12
+ # <code>:article</code> if the Mapping class is Article.
8
13
  def resource_sym
9
14
  mapping.singular
10
15
  end
11
-
16
+
17
+ # Returns the list of articles for this session. Can also be accessed as
18
+ # an instance variable, for example <code>@articles</code> if the
19
+ # Mapping class is Article.
12
20
  def resources
13
21
  instance_variable_get("@#{mapping.plural}")
14
22
  end
15
-
23
+
24
+ # Returns the Mapping model class, for example: Article.
16
25
  def model_class
17
26
  @model_class ||= mapping.to
18
27
  end
@@ -1,9 +1,9 @@
1
- # much love to Feather, borrowed from Merb
2
1
  module Governor
2
+ # heavily based on Feather[https://github.com/mleung/feather]
3
3
  module Formatters
4
4
  class << self
5
5
  ##
6
- # This registers a block to format article content
6
+ # Registers a block to format article content
7
7
  def register_formatter(name, &block)
8
8
  @formatters ||= {'default' => default_formatter}
9
9
  raise "Formatter `#{name}` already registered!" unless @formatters[name].nil?
@@ -11,14 +11,14 @@ module Governor
11
11
  end
12
12
 
13
13
  ##
14
- # This returns an array of available formatters that have been registered
14
+ # Returns an array of available formatters that have been registered
15
15
  def available_formatters
16
16
  @formatters ||= {'default' => default_formatter}
17
17
  return @formatters
18
18
  end
19
19
 
20
20
  ##
21
- # This returns a default formatter used for replacing line breaks within text
21
+ # Returns a default formatter used for replacing line breaks within text
22
22
  # This is the only formatter included within Governor
23
23
  def default_formatter
24
24
  Proc.new do |text|
@@ -27,13 +27,13 @@ module Governor
27
27
  end
28
28
 
29
29
  ##
30
- # This performs the relevant formatting for the article, and returns the formatted article content
30
+ # Performs the relevant formatting for the article, and returns the formatted article content
31
31
  def format_article(article)
32
32
  format_text(article.format, article.post)
33
33
  end
34
34
 
35
35
  ##
36
- # This performs the requested formatting, returning the formatted text
36
+ # Performs the requested formatting, returning the formatted text
37
37
  def format_text(formatter, text)
38
38
  formatter = 'default' unless available_formatters.include?(formatter)
39
39
  @formatters[formatter].call(text).html_safe
@@ -16,17 +16,14 @@ module Governor
16
16
  @controller = options[:controller] || 'governor/articles'
17
17
  end
18
18
 
19
- def fullpath
20
- "#{@path_prefix}/#{@path}".squeeze("/")
21
- end
22
-
19
+ # Provides the resource class.
23
20
  def to
24
21
  @ref.get
25
22
  end
26
23
 
24
+ # Presents a human-readable identifier of the resource type.
27
25
  def humanize
28
26
  @singular.to_s.humanize
29
27
  end
30
-
31
28
  end
32
29
  end
@@ -13,20 +13,58 @@ module Governor
13
13
  @migrations << path
14
14
  end
15
15
 
16
+ # Adds a nested resource. Any options are passed directly to the router.
17
+ # Any member or collection routes can be passed in as a block.
18
+ #
19
+ # Example:
20
+ #
21
+ # comments = Governor::Plugin.new('comments')
22
+ # comments.add_child_resource :comments do
23
+ # member do
24
+ # put 'mark_spam', 'not_spam'
25
+ # end
26
+ # end
27
+ #
16
28
  def add_child_resource(name, options={}, &block)
17
29
  options[:block] = block if block_given?
18
30
  @resources[:child_resources] ||= {}
19
31
  @resources[:child_resources][name] = options
20
32
  end
21
33
 
34
+ # Specifies that this plugin will display a partial of the given type, at
35
+ # the given path. This path is relative to the views directory underneath
36
+ # your app; it's expected that there will be a governor directory
37
+ # underneath views as well.
38
+ #
39
+ # DOCUMENTME I need to indicate which types are supported.
40
+ #
41
+ # Example:
42
+ #
43
+ # comments.register_partial :after_article_whole, 'articles/comments'
44
+ #
22
45
  def register_partial(type, path)
23
46
  @partials[type.to_sym] = path
24
47
  end
25
48
 
49
+ # Returns the path associated with the given partial type.
50
+ #
51
+ # Example:
52
+ #
53
+ # comments.partial_for(:after_article_whole) # => 'articles/comments'
54
+ #
26
55
  def partial_for(type)
27
56
  @partials[type.to_sym]
28
57
  end
29
58
 
59
+ # Associates a helper for this plugin, to be included into the controller
60
+ # and view.
61
+ #
62
+ # Currently this requires a string. This will be refactored soon.
63
+ #
64
+ # Example:
65
+ #
66
+ # comments.add_helper "GovernorCommentsHelper"
67
+ #
30
68
  def add_helper(mod)
31
69
  @helpers << mod
32
70
  end
@@ -6,10 +6,27 @@ module Governor
6
6
  class << self
7
7
  @@plugins = []
8
8
 
9
+ # Registers the given plugins with Governor. Usually called within the
10
+ # context of a single plugin, but any number of plugins can be
11
+ # registered.
12
+ #
13
+ # Example:
14
+ #
15
+ # comments = Governor::Plugin.new('comments')
16
+ # Governor::PluginManager.register comments
17
+ #
9
18
  def register(*plugins)
10
19
  @@plugins += plugins
11
20
  end
12
21
 
22
+ # A convenience method for obtaining the resources for plugins.
23
+ #
24
+ # Example:
25
+ #
26
+ # comments = Governor::Plugin.new('comments')
27
+ # comments.add_child_resource :comments, :path_names => {:create => 'comment'}
28
+ # Governor::PluginManager.register comments
29
+ # Governor::PluginManager.resources(:child_resources) # => {:comments => {:create => 'comment'}}
13
30
  def resources(name)
14
31
  @@plugins.map{|p| p.resources[name] }.compact.reduce({}, :merge)
15
32
  end
@@ -1,6 +1,7 @@
1
1
  require 'governor/rails/routes'
2
2
 
3
3
  module Governor
4
+ # Standard <code>Rails::Engine</code>.
4
5
  class Engine < ::Rails::Engine
5
6
 
6
7
  end
@@ -1,20 +1,34 @@
1
- module ActionDispatch::Routing
2
- class Mapper
3
- def governate(*resources)
4
- options = resources.extract_options!
5
- resources.map!(&:to_sym)
6
- resources.each do |resource|
7
- mapping = Governor.map(resource, options)
8
- resources mapping.resource, :controller => mapping.controller, :governor_mapping => resource do
9
- Governor::PluginManager.resources(:child_resources).each_pair do |child_resource, options|
10
- options = {:module => :governor}.merge options
11
- block = options.delete :block
12
- resources(child_resource, options) do
13
- instance_eval(&block) if block.present?
1
+ module ActionDispatch #:nodoc:
2
+ module Routing #:nodoc:
3
+ class Mapper
4
+ # Attach a Governor-based resource to your application's Rails routes.
5
+ #
6
+ # Example:
7
+ #
8
+ # RailsApp::Application.routes.draw do
9
+ # # ...
10
+ # governate :articles
11
+ # # ...
12
+ # end
13
+ #
14
+ # This will attach a controller that will create and modify Article
15
+ # objects.
16
+ def governate(*resources)
17
+ options = resources.extract_options!
18
+ resources.map!(&:to_sym)
19
+ resources.each do |resource|
20
+ mapping = Governor.map(resource, options)
21
+ resources mapping.resource, :controller => mapping.controller, :governor_mapping => resource do
22
+ Governor::PluginManager.resources(:child_resources).each_pair do |child_resource, options|
23
+ options = {:module => :governor}.merge options
24
+ block = options.delete :block
25
+ resources(child_resource, options) do
26
+ instance_eval(&block) if block.present?
27
+ end
14
28
  end
15
29
  end
16
30
  end
17
31
  end
18
32
  end
19
33
  end
20
- end
34
+ 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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Liam Morley
@@ -205,14 +205,14 @@ extensions: []
205
205
 
206
206
  extra_rdoc_files:
207
207
  - LICENSE.txt
208
- - README.markdown
208
+ - README.rdoc
209
209
  files:
210
210
  - .document
211
211
  - .rspec
212
212
  - Gemfile
213
213
  - Gemfile.lock
214
214
  - LICENSE.txt
215
- - README.markdown
215
+ - README.rdoc
216
216
  - Rakefile
217
217
  - VERSION
218
218
  - app/controllers/governor/articles_controller.rb
@@ -303,7 +303,7 @@ files:
303
303
  - spec/rails_app/vendor/plugins/.gitkeep
304
304
  - spec/spec_helper.rb
305
305
  has_rdoc: true
306
- homepage: http://github.com/carpeliam/governor
306
+ homepage: http://carpeliam.github.com/governor
307
307
  licenses:
308
308
  - MIT
309
309
  post_install_message: