acts_as_featureable 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fd7ae3319ca73121825929c08ffed994ed1da4d
4
- data.tar.gz: 1b0d23f470a30c8f5a4b56f9e78064c9dec180c2
3
+ metadata.gz: da0913e97c15dd0b9f312c91c8b9ac0c7cbee9db
4
+ data.tar.gz: 61381268c7f755346dfbe4968ce6491d524a2aec
5
5
  SHA512:
6
- metadata.gz: 6da70932bd2a8635194ddefa226dd36086f2a788d3c532bf94a02eabff9905b1093ec4d7216a39a6c73547babcbddbd739e5d03dd1edaee27dba2e90bd75b93c
7
- data.tar.gz: 9ad74f02e91c5a73c5196e88f80b6be92250dd31b2b4981e1f2804eccebba15bd7a9fc3677b3a2f55c407130ba0b56fd6ebb8c52878cde9ffba92af51bf618ec
6
+ metadata.gz: 256f4f5a3b7664cea18e224e9fd75d0ef9570096c9ae9106e8e1252f0f9da1274cc4ba48a7612c977ca5b3df38a7f1ef095952c92d52b1eb42346b23d7dcda16
7
+ data.tar.gz: f189187baf2ae53bf9c670aedb24242690dcfa7049d26ebaf2b16c387334b1f63ecd9231bcde43e1eff16647950b707baffeb1feba9c16599e939e3239e8fa0f
data/.gitignore CHANGED
@@ -14,5 +14,8 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
+ spec/dummy/log/*.log
17
18
  tmp
18
19
  .project
20
+ spec/log/*.log
21
+ /nbproject
@@ -1,6 +1,10 @@
1
+ ## v0.0.3
2
+
3
+ * Bug fix. Always use respond_to_missing? when using method_missing?
4
+
1
5
  ## v0.0.2
2
6
 
3
- * enhancements
7
+ * Enhancements
4
8
  * Added categories
5
9
  * Added validations
6
10
  * Turned into Rails::Engine with controller (with CanCan support) and basic views
@@ -8,4 +12,4 @@
8
12
 
9
13
  ## v0.0.1
10
14
 
11
- * initial release
15
+ * Initial release
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  begin
3
- require 'bundler/setup'
3
+ require 'bundler/setup'
4
4
  rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
7
 
8
8
  APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
@@ -4,26 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'acts_as_featureable/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "acts_as_featureable"
8
- spec.version = ActsAsFeatureable::VERSION
9
- spec.authors = ["Kainage"]
10
- spec.email = ["kainage@gmail.com"]
11
- spec.description = %q{Add a feature resource to a rails app}
12
- spec.summary = %q{Creates a new polymorphic resrouce, Feature, for pulling content to a main/features page}
13
- spec.homepage = "https://github.com/kainage/acts_as_featureable"
14
- spec.license = "MIT"
7
+ spec.name = "acts_as_featureable"
8
+ spec.version = ActsAsFeatureable::VERSION
9
+ spec.authors = ["Kainage"]
10
+ spec.email = ["kainage@gmail.com"]
11
+ spec.description = %q{Add a feature resource to a rails app}
12
+ spec.summary = %q{Creates a new polymorphic resrouce, Feature, for pulling content to a main/features page}
13
+ spec.homepage = "https://github.com/kainage/acts_as_featureable"
14
+ spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "rails", "~> 4.0.0.rc1"
21
+ spec.add_dependency "rails", "~> 4.0.0.rc1"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "sqlite3"
27
- spec.add_development_dependency "shoulda-matchers"
28
- spec.add_development_dependency "rspec-rails"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "sqlite3"
27
+ spec.add_development_dependency "shoulda-matchers"
28
+ spec.add_development_dependency "rspec-rails"
29
29
  end
@@ -1,90 +1,90 @@
1
1
  class FeaturesController < ApplicationController
2
- authorize_resource if defined?(CanCan::Ability)
3
-
4
- before_filter :find_featureable
5
-
6
- def index
7
- @features = Feature.all
8
-
9
- respond_to do |format|
10
- format.html
11
- format.json { render json: @features }
12
- end
13
- end
14
-
15
- def show
16
- @feature = Feature.find(params[:id])
17
-
18
- respond_to do |format|
19
- format.html
20
- format.json { render json: @feature }
21
- end
22
- end
23
-
24
- def new
25
- @feature = @featureable.features.build
26
-
27
- respond_to do |format|
28
- format.html
29
- format.json { render json: @feature }
30
- end
31
- end
32
-
33
- def edit
34
- @feature = Feature.find(params[:id])
35
-
36
- respond_to do |format|
37
- format.html
38
- format.json { render json: @feature }
39
- end
40
- end
41
-
42
- def create
43
- @feature = @featureable.features.build(feature_params)
44
-
45
- respond_to do |format|
46
- if @feature.save
47
- format.html { redirect_to @featureable, notice: 'Feature was successfully created.' }
48
- format.json { render json: @feature, status: :created, location: @feature }
49
- else
50
- format.html { redirect_to @featureable, alert: @feature.errors.full_messages.join(',') }
51
- format.json { render json: @feature.errors, status: :unprocessable_entity }
52
- end
53
- end
54
- end
55
-
56
- def update
57
- @feature = Feature.find(params[:id])
58
-
59
- respond_to do |format|
60
- if @feature.update(feature_params)
61
- format.html { redirect_to @featureable, notice: 'Feature was successfully updated.' }
62
- format.json { head :no_content }
63
- else
64
- format.html { redirect_to @featureable, alert: @feature.errors.full_messages.join(',') }
65
- format.json { render json: @feature.errors, status: :unprocessable_entity }
66
- end
67
- end
68
- end
69
-
70
- def destroy
71
- @feature = Feature.find(params[:id])
72
- @feature.destroy
73
-
74
- respond_to do |format|
75
- format.html { redirect_to @featureable, notice: 'Feature was successfully removed.' }
76
- format.json { head :no_content }
77
- end
78
- end
79
-
80
- private
81
-
82
- def feature_params
83
- params.require(:feature).permit(:position, :category)
84
- end
85
-
86
- def find_featureable
87
- resource, id = request.path.split('/')[1, 2]
88
- @featureable = resource.singularize.classify.constantize.find(id)
89
- end
2
+ authorize_resource if defined?(CanCan::Ability)
3
+
4
+ before_filter :find_featureable
5
+
6
+ def index
7
+ @features = Feature.all
8
+
9
+ respond_to do |format|
10
+ format.html
11
+ format.json { render json: @features }
12
+ end
13
+ end
14
+
15
+ def show
16
+ @feature = Feature.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html
20
+ format.json { render json: @feature }
21
+ end
22
+ end
23
+
24
+ def new
25
+ @feature = @featureable.features.build
26
+
27
+ respond_to do |format|
28
+ format.html
29
+ format.json { render json: @feature }
30
+ end
31
+ end
32
+
33
+ def edit
34
+ @feature = Feature.find(params[:id])
35
+
36
+ respond_to do |format|
37
+ format.html
38
+ format.json { render json: @feature }
39
+ end
40
+ end
41
+
42
+ def create
43
+ @feature = @featureable.features.build(feature_params)
44
+
45
+ respond_to do |format|
46
+ if @feature.save
47
+ format.html { redirect_to @featureable, notice: 'Feature was successfully created.' }
48
+ format.json { render json: @feature, status: :created, location: @feature }
49
+ else
50
+ format.html { redirect_to @featureable, alert: @feature.errors.full_messages.join(',') }
51
+ format.json { render json: @feature.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ def update
57
+ @feature = Feature.find(params[:id])
58
+
59
+ respond_to do |format|
60
+ if @feature.update(feature_params)
61
+ format.html { redirect_to @featureable, notice: 'Feature was successfully updated.' }
62
+ format.json { head :no_content }
63
+ else
64
+ format.html { redirect_to @featureable, alert: @feature.errors.full_messages.join(',') }
65
+ format.json { render json: @feature.errors, status: :unprocessable_entity }
66
+ end
67
+ end
68
+ end
69
+
70
+ def destroy
71
+ @feature = Feature.find(params[:id])
72
+ @feature.destroy
73
+
74
+ respond_to do |format|
75
+ format.html { redirect_to @featureable, notice: 'Feature was successfully removed.' }
76
+ format.json { head :no_content }
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def feature_params
83
+ params.require(:feature).permit(:position, :category)
84
+ end
85
+
86
+ def find_featureable
87
+ resource, id = request.path.split('/')[1, 2]
88
+ @featureable = resource.singularize.classify.constantize.find(id)
89
+ end
90
90
  end
@@ -1,9 +1,9 @@
1
1
  module FeaturesHelper
2
- def feature_form_for(featureable)
3
- render 'features/form', :featureable => featureable
4
- end
5
-
6
- def features_for(featureable)
7
- render 'features/features', :featureable => featureable
8
- end
2
+ def feature_form_for(featureable)
3
+ render 'features/form', :featureable => featureable
4
+ end
5
+
6
+ def features_for(featureable)
7
+ render 'features/features', :featureable => featureable
8
+ end
9
9
  end
@@ -1,76 +1,3 @@
1
1
  class Feature < ActiveRecord::Base
2
- include ActsAsFeatureable::Feature
3
-
4
- before_validation :assign_title, :assign_summary, :assign_position
5
-
6
- validate :feature_limit_not_reached, :ensure_categories
7
-
8
- validates_presence_of :featureable_id, :featureable_type
9
-
10
- validates_numericality_of :position
11
-
12
- private
13
-
14
- def ensure_categories
15
- cats = ::ActsAsFeatureable::categories
16
- # Allow all categories if set to false
17
- if cats && self.category && !cats.include?(self.category.to_sym)
18
- errors.add(:category, " is not in the list [#{cats.join(',')}]")
19
- end
20
- end
21
-
22
- def feature_limit_not_reached
23
- limit = ActsAsFeatureable.feature_limit
24
- errors.add(:base,
25
- "The feature limit of #{limit} has been reached. \
26
- Please delete or change an existing feature."
27
- ) if ActsAsFeatureable.categories ? Feature.where(category: self.category).count >= limit : Feature.count >= limit
28
- end
29
-
30
- def assign_title
31
- # If there is no title given, check the model.
32
- # Will check for the attributes in ActsAsFeatureable.auto_title_assign_list.
33
-
34
- unless self.title
35
- ActsAsFeatureable.auto_title_assign_list.each do |attr|
36
- if featureable.respond_to?(attr)
37
- self.title = featureable.send(attr)
38
- break
39
- end
40
- end
41
- end
42
- end
43
-
44
- def assign_summary
45
- # If there is no summary given, check the model.
46
- # Will check for the attributes in ActsAsFeatureable.auto_summary_assign_list.
47
-
48
- unless self.summary
49
- ActsAsFeatureable.auto_summary_assign_list.each do |attr|
50
- if featureable.respond_to?(attr)
51
- self.summary = featureable.send(attr)
52
- break
53
- end
54
- end
55
- end
56
- end
57
-
58
- def assign_position
59
- # If there is no position given, or the position given is already taken,
60
- # assign the lowest open position. Otherwise assign it.
61
- all_positions = if ActsAsFeatureable.categories
62
- Feature.select('features.position, features.category').where(category: self.category).map(&:position).sort
63
- else
64
- Feature.select('features.position').map(&:position).sort
65
- end
66
-
67
- if !self.position || (self.position && all_positions.include?(self.position))
68
- # Find lowest, non-taken position
69
- (1..ActsAsFeatureable.feature_limit).each do |n|
70
- next if all_positions.include? n
71
- self.position = n
72
- break
73
- end
74
- end
75
- end
2
+ include ActsAsFeatureable::FeatureAdditions
76
3
  end
@@ -1,5 +1,5 @@
1
1
  <div class="feature">
2
- <%= content_tag :span, feature.position, :class => 'position' %>
3
- <%= content_tag :span, feature.category, :class => 'category' %>
4
- <%= link_to 'Remove', [feature.featureable, feature], :method => :delete, :data => { :confirm => 'Are you sure?' } %>
2
+ <%= content_tag :span, feature.position, :class => 'position' %>
3
+ <%= content_tag :span, feature.category, :class => 'category' %>
4
+ <%= link_to 'Remove', [feature.featureable, feature], :method => :delete, :data => { :confirm => 'Are you sure?' } %>
5
5
  </div>
@@ -1,3 +1,3 @@
1
1
  <% featureable.features.each do |feature| %>
2
- <%= render feature %>
2
+ <%= render feature %>
3
3
  <% end unless featureable.features.empty? %>
@@ -1,19 +1,19 @@
1
1
  <% cats = ActsAsFeatureable.categories %>
2
2
 
3
3
  <%= form_for [featureable, Feature.new] do |f| %>
4
- <div class="field">
5
- <%= f.label :position %>
6
- <%= f.select :position, (1..ActsAsFeatureable.feature_limit) %>
7
- </div>
8
-
9
- <div class="field">
10
- <%= f.label :category%>
11
- <% if cats %>
12
- <%= f.select :category, cats %>
13
- <% else %>
14
- <%= f.text_field :category %>
15
- <% end %>
16
- </div>
17
-
18
- <%= f.submit %>
4
+ <div class="field">
5
+ <%= f.label :position %>
6
+ <%= f.select :position, (1..ActsAsFeatureable.feature_limit) %>
7
+ </div>
8
+
9
+ <div class="field">
10
+ <%= f.label :category%>
11
+ <% if cats %>
12
+ <%= f.select :category, cats %>
13
+ <% else %>
14
+ <%= f.text_field :category %>
15
+ <% end %>
16
+ </div>
17
+
18
+ <%= f.submit %>
19
19
  <% end %>
@@ -1,3 +1,3 @@
1
1
  <% @features.each do |feature| %>
2
- <%= render feature %>
2
+ <%= render feature %>
3
3
  <% end %>
@@ -4,5 +4,5 @@ require 'active_support/core_ext/module/attribute_accessors'
4
4
  require 'acts_as_featureable/config'
5
5
 
6
6
  require 'acts_as_featureable/version'
7
- require 'acts_as_featureable/featureable_methods'
8
- require 'acts_as_featureable/feature_methods'
7
+ require 'acts_as_featureable/featureable_additions'
8
+ require 'acts_as_featureable/feature_additions'
@@ -1,30 +1,30 @@
1
1
  module ActsAsFeatureable
2
- # Set the maximum limit of features availible.
3
- mattr_accessor :feature_limit
4
- @@feature_limit = 10
5
-
6
- # Set the order of auto title assign
7
- mattr_accessor :auto_title_assign_list
8
- @@auto_title_assign_list = [:title, :name]
9
-
10
- # Set the order of auto summary assigning
11
- mattr_accessor :auto_summary_assign_list
12
- @@auto_summary_assign_list = [:summary, :caption, :tldr, :content, :text]
13
-
14
- # Limit the categories you wish to use.
15
- # This should be an array of symbols
16
- # [:main, :articles, :images]
17
- #
18
- # false allows unlimited categories.
19
- #
20
- # The benefit of using this is gaining the scopes for which categories you include.
21
- #
22
- # Feature.articles
23
- # => [<# Feature > ,<# Feature>]
24
- mattr_accessor :categories
25
- @@categories = false
26
-
27
- def self.setup
28
- yield self
29
- end
2
+ # Set the maximum limit of features availible.
3
+ mattr_accessor :feature_limit
4
+ @@feature_limit = 10
5
+
6
+ # Set the order of auto title assign
7
+ mattr_accessor :auto_title_assign_list
8
+ @@auto_title_assign_list = [:title, :name]
9
+
10
+ # Set the order of auto summary assigning
11
+ mattr_accessor :auto_summary_assign_list
12
+ @@auto_summary_assign_list = [:summary, :caption, :tldr, :content, :text]
13
+
14
+ # Limit the categories you wish to use.
15
+ # This should be an array of symbols
16
+ # [:main, :articles, :images]
17
+ #
18
+ # false allows unlimited categories.
19
+ #
20
+ # The benefit of using this is gaining the scopes for which categories you include.
21
+ #
22
+ # Feature.articles
23
+ # => [<# Feature > ,<# Feature>]
24
+ mattr_accessor :categories
25
+ @@categories = false
26
+
27
+ def self.setup
28
+ yield self
29
+ end
30
30
  end