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 +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +6 -2
- data/Rakefile +2 -2
- data/acts_as_featureable.gemspec +19 -19
- data/app/controllers/features_controller.rb +88 -88
- data/app/helpers/features_helper.rb +7 -7
- data/app/models/feature.rb +1 -74
- data/app/views/features/_feature.html.erb +3 -3
- data/app/views/features/_features.html.erb +1 -1
- data/app/views/features/_form.html.erb +15 -15
- data/app/views/features/index.html.erb +1 -1
- data/lib/acts_as_featureable.rb +2 -2
- data/lib/acts_as_featureable/config.rb +28 -28
- data/lib/acts_as_featureable/engine.rb +7 -7
- data/lib/acts_as_featureable/feature_additions.rb +96 -0
- data/lib/acts_as_featureable/featureable_additions.rb +17 -0
- data/lib/acts_as_featureable/version.rb +1 -1
- data/lib/generators/features_generator.rb +12 -12
- data/lib/generators/templates/create_features.rb +12 -12
- data/lib/generators/templates/initializer.rb +13 -13
- data/spec/extra/model.rb +1 -1
- data/spec/extra/schema.rb +15 -15
- data/spec/factories/topics.rb +4 -4
- data/spec/helpers/features_helper_spec.rb +20 -20
- data/spec/models/feature_spec.rb +122 -127
- data/spec/models/featureable_spec.rb +4 -4
- data/spec/spec_helper.rb +6 -6
- metadata +4 -6
- data/lib/acts_as_featureable/feature_methods.rb +0 -20
- data/lib/acts_as_featureable/featureable_methods.rb +0 -17
- data/spec/dummy/log/test.log +0 -34618
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da0913e97c15dd0b9f312c91c8b9ac0c7cbee9db
|
4
|
+
data.tar.gz: 61381268c7f755346dfbe4968ce6491d524a2aec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256f4f5a3b7664cea18e224e9fd75d0ef9570096c9ae9106e8e1252f0f9da1274cc4ba48a7612c977ca5b3df38a7f1ef095952c92d52b1eb42346b23d7dcda16
|
7
|
+
data.tar.gz: f189187baf2ae53bf9c670aedb24242690dcfa7049d26ebaf2b16c387334b1f63ecd9231bcde43e1eff16647950b707baffeb1feba9c16599e939e3239e8fa0f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
-
*
|
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
|
-
*
|
15
|
+
* Initial release
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
begin
|
3
|
-
|
3
|
+
require 'bundler/setup'
|
4
4
|
rescue LoadError
|
5
|
-
|
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__)
|
data/acts_as_featureable.gemspec
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
21
|
+
spec.add_dependency "rails", "~> 4.0.0.rc1"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/app/models/feature.rb
CHANGED
@@ -1,76 +1,3 @@
|
|
1
1
|
class Feature < ActiveRecord::Base
|
2
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
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,19 +1,19 @@
|
|
1
1
|
<% cats = ActsAsFeatureable.categories %>
|
2
2
|
|
3
3
|
<%= form_for [featureable, Feature.new] do |f| %>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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 %>
|
data/lib/acts_as_featureable.rb
CHANGED
@@ -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/
|
8
|
-
require 'acts_as_featureable/
|
7
|
+
require 'acts_as_featureable/featureable_additions'
|
8
|
+
require 'acts_as_featureable/feature_additions'
|
@@ -1,30 +1,30 @@
|
|
1
1
|
module ActsAsFeatureable
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|