adva 0.1.4 → 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/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 +71 -144
- 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,100 +0,0 @@
|
|
1
|
-
#filters {
|
2
|
-
min-width: 320px;
|
3
|
-
position: relative;
|
4
|
-
padding-top: 15px;
|
5
|
-
}
|
6
|
-
#filters .set {
|
7
|
-
position: relative;
|
8
|
-
white-space: nowrap;
|
9
|
-
padding: 0;
|
10
|
-
margin-bottom: 2px;
|
11
|
-
background-color: #e8e8e8;
|
12
|
-
}
|
13
|
-
#filters .set fieldset {
|
14
|
-
display: none;
|
15
|
-
vertical-align: middle;
|
16
|
-
padding: 0;
|
17
|
-
}
|
18
|
-
#filters .selected_filter,
|
19
|
-
#filters .set .selected {
|
20
|
-
display: inline-block;
|
21
|
-
}
|
22
|
-
#filters .set select {
|
23
|
-
vertical-align: middle;
|
24
|
-
}
|
25
|
-
#filters .set input[type=text] {
|
26
|
-
width: 50px;
|
27
|
-
padding: 1px 5px 2px 5px;
|
28
|
-
font-size: 0.9em;
|
29
|
-
vertical-align: middle;
|
30
|
-
}
|
31
|
-
#filters .set input[type=checkbox] {
|
32
|
-
vertical-align: middle;
|
33
|
-
}
|
34
|
-
#filters .set label {
|
35
|
-
display: inline;
|
36
|
-
margin: -2px 0 2px 0;
|
37
|
-
font-weight: normal;
|
38
|
-
font-size: 0.85em;
|
39
|
-
vertical-align: baseline;
|
40
|
-
}
|
41
|
-
#filters .set .controls {
|
42
|
-
display: inline-block;
|
43
|
-
position: absolute;
|
44
|
-
right: 4px;
|
45
|
-
top: 3px;
|
46
|
-
width: 36px;
|
47
|
-
height: 18px;
|
48
|
-
}
|
49
|
-
#filters .set .controls a {
|
50
|
-
display: inline-block;
|
51
|
-
float: right;
|
52
|
-
overflow: hidden;
|
53
|
-
width: 18px;
|
54
|
-
height: 18px;
|
55
|
-
outline: 0px;
|
56
|
-
text-indent: 18px;
|
57
|
-
}
|
58
|
-
#filters .set .controls a.filter_add {
|
59
|
-
background: image_url("has_filter/filter_add.png") left top;
|
60
|
-
}
|
61
|
-
#filters .set .controls a.filter_remove {
|
62
|
-
background: image_url("has_filter/filter_remove.png") left top;
|
63
|
-
}
|
64
|
-
#filters .set:first-child .controls a.filter_remove {
|
65
|
-
display: none;
|
66
|
-
text-indent: 20px;
|
67
|
-
}
|
68
|
-
#filters .set .controls a.filter_add {
|
69
|
-
/* margin-right: 4px;*/
|
70
|
-
}
|
71
|
-
#filters .set .controls a.filter_remove {
|
72
|
-
/* margin-left: -4px;*/
|
73
|
-
}
|
74
|
-
#filters div.submit {
|
75
|
-
height: 18px;
|
76
|
-
padding: 0;
|
77
|
-
padding-left: 16px;
|
78
|
-
margin-right: 2px;
|
79
|
-
background: image_url("has_filter/filter_button_left.png") repeat-x left top;
|
80
|
-
vertical-align: top;
|
81
|
-
}
|
82
|
-
|
83
|
-
#filters div.submit button {
|
84
|
-
display: block;
|
85
|
-
float: right;
|
86
|
-
padding: 0px 16px 0px 0px;
|
87
|
-
margin-right: -2px;
|
88
|
-
border: 0;
|
89
|
-
background: image_url("has_filter/filter_button_right.png") repeat-x right top;
|
90
|
-
font-size: 11px;
|
91
|
-
height: 20px;
|
92
|
-
color: #555;
|
93
|
-
outline: none;
|
94
|
-
text-decoration: none;
|
95
|
-
}
|
96
|
-
|
97
|
-
#filters div.submit button:hover {
|
98
|
-
color: #333;
|
99
|
-
cursor: pointer;
|
100
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/has_filter/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_filter"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = HasFilter::VERSION
|
17
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# Heavily inspired by Noel Rappin's "More Named Scope Awesomeness"
|
2
|
-
# http://www.pathf.com/blogs/2008/06/more-named-scope-awesomeness/
|
3
|
-
|
4
|
-
module HasFilter
|
5
|
-
# # raised when filter_by is called with an attribute that has not been
|
6
|
-
# # whitelisted for being filtered
|
7
|
-
# class IllegalAttributeAccessError < ActiveRecordError
|
8
|
-
# attr_reader :attribute
|
9
|
-
# def initialize(attribute)
|
10
|
-
# @attribute = attribute
|
11
|
-
# super "Tried to filter by #{attribute.inspect}. This attribute has not been whitelisted for filtering."
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
|
15
|
-
module ActiveRecord
|
16
|
-
module ActMacro
|
17
|
-
def has_filter(*filters)
|
18
|
-
return if has_filter?
|
19
|
-
include InstanceMethods
|
20
|
-
extend ClassMethods
|
21
|
-
|
22
|
-
class_attribute :filter_chain
|
23
|
-
self.filter_chain = ::HasFilter::Filter::Chain.build(self, filters)
|
24
|
-
|
25
|
-
scopes = { # FIXME make these extensible
|
26
|
-
:is => ["=" ],
|
27
|
-
:is_not => ["<>"],
|
28
|
-
:contains => ["LIKE", "%%%s%"],
|
29
|
-
:does_not_contain => ["NOT LIKE", "%%%s%"],
|
30
|
-
:starts_with => ["LIKE", "%s%" ],
|
31
|
-
:does_not_start_with => ["NOT LIKE", "%s%" ],
|
32
|
-
:ends_with => ["LIKE", "%%%s" ],
|
33
|
-
:does_not_end_with => ["NOT LIKE", "%%%s" ] }
|
34
|
-
# FIXME add these
|
35
|
-
# created_before, created_after
|
36
|
-
# updated_before, updated_after
|
37
|
-
|
38
|
-
scopes.each do |name, scope|
|
39
|
-
scope name, lambda { |column, value| filter_scope(column, Array(value), *scope) }
|
40
|
-
end
|
41
|
-
|
42
|
-
scope :contains_all, contains_all_scope
|
43
|
-
scope :categorized, categorized_scope
|
44
|
-
end
|
45
|
-
|
46
|
-
def filtered(filters)
|
47
|
-
scope = scope(:find).blank? ? self : scoped(scope(:find))
|
48
|
-
filter_chain.select(filters).scope(scope)
|
49
|
-
end
|
50
|
-
|
51
|
-
def has_filter?
|
52
|
-
included_modules.include? HasFilter::ActiveRecord::InstanceMethods
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
module ClassMethods
|
57
|
-
protected
|
58
|
-
def contains_all_scope
|
59
|
-
lambda { |column, values|
|
60
|
-
values = values.split(' ') if values.is_a?(String)
|
61
|
-
values.map! { |value| "%#{value}%" }
|
62
|
-
{ :conditions => [(["#{column} LIKE ?"] * values.size).join(' AND '), *values] }
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
def categorized_scope
|
67
|
-
lambda { |*ids|
|
68
|
-
{ :select => "#{table_name}.*, COUNT(*) AS count",
|
69
|
-
:joins => { :categorizations => :category },
|
70
|
-
:conditions => ["#{reflect_on_association(:categories).table_name}.id IN(?)", ids],
|
71
|
-
:group => "#{table_name}.id HAVING count >= #{ids.size}" }
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
def filter_scope(column, values, operator, format = nil)
|
76
|
-
query = (["#{column} #{operator} ?"] * values.size)
|
77
|
-
# FIXME why did we have .map($:downcase) here ?
|
78
|
-
values = values.map{ |value| format ? format % value : value } # .map(&:downcase)
|
79
|
-
scope = { :conditions => [query.join(' OR '), *values] }
|
80
|
-
translated?(column) ? merge_globalization_scope(scope) : scope
|
81
|
-
end
|
82
|
-
|
83
|
-
def translated?(column)
|
84
|
-
# FIXME really should be in globalize
|
85
|
-
respond_to?(:globalize_options) && globalize_options[:translated_attributes].include?(column.to_sym)
|
86
|
-
end
|
87
|
-
|
88
|
-
def merge_globalization_scope(scope)
|
89
|
-
if scope.has_key?(:conditions)
|
90
|
-
scope[:conditions][0] += " AND current = ?"
|
91
|
-
scope[:conditions] << true
|
92
|
-
scope.merge!(:joins => :globalize_translations, :group => "#{self.table_name}.id")
|
93
|
-
else
|
94
|
-
scope.merge!(:joins => :globalize_translations, :group => "#{self.table_name}.id", :conditions => ['current = ?', true])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
module InstanceMethods
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module HasFilter
|
2
|
-
module Filter
|
3
|
-
class Base
|
4
|
-
class_attribute :scopes, :priority
|
5
|
-
attr_accessor :set, :options
|
6
|
-
delegate :view, :to => :set
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def build(*args)
|
10
|
-
[new(*args)]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(options = {})
|
15
|
-
@options = options
|
16
|
-
end
|
17
|
-
|
18
|
-
def attribute
|
19
|
-
@options[:attribute] if @options
|
20
|
-
end
|
21
|
-
|
22
|
-
def matches?(name)
|
23
|
-
type == name
|
24
|
-
end
|
25
|
-
|
26
|
-
def select(selected)
|
27
|
-
@selected = selected
|
28
|
-
end
|
29
|
-
|
30
|
-
def selected
|
31
|
-
@selected ||= {}
|
32
|
-
end
|
33
|
-
|
34
|
-
def selected?
|
35
|
-
set.selected?(type)
|
36
|
-
end
|
37
|
-
|
38
|
-
def type
|
39
|
-
@type ||= self.class.name.demodulize.underscore.to_sym
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_field_set_tag(options = {})
|
43
|
-
view.capture do
|
44
|
-
options.reverse_merge! :id => "filter_#{type}_#{set.index}", :class => "filter filter_#{attribute || type}"
|
45
|
-
options[:class] += ' selected' if selected?
|
46
|
-
view.field_set_tag(nil, options.slice(:id, :class, :label)) do
|
47
|
-
to_form_fields(options).join("\n")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def filter_select_option
|
53
|
-
[I18n.t(type, :scope => :'has_filter.filters', :default => type.to_s.gsub('_', ' ')), type]
|
54
|
-
end
|
55
|
-
|
56
|
-
protected
|
57
|
-
|
58
|
-
def form_field_name(*keys)
|
59
|
-
"filters[]" + keys.map { |key| "[#{key}]" }.join
|
60
|
-
end
|
61
|
-
|
62
|
-
def form_field_id(*keys)
|
63
|
-
"filter" + keys.map { |key| "_#{key}" }.join + "_#{set.index}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module HasFilter
|
2
|
-
module Filter
|
3
|
-
class Categorized < Base
|
4
|
-
self.priority = 4
|
5
|
-
self.scopes = [:categories]
|
6
|
-
|
7
|
-
def to_form_fields(options = {})
|
8
|
-
options[:categories].blank? ? [] : [categories_select_tag(options)]
|
9
|
-
end
|
10
|
-
|
11
|
-
def scope(target)
|
12
|
-
target.categorized(*selected)
|
13
|
-
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
|
17
|
-
def categories_select_tag(options = {})
|
18
|
-
categories = options[:categories].map { |c| [c.title, c.id] }
|
19
|
-
options = view.options_for_select(categories, selected)
|
20
|
-
view.select_tag(form_field_name(:categorized, nil), options, :id => form_field_id(:categorized, :id))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# A filter chain is a collection of filter sets. A filter set hold individual
|
2
|
-
# filters of which only one can be active/selected at a time.
|
3
|
-
|
4
|
-
module HasFilter
|
5
|
-
module Filter
|
6
|
-
class Chain < Array
|
7
|
-
class << self
|
8
|
-
def build(owner, *args)
|
9
|
-
new owner, Set.build(*args)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :owner, :view
|
14
|
-
|
15
|
-
def initialize(owner, *sets)
|
16
|
-
@owner = owner
|
17
|
-
concat sets.each { |set| set.chain = self }
|
18
|
-
end
|
19
|
-
|
20
|
-
def select(params)
|
21
|
-
params ||= []
|
22
|
-
adjust_size(params)
|
23
|
-
each { |set| set.select(params[set.index]) }
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def scope(target = nil)
|
28
|
-
inject(target || owner) { |target, set| set.scope(target) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_form_fields(view, options = {})
|
32
|
-
@view = view
|
33
|
-
map { |set| set.to_field_set_tag(options) }
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
def adjust_size(params)
|
39
|
-
size = [params.size, 1].max
|
40
|
-
replace (1..size).map { first.dup }
|
41
|
-
each_with_index { |set, index| set.index = index }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module HasFilter
|
2
|
-
module Filter
|
3
|
-
class Set < Array
|
4
|
-
attr_accessor :chain, :index, :selected
|
5
|
-
delegate :view, :to => :chain
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def build(filters)
|
9
|
-
new filters.map { |filter|
|
10
|
-
case filter
|
11
|
-
when Hash
|
12
|
-
filter.map { |type, args| Filter.build(type, args) }
|
13
|
-
when Symbol
|
14
|
-
Filter.build(filter)
|
15
|
-
end
|
16
|
-
}.flatten
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(filters)
|
21
|
-
concat filters.each { |f| f.set = self }
|
22
|
-
sort!
|
23
|
-
end
|
24
|
-
|
25
|
-
def initialize_copy(orig)
|
26
|
-
super
|
27
|
-
replace orig.map { |f| f.dup }.each { |f| f.set = self }
|
28
|
-
end
|
29
|
-
|
30
|
-
def sort!
|
31
|
-
head = self.reject { |f| !f.is_a?(Text) }
|
32
|
-
replace head + (self - head).sort { |a, b| a.priority <=> b.priority }
|
33
|
-
end
|
34
|
-
|
35
|
-
def select(params)
|
36
|
-
params ||= { :selected => first.attribute || first.type }
|
37
|
-
@selected = params[:selected].to_sym
|
38
|
-
find_filter(selected).select(params[selected]) if @selected
|
39
|
-
end
|
40
|
-
|
41
|
-
def selected?(name)
|
42
|
-
selected == name
|
43
|
-
end
|
44
|
-
|
45
|
-
def first?
|
46
|
-
index == 0
|
47
|
-
end
|
48
|
-
|
49
|
-
def scope(target)
|
50
|
-
selected ? find_filter(selected).scope(target) : target
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_field_set_tag(options = {})
|
54
|
-
view.capture do
|
55
|
-
view.field_set_tag(nil, :class => 'set') do
|
56
|
-
tag = filter_select_tag(view) + "\n"
|
57
|
-
tag << map { |filter| filter.to_field_set_tag(options.dup) }.join("\n")
|
58
|
-
tag << view.content_tag(:span, :class => 'controls') do
|
59
|
-
view.content_tag(:a, '+', :href => '#', :class => 'filter_add') +
|
60
|
-
view.content_tag(:a, '-', :href => '#', :class => 'filter_remove')
|
61
|
-
end
|
62
|
-
tag
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
protected
|
68
|
-
|
69
|
-
def find_filter(type)
|
70
|
-
# FIXME ask the filter instead: filter.matches?(type) or something
|
71
|
-
detect { |filter| filter.matches?(type) }
|
72
|
-
end
|
73
|
-
|
74
|
-
def filter_select_tag(view)
|
75
|
-
options = view.options_for_select(map(&:filter_select_option), selected)
|
76
|
-
view.select_tag :'filters[][selected]', options, :id => "selected_filter_#{index}", :class => 'selected_filter'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module HasFilter
|
2
|
-
module Filter
|
3
|
-
class State < Base
|
4
|
-
self.priority = 3
|
5
|
-
self.scopes = [:state]
|
6
|
-
|
7
|
-
def to_form_fields(options = {})
|
8
|
-
@options[:states].map { |state| state_tag(state) }
|
9
|
-
end
|
10
|
-
|
11
|
-
def scope(target)
|
12
|
-
# FIXME assert that state is a valid state!
|
13
|
-
selected.inject(target) { |target, state| target.send(state) }
|
14
|
-
end
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def state_tag(state)
|
19
|
-
id = form_field_id(:state, state)
|
20
|
-
view.check_box_tag(form_field_name(:state, nil), state, selected.include?(state), :id => id) +
|
21
|
-
view.label_tag(id, I18n.t(state, :scope => :'has_filter.states', :default => state.to_s))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module HasFilter
|
2
|
-
module Filter
|
3
|
-
class Tagged < Base
|
4
|
-
self.priority = 2
|
5
|
-
self.scopes = [:tagged]
|
6
|
-
|
7
|
-
def to_form_fields(options = {})
|
8
|
-
[query_tag]
|
9
|
-
end
|
10
|
-
|
11
|
-
def scope(target)
|
12
|
-
target.tagged(selected)
|
13
|
-
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
|
17
|
-
def query_tag
|
18
|
-
view.text_field_tag(form_field_name(:tagged), selected, :id => form_field_id(:tagged, :query))
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module HasFilter
|
2
|
-
module Filter
|
3
|
-
class Text < Base
|
4
|
-
self.priority = 1
|
5
|
-
self.scopes = [:contains, :starts_with, :ends_with, :is]
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def build(args)
|
9
|
-
Array(args[:attributes]).map { |attribute| new(:attribute => attribute) }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def matches?(name)
|
14
|
-
attribute == name
|
15
|
-
end
|
16
|
-
|
17
|
-
def selected?
|
18
|
-
set.selected?(attribute)
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_field_set_tag(options = {})
|
22
|
-
options[:id] = "filter_#{attribute}_#{set.index}"
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_form_fields(options = {})
|
27
|
-
[scopes_select_tag, query_input_tag]
|
28
|
-
end
|
29
|
-
|
30
|
-
def scope(target)
|
31
|
-
# FIXME assert that scope is contained in self.scopes
|
32
|
-
scope, query = selected.values_at(:scope, :query)
|
33
|
-
query.blank? ? target : target.send(scope, attribute, query)
|
34
|
-
end
|
35
|
-
|
36
|
-
def filter_select_option
|
37
|
-
[I18n.t(attribute, :scope => :'has_filter.filters', :default => attribute.to_s.gsub('_', ' ')), attribute]
|
38
|
-
end
|
39
|
-
|
40
|
-
protected
|
41
|
-
|
42
|
-
def scopes_select_tag
|
43
|
-
options = self.class.scopes.map do |scope|
|
44
|
-
[I18n.t(scope, :scope => :'has_filter.scopes', :default => scope.to_s.gsub('_', ' ')), scope]
|
45
|
-
end
|
46
|
-
options = view.options_for_select(options, selected[:scope].try(:to_sym))
|
47
|
-
view.select_tag(form_field_name(attribute, :scope), options, :id => form_field_id(attribute, :scope))
|
48
|
-
end
|
49
|
-
|
50
|
-
def query_input_tag
|
51
|
-
view.text_field_tag(form_field_name(attribute, :query), selected[:query], :id => form_field_id(attribute, :query))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require_dependency 'has_filter/filter/base'
|
2
|
-
require_dependency 'has_filter/filter/categorized'
|
3
|
-
require_dependency 'has_filter/filter/chain'
|
4
|
-
require_dependency 'has_filter/filter/set'
|
5
|
-
require_dependency 'has_filter/filter/state'
|
6
|
-
require_dependency 'has_filter/filter/tagged'
|
7
|
-
require_dependency 'has_filter/filter/text'
|
8
|
-
|
9
|
-
module HasFilter
|
10
|
-
module Filter
|
11
|
-
class << self
|
12
|
-
def build(type, *args)
|
13
|
-
HasFilter::Filter.const_get(type.to_s.classify).build(*args)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require "has_filter/version"
|
2
|
-
require 'has_filter/filter'
|
3
|
-
require 'has_filter/active_record/act_macro'
|
4
|
-
|
5
|
-
module HasFilter
|
6
|
-
module Helper
|
7
|
-
def filter_for(klass, options = {})
|
8
|
-
form_tag(options.delete(:url) || request.path, :method => :get, :id => 'filters', :class => 'filters') do
|
9
|
-
klass.filter_chain.to_form_fields(self, options).join(raw("\n")) +
|
10
|
-
content_tag(:div, :class => 'submit') do
|
11
|
-
content_tag(:button, I18n.t(:'filter.submit.value', :default => 'Apply'))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Engine < Rails::Engine
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
ActiveRecord::Base.send :extend, HasFilter::ActiveRecord::ActMacro
|
22
|
-
ActionController::Base.send :helper, HasFilter::Helper
|
@@ -1,45 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
ActiveRecord::Base.connection
|
3
|
-
rescue ActiveRecord::ConnectionNotEstablished => e
|
4
|
-
|
5
|
-
dir_name = File.dirname(__FILE__)
|
6
|
-
log_file = "#{dir_name}/../log/test.log"
|
7
|
-
db_file = "#{dir_name}/test.sqlite3.db"
|
8
|
-
|
9
|
-
FileUtils.rm(db_file) if File.exists?(db_file)
|
10
|
-
FileUtils.mkdir_p(File.dirname(log_file)) unless File.exists?(File.dirname(log_file))
|
11
|
-
|
12
|
-
ActiveRecord::Base.logger = Logger.new log_file
|
13
|
-
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :dbfile => db_file
|
14
|
-
end
|
15
|
-
|
16
|
-
ActiveRecord::Migration.verbose = false
|
17
|
-
ActiveRecord::Schema.define(:version => 20090126133510) do
|
18
|
-
create_table "has_filter_articles", :force => true do |t|
|
19
|
-
t.string :title
|
20
|
-
t.string :body
|
21
|
-
t.integer :published
|
22
|
-
t.integer :approved
|
23
|
-
t.string :cached_tag_list
|
24
|
-
end unless ActiveRecord::Base.connection.table_exists?('has_filter_articles')
|
25
|
-
|
26
|
-
create_table "has_filter_categories", :force => true do |t|
|
27
|
-
t.string :title
|
28
|
-
end unless ActiveRecord::Base.connection.table_exists?('has_filter_categories')
|
29
|
-
|
30
|
-
create_table "has_filter_categorizations", :force => true do |t|
|
31
|
-
t.integer :category_id
|
32
|
-
t.integer :has_filter_article_id
|
33
|
-
end unless ActiveRecord::Base.connection.table_exists?('has_filter_categorizations')
|
34
|
-
|
35
|
-
create_table :tags, :force => true do |t|
|
36
|
-
t.column :name, :string
|
37
|
-
end unless ActiveRecord::Base.connection.table_exists?('tags')
|
38
|
-
|
39
|
-
create_table :taggings, :force => true do |t|
|
40
|
-
t.column :tag_id, :integer
|
41
|
-
t.column :taggable_id, :integer
|
42
|
-
t.column :taggable_type, :string
|
43
|
-
t.column :created_at, :datetime
|
44
|
-
end unless ActiveRecord::Base.connection.table_exists?('taggings')
|
45
|
-
end
|
Binary file
|
@@ -1,15 +0,0 @@
|
|
1
|
-
HasFilterArticle.destroy_all
|
2
|
-
HasFilterCategory.destroy_all
|
3
|
-
HasFilterCategorization.destroy_all
|
4
|
-
|
5
|
-
first = HasFilterArticle.create! :title => 'first', :body => 'first', :published => 1, :approved => 0, :tag_list => 'foo bar baz'
|
6
|
-
second = HasFilterArticle.create! :title => 'second', :body => 'second', :published => 1, :approved => 1, :tag_list => 'foo bar'
|
7
|
-
third = HasFilterArticle.create! :title => 'third', :body => 'third', :published => 0, :approved => 0, :tag_list => 'foo'
|
8
|
-
third = HasFilterArticle.create! :title => 'UPCASE', :body => 'UPCASE', :published => 0, :approved => 0, :tag_list => 'upcase'
|
9
|
-
|
10
|
-
foo = HasFilterCategory.create! :title => 'has_filter foo'
|
11
|
-
bar = HasFilterCategory.create! :title => 'has_filter bar'
|
12
|
-
|
13
|
-
first.categories << foo << bar
|
14
|
-
second.categories << foo
|
15
|
-
|