adva 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/adva.gemspec +3 -0
- data/app/assets/config/manifest.js +6 -0
- data/app/assets/javascripts/adva_cms/ckeditor.js.erb +12 -0
- data/app/assets/javascripts/adva_cms/concat_main_menus.js +13 -0
- data/app/assets/javascripts/adva_cms/jquery.table_tree.js +704 -0
- data/app/assets/javascripts/adva_cms.js +7 -0
- data/app/assets/javascripts/ckeditor/config.js.erb +94 -0
- data/app/assets/stylesheets/adva_cms/admin/common.scss +15 -1
- data/app/assets/stylesheets/adva_cms/admin/projection.scss +2 -5
- data/app/assets/stylesheets/adva_cms/admin/sidebar.scss +30 -9
- data/app/assets/stylesheets/adva_cms/admin.scss +1 -1
- data/app/controllers/admin/base_controller.rb +10 -24
- data/app/controllers/admin/page/articles_controller.rb +8 -27
- data/app/controllers/admin/page/categories_controller.rb +6 -9
- data/app/controllers/admin/page/links_controller.rb +6 -9
- data/app/controllers/admin/sections_controller.rb +7 -9
- data/app/controllers/admin/sites_controller.rb +9 -12
- data/app/controllers/admin/users_controller.rb +6 -9
- data/app/controllers/articles_controller.rb +30 -52
- data/app/controllers/base_controller.rb +8 -8
- data/app/controllers/password_controller.rb +3 -5
- data/app/controllers/session_controller.rb +3 -5
- data/app/helpers/activities_helper.rb +9 -20
- data/app/helpers/admin/base_helper.rb +4 -22
- data/app/helpers/base_helper.rb +1 -1
- data/app/helpers/content_helper.rb +7 -5
- data/app/helpers/resource_helper.rb +4 -5
- data/app/helpers/users_helper.rb +1 -1
- data/app/models/activity.rb +3 -0
- data/app/models/article.rb +0 -11
- data/app/models/category.rb +3 -3
- data/app/models/content.rb +10 -39
- data/app/models/link.rb +0 -1
- data/app/models/password_mailer.rb +6 -9
- data/app/models/section.rb +6 -7
- data/app/models/site.rb +0 -2
- data/app/models/user.rb +1 -2
- data/app/views/activity_notifier/new_content_notification.html.erb +5 -5
- data/app/views/admin/activities/_activities.html.erb +4 -4
- data/app/views/admin/activities/_comment.html.erb +21 -21
- data/app/views/admin/activities/_content.html.erb +4 -3
- data/app/views/admin/activities/_topic.html.erb +5 -5
- data/app/views/admin/install/confirmation.html.erb +3 -3
- data/app/views/admin/install/index.html.erb +14 -14
- data/app/views/admin/page/articles/_form.html.erb +28 -25
- data/app/views/admin/page/articles/_options.html.erb +3 -4
- data/app/views/admin/page/articles/edit.html.erb +3 -3
- data/app/views/admin/page/articles/new.html.erb +4 -4
- data/app/views/admin/page/categories/edit.html.erb +9 -9
- data/app/views/admin/page/categories/index.html.erb +16 -16
- data/app/views/admin/page/categories/new.html.erb +5 -3
- data/app/views/admin/page/contents/index.html.erb +3 -18
- data/app/views/admin/page/links/_form.html.erb +17 -17
- data/app/views/admin/page/links/_options.html.erb +16 -19
- data/app/views/admin/page/links/edit.html.erb +3 -3
- data/app/views/admin/page/links/new.html.erb +3 -3
- data/app/views/admin/sections/_form.html.haml +5 -5
- data/app/views/admin/sections/edit.html.haml +2 -2
- data/app/views/admin/sections/index.html.erb +18 -18
- data/app/views/admin/sections/new.html.erb +15 -13
- data/app/views/admin/sections/settings/_page.html.haml +4 -6
- data/app/views/admin/shared/_header.html.erb +5 -4
- data/app/views/admin/shared/_section_tree.html.erb +2 -2
- data/app/views/admin/sites/_email_notifications.html.erb +6 -7
- data/app/views/admin/sites/_form.html.erb +7 -7
- data/app/views/admin/sites/_recent_users.html.erb +4 -2
- data/app/views/admin/sites/_unapproved_comments.html.erb +1 -1
- data/app/views/admin/sites/index.html.erb +1 -1
- data/app/views/admin/sites/new.html.erb +2 -2
- data/app/views/admin/sites/show.html.erb +7 -8
- data/app/views/admin/users/edit.html.erb +1 -1
- data/app/views/admin/users/index.html.erb +10 -10
- data/app/views/admin/users/new.html.erb +1 -1
- data/app/views/admin/users/show.html.erb +7 -7
- data/app/views/layouts/admin.html.haml +3 -5
- data/app/views/layouts/login.html.erb +1 -1
- data/app/views/password/edit.html.erb +12 -5
- data/app/views/password/new.html.erb +7 -7
- data/app/views/password_mailer/reset_password_email.html.erb +21 -1
- data/app/views/password_mailer/updated_password_email.html.erb +3 -1
- data/app/views/session/new.html.erb +9 -9
- data/app/views/shared/_flash.html.erb +2 -2
- data/app/views/shared/_sidebar.html.erb +2 -2
- data/config/initializers/ckeditor.rb +61 -0
- data/config/initializers/menus.rb +1 -1
- data/config/initializers/time_format.rb +2 -0
- data/lib/adva/authenticate_user.rb +193 -0
- data/lib/{active_record → adva}/belongs_to_author.rb +4 -4
- data/lib/adva/event.rb +34 -0
- data/lib/adva/extensible_forms.rb +285 -0
- data/lib/{has_options.rb → adva/has_options.rb} +5 -7
- data/lib/adva/has_permalink.rb +36 -0
- data/lib/adva/version.rb +1 -1
- data/lib/adva.rb +10 -36
- data/lib/rails_ext/action_controller/event_helper.rb +1 -1
- data/lib/rails_ext.rb +0 -9
- data/vendor/gems/cacheable_flash/.gitignore +8 -0
- data/vendor/gems/cacheable_flash/Gemfile +8 -0
- data/vendor/gems/cacheable_flash/README.md +35 -0
- data/vendor/gems/cacheable_flash/Rakefile +4 -0
- data/vendor/gems/cacheable_flash/bin/console +15 -0
- data/vendor/gems/cacheable_flash/bin/setup +8 -0
- data/vendor/gems/cacheable_flash/cacheable_flash.gemspec +38 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/controller.rb +29 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/javascript.js +19 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/middleware.rb +30 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/version.rb +5 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash.rb +12 -0
- data/vendor/gems/simple_taggable/lib/tag_list.rb +1 -1
- data/vendor/gems/tags/lib/menu.rb +1 -1
- data/vendor/gems/tags/lib/tags/tag.rb +1 -1
- metadata +72 -145
- data/app/assets/javascripts/adva_cms/admin/jquery.admin.js +0 -23
- data/app/assets/javascripts/adva_cms/admin/jquery.article.js +0 -22
- data/app/assets/javascripts/adva_cms/admin/jquery.cached_pages.js +0 -14
- data/app/assets/javascripts/adva_cms/admin/jquery.table_tree.js +0 -7
- data/app/assets/javascripts/adva_cms/application.js +0 -13
- data/app/assets/javascripts/adva_cms/base.js +0 -4
- data/app/assets/javascripts/adva_cms/cookie.js +0 -49
- data/app/assets/javascripts/adva_cms/jquery/jquery-lowpro.js +0 -224
- data/app/assets/javascripts/adva_cms/jquery/jquery.qtip.js +0 -2085
- data/app/assets/javascripts/adva_cms/jquery/jquery.table_tree.js +0 -307
- data/app/assets/javascripts/adva_cms/jquery/jquery.tablednd_0_5.js +0 -386
- data/app/assets/javascripts/adva_cms/jquery.common.js +0 -41
- data/app/assets/javascripts/adva_cms/jquery.dates.js +0 -51
- data/app/assets/javascripts/adva_cms/jquery.flash.js +0 -59
- data/app/assets/javascripts/adva_cms/jquery.roles.js +0 -25
- data/app/assets/javascripts/adva_cms/json.js +0 -139
- data/app/controllers/admin/base_account_controller.rb +0 -13
- data/app/controllers/admin/install_controller.rb +0 -61
- data/app/controllers/admin/plugins_controller.rb +0 -38
- data/app/helpers/meta_tags_helper.rb +0 -30
- data/app/models/account.rb +0 -7
- data/app/models/event.rb +0 -34
- data/app/views/admin/articles/_meta_tags.html.erb +0 -7
- data/app/views/admin/cached_pages/_filter.html.erb +0 -8
- data/app/views/admin/cached_pages/destroy.js.erb +0 -18
- data/app/views/admin/cached_pages/index.html.erb +0 -26
- data/app/views/admin/plugins/_form.html.erb +0 -11
- data/app/views/admin/plugins/index.html.erb +0 -16
- data/app/views/admin/plugins/show.html.erb +0 -43
- data/app/views/admin/shared/_language_select.html.erb +0 -6
- data/app/views/admin/shared/_section_summary.html.erb +0 -23
- data/app/views/admin/sites/_meta_tags.html.erb +0 -15
- data/app/views/layouts/default.html.erb +0 -38
- data/app/views/layouts/simple.html.erb +0 -22
- data/app/views/shared/_footer.html.erb +0 -4
- data/app/views/shared/messages/insufficient_permissions.html.erb +0 -4
- data/config/initializers/article.rb +0 -8
- data/config/initializers/has_options.rb +0 -2
- data/config/initializers/has_permalink.rb +0 -2
- data/config/initializers/site.rb +0 -8
- data/config/locales/en.yml +0 -1319
- data/lib/action_controller/authenticate_anonymous.rb +0 -69
- data/lib/action_controller/authenticate_user.rb +0 -203
- data/lib/core_ext.rb +0 -7
- data/lib/extensible_forms.rb +0 -284
- data/lib/has_permalink.rb +0 -33
- data/lib/login/helper_integration.rb +0 -11
- data/lib/login/mail_config.rb +0 -39
- data/lib/rails_ext/action_controller/cacheable_flash.rb +0 -30
- data/lib/rails_ext/action_controller/content_for_assignments.rb +0 -106
- data/lib/rails_ext/action_controller/page_caching.rb +0 -23
- data/lib/rails_ext/action_controller/responds_to_parent.rb +0 -46
- data/lib/rails_ext/active_record/exists.rb +0 -5
- data/lib/rails_ext/active_record/sti_instantiation.rb +0 -35
- data/lib/rails_ext/active_record/sticky_changes.rb +0 -30
- data/lib/rails_ext/railties/plugin.rb +0 -58
- data/lib/rails_ext/railties/plugin_configuration.rb +0 -72
- data/lib/registry.rb +0 -49
- data/lib/tasks/translation.rake +0 -69
- data/lib/time_hacks.rb +0 -57
- data/lib/webrat_patch.rb +0 -11
- data/test/meta_tags_test.rb +0 -42
- data/vendor/gems/has_counter/.gitignore +0 -17
- data/vendor/gems/has_counter/Gemfile +0 -4
- data/vendor/gems/has_counter/LICENSE +0 -22
- data/vendor/gems/has_counter/MIT-LICENSE +0 -20
- data/vendor/gems/has_counter/README.markdown +0 -64
- data/vendor/gems/has_counter/README.md +0 -29
- data/vendor/gems/has_counter/Rakefile +0 -2
- data/vendor/gems/has_counter/db/migrate/20080601194338_create_counters_table.rb.rb +0 -13
- data/vendor/gems/has_counter/has_counter.gemspec +0 -17
- data/vendor/gems/has_counter/lib/active_record/has_counter.rb +0 -67
- data/vendor/gems/has_counter/lib/counter.rb +0 -23
- data/vendor/gems/has_counter/lib/has_counter/version.rb +0 -3
- data/vendor/gems/has_counter/lib/has_counter.rb +0 -4
- data/vendor/gems/has_counter/spec/has_counter.sqlite3.db +0 -0
- data/vendor/gems/has_counter/spec/has_counter_spec.rb +0 -55
- data/vendor/gems/has_counter/spec/spec_helper.rb +0 -117
- data/vendor/gems/has_filter/.gitignore +0 -17
- data/vendor/gems/has_filter/Gemfile +0 -4
- data/vendor/gems/has_filter/LICENSE +0 -22
- data/vendor/gems/has_filter/README.md +0 -29
- data/vendor/gems/has_filter/Rakefile +0 -2
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_add.png +0 -0
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_left.png +0 -0
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_right.png +0 -0
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_remove.png +0 -0
- data/vendor/gems/has_filter/app/assets/javascripts/has_filter/filter.js +0 -35
- data/vendor/gems/has_filter/app/assets/javascripts/has_filter/jquery.filter.js +0 -23
- data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/alternate/filter.scss +0 -102
- data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/filter.scss +0 -100
- data/vendor/gems/has_filter/app/helpers/filter_helper.rb +0 -3
- data/vendor/gems/has_filter/has_filter.gemspec +0 -17
- data/vendor/gems/has_filter/init.rb +0 -3
- data/vendor/gems/has_filter/lib/has_filter/active_record/act_macro.rb +0 -102
- data/vendor/gems/has_filter/lib/has_filter/filter/base.rb +0 -67
- data/vendor/gems/has_filter/lib/has_filter/filter/categorized.rb +0 -24
- data/vendor/gems/has_filter/lib/has_filter/filter/chain.rb +0 -45
- data/vendor/gems/has_filter/lib/has_filter/filter/set.rb +0 -80
- data/vendor/gems/has_filter/lib/has_filter/filter/state.rb +0 -25
- data/vendor/gems/has_filter/lib/has_filter/filter/tagged.rb +0 -22
- data/vendor/gems/has_filter/lib/has_filter/filter/text.rb +0 -55
- data/vendor/gems/has_filter/lib/has_filter/filter.rb +0 -17
- data/vendor/gems/has_filter/lib/has_filter/version.rb +0 -3
- data/vendor/gems/has_filter/lib/has_filter.rb +0 -22
- data/vendor/gems/has_filter/test/db/setup.rb +0 -45
- data/vendor/gems/has_filter/test/db/test.sqlite3.db +0 -0
- data/vendor/gems/has_filter/test/fixtures.rb +0 -15
- data/vendor/gems/has_filter/test/has_filter/filter_chain_test.rb +0 -41
- data/vendor/gems/has_filter/test/has_filter/filter_scopes_test.rb +0 -102
- data/vendor/gems/has_filter/test/has_filter/filter_tags_test.rb +0 -113
- data/vendor/gems/has_filter/test/has_filter/integration.rb +0 -15
- data/vendor/gems/has_filter/test/has_filter/scopes_test.rb +0 -48
- data/vendor/gems/has_filter/test/log/test.log +0 -34346
- data/vendor/gems/has_filter/test/models.rb +0 -23
- data/vendor/gems/has_filter/test/templates/has_filter/test/index.html.erb +0 -5
- data/vendor/gems/has_filter/test/test_helper.rb +0 -66
- data/vendor/gems/xss_terminate/.gitignore +0 -17
- data/vendor/gems/xss_terminate/Gemfile +0 -4
- data/vendor/gems/xss_terminate/LICENSE +0 -22
- data/vendor/gems/xss_terminate/MIT-LICENSE +0 -20
- data/vendor/gems/xss_terminate/README +0 -94
- data/vendor/gems/xss_terminate/README.md +0 -29
- data/vendor/gems/xss_terminate/Rakefile +0 -23
- data/vendor/gems/xss_terminate/lib/html5lib_sanitize.rb +0 -2453
- data/vendor/gems/xss_terminate/lib/rails_sanitize.rb +0 -8
- data/vendor/gems/xss_terminate/lib/xss_terminate/version.rb +0 -3
- data/vendor/gems/xss_terminate/lib/xss_terminate.rb +0 -141
- data/vendor/gems/xss_terminate/tasks/xss_terminate_tasks.rake +0 -7
- data/vendor/gems/xss_terminate/test/models/comment.rb +0 -5
- data/vendor/gems/xss_terminate/test/models/entry.rb +0 -7
- data/vendor/gems/xss_terminate/test/models/message.rb +0 -3
- data/vendor/gems/xss_terminate/test/models/person.rb +0 -5
- data/vendor/gems/xss_terminate/test/models/review.rb +0 -5
- data/vendor/gems/xss_terminate/test/schema.rb +0 -34
- data/vendor/gems/xss_terminate/test/setup_test.rb +0 -16
- data/vendor/gems/xss_terminate/test/xss_terminate_test.rb +0 -50
- data/vendor/gems/xss_terminate/xss_terminate.gemspec +0 -17
- /data/lib/tasks/{adva_cms.rake → adva.rake} +0 -0
@@ -1,64 +0,0 @@
|
|
1
|
-
## Has Counter
|
2
|
-
|
3
|
-
Allows to cache the number of records for a `has_many` association.
|
4
|
-
|
5
|
-
Yes, this is the same thing you can do by setting the `:counter_cache` option
|
6
|
-
on the corresponding `belongs_to` association.
|
7
|
-
|
8
|
-
The reason for reinventing the `counter_cache` wheel here is that
|
9
|
-
`counter_cache` is a bit inflexible. We need to "hardcode" the counter_cache
|
10
|
-
column and thereby clutter the schema. This can especially get annoying in
|
11
|
-
combo with STI, when - e.g. one subclass needs some `counter_caches` that are
|
12
|
-
specific to this subclass only.
|
13
|
-
|
14
|
-
Instead, with `has_counter`, counters can be separated into an external table
|
15
|
-
with generic column names.
|
16
|
-
|
17
|
-
The ActiveRecord `counter_cache` mechanism also requires to put the
|
18
|
-
`:counter_cache` directive on the `belongs_to` association of the counted class,
|
19
|
-
which adds some tight coupleing that we might want to avoid.
|
20
|
-
|
21
|
-
Instead, with `has_counter`, we can observe the counted class and update our
|
22
|
-
counters "from the outside", so the counted class does not need to know about
|
23
|
-
the fact that somebody else keeps a counter on it.
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
class User
|
28
|
-
has_counter :posts
|
29
|
-
end
|
30
|
-
|
31
|
-
This will add a `has_one :post_counter` association to the User model as well
|
32
|
-
as the appropriate callbacks for creating the initial counter object when a
|
33
|
-
User is created and in/decrementing the counter when a Post is created or
|
34
|
-
destroyed.
|
35
|
-
|
36
|
-
For convenience it also adds a `posts_count` method to the User model that you
|
37
|
-
should use to read the actual numeric count value.
|
38
|
-
|
39
|
-
In case you need that you can use the following methods to manually
|
40
|
-
in/decrement or set the counter value:
|
41
|
-
|
42
|
-
user.posts_counter.increment! # increments and saves the counter
|
43
|
-
user.posts_counter.decrement! # decrement and saves the counter
|
44
|
-
user.posts_counter.set(5) # sets the counter to 5 and saves it
|
45
|
-
|
46
|
-
## Limitations
|
47
|
-
|
48
|
-
There are quite some. The above example expects that there is the following
|
49
|
-
association on the Posts model:
|
50
|
-
|
51
|
-
class Post
|
52
|
-
belongs_to :user
|
53
|
-
end
|
54
|
-
|
55
|
-
`User.has_counter :posts` also expects that a Post model exists and that this
|
56
|
-
is the one you want to count. At this point you can **not** count arbitrary
|
57
|
-
associations like:
|
58
|
-
|
59
|
-
class Post
|
60
|
-
has_counter :approved_comments # with special conditions/callbacks
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# HasCounter
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'has_counter'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install has_counter
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateCountersTable < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :counters, :force => true do |t|
|
4
|
-
t.references :owner, :polymorphic => true
|
5
|
-
t.string :name, :limit => 25
|
6
|
-
t.integer :count, :default => 0
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.down
|
11
|
-
drop_table :counters
|
12
|
-
end
|
13
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/has_counter/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Micah Geisel"]
|
6
|
-
gem.email = ["micah@botandrose.com"]
|
7
|
-
gem.description = %q{TODO: Write a gem description}
|
8
|
-
gem.summary = %q{TODO: Write a gem summary}
|
9
|
-
gem.homepage = ""
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "has_counter"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = HasCounter::VERSION
|
17
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module HasCounter
|
3
|
-
class << self
|
4
|
-
def included(base)
|
5
|
-
base.extend ActMacro
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
module ActMacro
|
10
|
-
def has_counter(*names)
|
11
|
-
options = names.extract_options!
|
12
|
-
callbacks = options[:callbacks] || { :after_create => :increment!, :after_destroy => :decrement! }
|
13
|
-
|
14
|
-
class_attribute :"update_counters"
|
15
|
-
self.update_counters ||= {}
|
16
|
-
|
17
|
-
names.each do |name|
|
18
|
-
counter_name = :"#{name}_counter"
|
19
|
-
owner_name = options[:as] || self.name.demodulize.underscore
|
20
|
-
class_name = options[:class_name] || name
|
21
|
-
|
22
|
-
define_method :"#{name}_count" do
|
23
|
-
send(counter_name).count
|
24
|
-
end
|
25
|
-
|
26
|
-
has_one counter_name, -> { where(name: name) },
|
27
|
-
as: :owner,
|
28
|
-
class_name: "Counter",
|
29
|
-
dependent: :delete
|
30
|
-
|
31
|
-
# create the counter lazily upon first access
|
32
|
-
class_eval <<-code, __FILE__, __LINE__
|
33
|
-
prepend Module.new {
|
34
|
-
def #{counter_name}(force_reload = false)
|
35
|
-
reload_#{counter_name} if force_reload
|
36
|
-
result = super()
|
37
|
-
if result.nil?
|
38
|
-
Counter.create!(:owner => self, :name => #{name.to_s.inspect})
|
39
|
-
reload_#{counter_name}
|
40
|
-
result = super()
|
41
|
-
end
|
42
|
-
result
|
43
|
-
end
|
44
|
-
}
|
45
|
-
code
|
46
|
-
|
47
|
-
# Wire up the counted class so that it updates our counter, basically
|
48
|
-
# an anonymous callback/observer pattern
|
49
|
-
target = class_name.to_s.classify.constantize
|
50
|
-
callbacks.keys.each do |callback|
|
51
|
-
target.send callback do |record|
|
52
|
-
owner = record.send(owner_name) if record.respond_to?(owner_name)
|
53
|
-
# do not update the counter when counter's owner (e.g. article) is not frozen (deleted)
|
54
|
-
if self === owner && !owner.frozen? && record.class == target
|
55
|
-
method = callbacks[callback]
|
56
|
-
method = method.call(record) if Proc === method
|
57
|
-
counter = owner.send(counter_name) if method
|
58
|
-
counter.send method if counter && method
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class Counter < ActiveRecord::Base
|
2
|
-
belongs_to :owner, :polymorphic => true
|
3
|
-
|
4
|
-
def increment!
|
5
|
-
set count + 1
|
6
|
-
end
|
7
|
-
|
8
|
-
def increment_by!(value)
|
9
|
-
set count + value
|
10
|
-
end
|
11
|
-
|
12
|
-
def decrement!
|
13
|
-
set count - 1
|
14
|
-
end
|
15
|
-
|
16
|
-
def decrement_by!(value)
|
17
|
-
set count - value
|
18
|
-
end
|
19
|
-
|
20
|
-
def set(value)
|
21
|
-
update! count: value
|
22
|
-
end
|
23
|
-
end
|
Binary file
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/spec_helper.rb")
|
2
|
-
|
3
|
-
describe "has_counter:", "using default after_create and after_destroy callbacks" do
|
4
|
-
before :each do
|
5
|
-
Counter.delete_all
|
6
|
-
CounterSpec::Content.delete_all
|
7
|
-
CounterSpec::Comment.delete_all
|
8
|
-
|
9
|
-
@content = CounterSpec::Content.create! :title => 'first content'
|
10
|
-
end
|
11
|
-
|
12
|
-
it "instantiates a counter" do
|
13
|
-
@content.comments.create! :text => 'first comment'
|
14
|
-
@content.comments_counter.should_not be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "increments the counter on creation" do
|
18
|
-
@content.comments.create! :text => 'first comment'
|
19
|
-
@content.comments_count.should == 1
|
20
|
-
end
|
21
|
-
|
22
|
-
it "decrements the counter on deletion" do
|
23
|
-
@comment = @content.comments.create! :text => 'first comment'
|
24
|
-
@comment.destroy
|
25
|
-
@content.comments_count.should == 0
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "has_counter:", "using a method name as after_create and after_destroy callbacks" do
|
30
|
-
before :each do
|
31
|
-
Counter.delete_all
|
32
|
-
CounterSpec::Content.delete_all
|
33
|
-
CounterSpec::Comment.delete_all
|
34
|
-
|
35
|
-
@content = CounterSpec::Content.create! :title => 'first content'
|
36
|
-
end
|
37
|
-
|
38
|
-
it "instantiates a counter" do
|
39
|
-
@content.comments.create! :text => 'first comment'
|
40
|
-
@content.approved_comments_counter.should_not be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "increments the counter on creation" do
|
44
|
-
@content.comments.create! :text => 'first comment', :approved => 1
|
45
|
-
@content.approved_comments_count.should == 1
|
46
|
-
end
|
47
|
-
|
48
|
-
it "decrements the counter on deletion" do
|
49
|
-
@comment = @content.comments.create! :text => 'first comment', :approved => 1
|
50
|
-
@content.approved_comments_count.should == 1
|
51
|
-
@comment.destroy
|
52
|
-
@content.reload
|
53
|
-
@content.approved_comments_count.should == 0
|
54
|
-
end
|
55
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__) + '/../lib/'
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] = "test"
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'active_record'
|
7
|
-
|
8
|
-
ActiveRecord::Base.class_eval do
|
9
|
-
class << self
|
10
|
-
# no peeping toms (aka observers) wanted here
|
11
|
-
alias_method :dont_instantiate_observers, :instantiate_observers
|
12
|
-
def instantiate_observers; end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
17
|
-
require 'spec'
|
18
|
-
require 'spec/rails'
|
19
|
-
|
20
|
-
config = {'adapter' => 'sqlite3', 'dbfile' => File.dirname(__FILE__) + '/has_counter.sqlite3.db'}
|
21
|
-
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/has_counter.spec.log')
|
22
|
-
ActiveRecord::Base.establish_connection(config)
|
23
|
-
|
24
|
-
require 'counter'
|
25
|
-
unless Counter.table_exists?
|
26
|
-
ActiveRecord::Migration.verbose = false
|
27
|
-
ActiveRecord::Schema.define(:version => 1) do
|
28
|
-
create_table :counters, :force => true do |t|
|
29
|
-
t.references :owner, :polymorphic => true
|
30
|
-
t.string :name, :limit => 25
|
31
|
-
t.integer :count, :default => 0
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module CounterSpec
|
37
|
-
class Comment < ActiveRecord::Base
|
38
|
-
self.table_name = 'comments'
|
39
|
-
|
40
|
-
belongs_to :content
|
41
|
-
after_save :update_commentable
|
42
|
-
after_destroy :update_commentable
|
43
|
-
|
44
|
-
unless table_exists?
|
45
|
-
ActiveRecord::Migration.verbose = false
|
46
|
-
ActiveRecord::Schema.define(:version => 1) do
|
47
|
-
create_table :comments, :force => true do |t|
|
48
|
-
t.references :content
|
49
|
-
t.text :text
|
50
|
-
t.integer :approved
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def unapproved?
|
56
|
-
!approved?
|
57
|
-
end
|
58
|
-
|
59
|
-
def just_approved?
|
60
|
-
approved? && approved_changed?
|
61
|
-
end
|
62
|
-
|
63
|
-
def just_unapproved?
|
64
|
-
!approved? && approved_changed?
|
65
|
-
end
|
66
|
-
|
67
|
-
def update_commentable
|
68
|
-
content.after_comment_update(self)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class Content < ActiveRecord::Base
|
73
|
-
self.table_name = 'contents'
|
74
|
-
|
75
|
-
has_many :comments
|
76
|
-
|
77
|
-
has_counter :comments,
|
78
|
-
:class_name => 'CounterSpec::Comment'
|
79
|
-
|
80
|
-
has_counter :approved_comments,
|
81
|
-
:class_name => 'CounterSpec::Comment',
|
82
|
-
:after_create => false,
|
83
|
-
:after_destroy => false
|
84
|
-
# :after_destroy => lambda{|record|
|
85
|
-
# :decrement! if record.approved?
|
86
|
-
# },
|
87
|
-
# :after_save => lambda{|record|
|
88
|
-
# record.just_approved? && :increment! or
|
89
|
-
# record.just_unapproved? && :decrement!
|
90
|
-
# }
|
91
|
-
|
92
|
-
def after_comment_update(comment)
|
93
|
-
method = if comment.frozen? && comment.approved?
|
94
|
-
:decrement!
|
95
|
-
elsif comment.just_approved?
|
96
|
-
:increment!
|
97
|
-
elsif comment.just_unapproved?
|
98
|
-
:decrement!
|
99
|
-
end
|
100
|
-
approved_comments_counter.send method if method
|
101
|
-
end
|
102
|
-
|
103
|
-
unless table_exists?
|
104
|
-
ActiveRecord::Migration.verbose = false
|
105
|
-
ActiveRecord::Schema.define(:version => 1) do
|
106
|
-
create_table :contents, :force => true do |t|
|
107
|
-
t.string :title, :limit => 50
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Micah Geisel
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# HasFilter
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'has_filter'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install has_filter
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,35 +0,0 @@
|
|
1
|
-
Filter = {
|
2
|
-
select_filter: function(event) {
|
3
|
-
var set = this.parentNode;
|
4
|
-
var name = this.options[this.selectedIndex].value;
|
5
|
-
|
6
|
-
Element.select(set, '.filter').each(function(e) { e.removeClassName('selected'); });
|
7
|
-
Element.select(set, '.filter_' + name)[0].addClassName('selected');
|
8
|
-
},
|
9
|
-
add_filter: function(event) {
|
10
|
-
this.blur();
|
11
|
-
var form = this.parentNode.parentNode.parentNode;
|
12
|
-
var set = this.parentNode.parentNode.cloneNode(true);
|
13
|
-
|
14
|
-
form.insertBefore(set, this.parentNode.parentNode.nextSibling);
|
15
|
-
Element.select(set, '.filter_remove')[0].removeClassName('first')
|
16
|
-
|
17
|
-
Event.observe(Element.select(set, '.selected_filter')[0], 'click', Filter.select_filter);
|
18
|
-
Event.observe(Element.select(set, '.filter_add')[0], 'click', Filter.add_filter);
|
19
|
-
Event.observe(Element.select(set, '.filter_remove')[0], 'click', Filter.remove_filter);
|
20
|
-
|
21
|
-
event.preventDefault();
|
22
|
-
},
|
23
|
-
remove_filter: function(event) {
|
24
|
-
this.blur();
|
25
|
-
var filter = this.parentNode.parentNode;
|
26
|
-
Element.remove(filter);
|
27
|
-
event.preventDefault();
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
Event.addBehavior({
|
32
|
-
'.selected_filter:click': Filter.select_filter,
|
33
|
-
'.filter_add:click': Filter.add_filter,
|
34
|
-
'.remove_filter:click': Filter.remove_filter
|
35
|
-
});
|
@@ -1,23 +0,0 @@
|
|
1
|
-
var Filter = {
|
2
|
-
add: function() {
|
3
|
-
var set = $(this).closest('.set');
|
4
|
-
set.clone().insertBefore(set);
|
5
|
-
$('.filter_remove', set).removeClass('first');
|
6
|
-
},
|
7
|
-
remove: function() {
|
8
|
-
$(this).closest('.set').remove();
|
9
|
-
},
|
10
|
-
select: function() {
|
11
|
-
var set = $(this).closest('.set');
|
12
|
-
var name = this.options[this.selectedIndex].value;
|
13
|
-
|
14
|
-
$('.filter', set).removeClass('selected');
|
15
|
-
$($('.filter_' + name, set)[0]).addClass('selected');
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
$(function() {
|
20
|
-
$(document).on('click', '.selected_filter', Filter.select);
|
21
|
-
$(document).on('click', '.filter_add', Filter.add);
|
22
|
-
$(document).on('click', '.filter_remove', Filter.remove);
|
23
|
-
});
|
@@ -1,102 +0,0 @@
|
|
1
|
-
#filters {
|
2
|
-
position: relative;
|
3
|
-
padding: 0;
|
4
|
-
margin-top: 15px;
|
5
|
-
}
|
6
|
-
#filters .set {
|
7
|
-
position: relative;
|
8
|
-
background-color: #ebecec;
|
9
|
-
margin-bottom: 2px;
|
10
|
-
padding: 3px 5px;
|
11
|
-
}
|
12
|
-
#filters .set fieldset {
|
13
|
-
display: none;
|
14
|
-
}
|
15
|
-
#filters .selected_filter, #filters .set .selected {
|
16
|
-
display: inline;
|
17
|
-
float: left;
|
18
|
-
vertical-align: middle;
|
19
|
-
}
|
20
|
-
#filters .set select {
|
21
|
-
vertical-align: middle;
|
22
|
-
}
|
23
|
-
#filters .set input[type=text] {
|
24
|
-
width: 40px;
|
25
|
-
font-size: 0.9em;
|
26
|
-
vertical-align: middle;
|
27
|
-
padding-right: 3px;
|
28
|
-
padding-left: 3px;
|
29
|
-
}
|
30
|
-
#filters .set input[type=checkbox] {
|
31
|
-
vertical-align: middle;
|
32
|
-
}
|
33
|
-
#filters .set label {
|
34
|
-
display: inline;
|
35
|
-
margin: -2px 0 2px 0;
|
36
|
-
font-weight: normal;
|
37
|
-
font-size: 0.85em;
|
38
|
-
vertical-align: baseline;
|
39
|
-
}
|
40
|
-
#filters .set .controls {
|
41
|
-
padding: 0;
|
42
|
-
margin: 4px 0 0;
|
43
|
-
height: 18px;
|
44
|
-
vertical-align: middle;
|
45
|
-
float: right;
|
46
|
-
display: inline;
|
47
|
-
}
|
48
|
-
#filters .set .controls a {
|
49
|
-
outline: 0px;
|
50
|
-
width: 18px;
|
51
|
-
padding: 0;
|
52
|
-
height: 18px;
|
53
|
-
display: block;
|
54
|
-
text-align: center;
|
55
|
-
color: #7d7d7d;
|
56
|
-
float: right;
|
57
|
-
margin-left: 3px;
|
58
|
-
text-decoration: none;
|
59
|
-
}
|
60
|
-
#filters .set .controls a.filter_add {
|
61
|
-
background: image_url("has_filter/filter_add.png") no-repeat center center;
|
62
|
-
}
|
63
|
-
#filters .set .controls a.filter_remove {
|
64
|
-
background: image_url("has_filter/filter_remove.png") left top;
|
65
|
-
}
|
66
|
-
#filters .set:first-child .controls a.filter_remove {
|
67
|
-
display: none;
|
68
|
-
text-indent: 18px;
|
69
|
-
}
|
70
|
-
#filters .set .controls a.filter_add {
|
71
|
-
/* margin-right: 4px;*/
|
72
|
-
}
|
73
|
-
#filters .set .controls a.filter_remove {
|
74
|
-
/* margin-left: -4px;*/
|
75
|
-
}
|
76
|
-
#filters div.submit {
|
77
|
-
float: right;
|
78
|
-
height: 18px;
|
79
|
-
padding: 0;
|
80
|
-
padding-left: 16px;
|
81
|
-
background: image_url("has_filter/filter_button_left.png") no-repeat left top;
|
82
|
-
vertical-align: top;
|
83
|
-
margin-right: 2px;
|
84
|
-
display: block;
|
85
|
-
}
|
86
|
-
|
87
|
-
#filters div.submit button {
|
88
|
-
padding: 0px 16px 0px 0;
|
89
|
-
margin-right: -2px;
|
90
|
-
border: 0;
|
91
|
-
background: image_url("has_filter/filter_button_right.png") repeat-x right top;
|
92
|
-
font-size: 11px;
|
93
|
-
height: 20px;
|
94
|
-
color: #555;
|
95
|
-
outline: none;
|
96
|
-
text-decoration: none;
|
97
|
-
}
|
98
|
-
|
99
|
-
#filters div.submit button:hover {
|
100
|
-
color: #000;
|
101
|
-
cursor: pointer;
|
102
|
-
}
|