pages_core 3.4.2
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 +7 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/app/assets/images/pages/admin/description-bg.gif +0 -0
- data/app/assets/images/pages/admin/drag-handle.gif +0 -0
- data/app/assets/images/pages/admin/drag-icon.png +0 -0
- data/app/assets/images/pages/admin/flash-error-bg.gif +0 -0
- data/app/assets/images/pages/admin/formelement-bg.gif +0 -0
- data/app/assets/images/pages/admin/header-tab-current-bg.gif +0 -0
- data/app/assets/images/pages/admin/icon.png +0 -0
- data/app/assets/images/pages/admin/image-editor-bg.png +0 -0
- data/app/assets/images/pages/admin/list-table-pin-blue.gif +0 -0
- data/app/assets/images/pages/admin/list-table-pin-disabled.gif +0 -0
- data/app/assets/images/pages/admin/list-table-pin-green.gif +0 -0
- data/app/assets/images/pages/admin/list-table-pin-red.gif +0 -0
- data/app/assets/images/pages/admin/list-table-pin-yellow.gif +0 -0
- data/app/assets/images/pages/admin/list-table-td-bg.gif +0 -0
- data/app/assets/images/pages/admin/loading-modal.gif +0 -0
- data/app/assets/images/pages/admin/sidebar-bg.gif +0 -0
- data/app/assets/images/pages/admin/textarea_controls.gif +0 -0
- data/app/assets/images/pages/admin/warning-icon.gif +0 -0
- data/app/assets/images/pages/favicon.gif +0 -0
- data/app/assets/images/pages/feed-icon-14x14.png +0 -0
- data/app/assets/javascripts/pages/admin/controllers/base.js.coffee +4 -0
- data/app/assets/javascripts/pages/admin/controllers/pages_controller.js.coffee +139 -0
- data/app/assets/javascripts/pages/admin/controllers/users_controller.js.coffee +9 -0
- data/app/assets/javascripts/pages/admin/features/content_tabs.js.coffee +47 -0
- data/app/assets/javascripts/pages/admin/features/editable_image.js.coffee.erb +122 -0
- data/app/assets/javascripts/pages/admin/features/modal.js.coffee +66 -0
- data/app/assets/javascripts/pages/admin/features/page_images.js +329 -0
- data/app/assets/javascripts/pages/admin/features/rich_text.js.coffee +40 -0
- data/app/assets/javascripts/pages/admin/features/tag_editor.js +159 -0
- data/app/assets/javascripts/pages/admin/lib/ajax_extensions.js.coffee +17 -0
- data/app/assets/javascripts/pages/admin/lib/center_on_screen.js.coffee +21 -0
- data/app/assets/javascripts/pages/admin/lib/jrichtextarea.js +57 -0
- data/app/assets/javascripts/pages/admin.js.coffee +54 -0
- data/app/assets/javascripts/pages/login_form.js.coffee +17 -0
- data/app/assets/stylesheets/pages/admin/buttons.css.erb +5 -0
- data/app/assets/stylesheets/pages/admin/controllers/artists.css.erb +94 -0
- data/app/assets/stylesheets/pages/admin/controllers/files.css.erb +58 -0
- data/app/assets/stylesheets/pages/admin/controllers/pages.css.scss.erb +178 -0
- data/app/assets/stylesheets/pages/admin/controllers/users.css.erb +3 -0
- data/app/assets/stylesheets/pages/admin/editable_image.css.erb +19 -0
- data/app/assets/stylesheets/pages/admin/forms.css.scss.erb +73 -0
- data/app/assets/stylesheets/pages/admin/header.css.erb +129 -0
- data/app/assets/stylesheets/pages/admin/images.css.scss.erb +160 -0
- data/app/assets/stylesheets/pages/admin/links.css.erb +34 -0
- data/app/assets/stylesheets/pages/admin/list_table.css.erb +56 -0
- data/app/assets/stylesheets/pages/admin/login.css.scss.erb +32 -0
- data/app/assets/stylesheets/pages/admin/modal.css.erb +14 -0
- data/app/assets/stylesheets/pages/admin/pagination.css.scss +22 -0
- data/app/assets/stylesheets/pages/admin/print.css.erb +17 -0
- data/app/assets/stylesheets/pages/admin/sidebar.css.erb +39 -0
- data/app/assets/stylesheets/pages/admin/sortable_images.css.erb +18 -0
- data/app/assets/stylesheets/pages/admin/tag_editor.css.scss.erb +48 -0
- data/app/assets/stylesheets/pages/admin/textarea.css.erb +55 -0
- data/app/assets/stylesheets/pages/admin.css.erb +404 -0
- data/app/assets/stylesheets/pages/errors.css +126 -0
- data/app/controller_dummies/admin/admin_controller.rb +6 -0
- data/app/controller_dummies/application_controller.rb +6 -0
- data/app/controller_dummies/frontend_controller.rb +4 -0
- data/app/controller_dummies/images_controller.rb +4 -0
- data/app/controller_dummies/page_files_controller.rb +4 -0
- data/app/controller_dummies/pages_controller.rb +4 -0
- data/app/controller_dummies/sitemaps_controller.rb +4 -0
- data/app/controllers/admin/categories_controller.rb +57 -0
- data/app/controllers/admin/images_controller.rb +48 -0
- data/app/controllers/admin/invites_controller.rb +79 -0
- data/app/controllers/admin/page_comments_controller.rb +61 -0
- data/app/controllers/admin/page_files_controller.rb +81 -0
- data/app/controllers/admin/page_images_controller.rb +116 -0
- data/app/controllers/admin/pages_controller.rb +179 -0
- data/app/controllers/admin/password_resets_controller.rb +83 -0
- data/app/controllers/admin/users_controller.rb +102 -0
- data/app/controllers/concerns/pages_core/authentication.rb +48 -0
- data/app/controllers/concerns/pages_core/domain_based_cache.rb +28 -0
- data/app/controllers/concerns/pages_core/exception_handler.rb +114 -0
- data/app/controllers/concerns/pages_core/policies_helper.rb +40 -0
- data/app/controllers/concerns/pages_core/process_titler.rb +44 -0
- data/app/controllers/errors_controller.rb +45 -0
- data/app/controllers/pages_core/admin_controller.rb +109 -0
- data/app/controllers/pages_core/application_controller.rb +31 -0
- data/app/controllers/pages_core/frontend/page_files_controller.rb +42 -0
- data/app/controllers/pages_core/frontend/pages_controller.rb +308 -0
- data/app/controllers/pages_core/frontend_controller.rb +34 -0
- data/app/controllers/pages_core/images_controller.rb +15 -0
- data/app/controllers/pages_core/sitemaps_controller.rb +73 -0
- data/app/controllers/sessions_controller.rb +38 -0
- data/app/formatters/pages_core/html_formatter.rb +86 -0
- data/app/helpers/admin/admin_helper.rb +7 -0
- data/app/helpers/admin/menu_helper.rb +65 -0
- data/app/helpers/admin/pages_helper.rb +74 -0
- data/app/helpers/application_helper.rb +5 -0
- data/app/helpers/frontend_helper.rb +5 -0
- data/app/helpers/pages_core/admin/admin_helper.rb +108 -0
- data/app/helpers/pages_core/admin/labelled_field_helper.rb +73 -0
- data/app/helpers/pages_core/admin/tag_editor_helper.rb +46 -0
- data/app/helpers/pages_core/application_helper.rb +65 -0
- data/app/helpers/pages_core/form_builder.rb +187 -0
- data/app/helpers/pages_core/frontend_helper.rb +21 -0
- data/app/helpers/pages_core/head_tags_helper.rb +270 -0
- data/app/helpers/pages_core/images_helper.rb +36 -0
- data/app/helpers/pages_core/login_helper.rb +14 -0
- data/app/indices/page_file_index.rb +9 -0
- data/app/indices/page_index.rb +29 -0
- data/app/indices/user_index.rb +11 -0
- data/app/jobs/pages_core/autopublish_job.rb +11 -0
- data/app/jobs/pages_core/sweep_cache_job.rb +11 -0
- data/app/mailers/admin_mailer.rb +46 -0
- data/app/models/autopublisher.rb +33 -0
- data/app/models/category.rb +23 -0
- data/app/models/concerns/pages_core/has_roles.rb +25 -0
- data/app/models/concerns/pages_core/humanizable_param.rb +17 -0
- data/app/models/concerns/pages_core/page_tree.rb +85 -0
- data/app/models/concerns/pages_core/searchable_page.rb +33 -0
- data/app/models/concerns/pages_core/sweepable.rb +23 -0
- data/app/models/concerns/pages_core/taggable.rb +46 -0
- data/app/models/concerns/pages_core/templateable.rb +85 -0
- data/app/models/image.rb +23 -0
- data/app/models/invite.rb +33 -0
- data/app/models/invite_role.rb +11 -0
- data/app/models/localization.rb +27 -0
- data/app/models/page.rb +281 -0
- data/app/models/page_builder.rb +61 -0
- data/app/models/page_comment.rb +18 -0
- data/app/models/page_file.rb +74 -0
- data/app/models/page_image.rb +62 -0
- data/app/models/password_reset_token.rb +38 -0
- data/app/models/role.rb +51 -0
- data/app/models/tag.rb +64 -0
- data/app/models/tagging.rb +22 -0
- data/app/models/user.rb +131 -0
- data/app/policies/invite_policy.rb +29 -0
- data/app/policies/page_file_policy.rb +25 -0
- data/app/policies/page_image_policy.rb +25 -0
- data/app/policies/page_policy.rb +33 -0
- data/app/policies/policy.rb +64 -0
- data/app/policies/user_policy.rb +49 -0
- data/app/serializers/admin/image_serializer.rb +10 -0
- data/app/serializers/admin/page_image_serializer.rb +6 -0
- data/app/serializers/page_image_serializer.rb +38 -0
- data/app/serializers/page_serializer.rb +21 -0
- data/app/views/admin/invites/new.html.erb +16 -0
- data/app/views/admin/invites/show.html.erb +25 -0
- data/app/views/admin/pages/_edit_comments.html.erb +21 -0
- data/app/views/admin/pages/_edit_content.html.erb +10 -0
- data/app/views/admin/pages/_edit_images.html.erb +84 -0
- data/app/views/admin/pages/_edit_metadata.html.erb +24 -0
- data/app/views/admin/pages/_edit_options.html.erb +72 -0
- data/app/views/admin/pages/_pagelisting.html.erb +63 -0
- data/app/views/admin/pages/edit.html.erb +161 -0
- data/app/views/admin/pages/index.html.erb +67 -0
- data/app/views/admin/pages/new.html.erb +48 -0
- data/app/views/admin/pages/news.html.erb +69 -0
- data/app/views/admin/password_resets/show.html.erb +24 -0
- data/app/views/admin/users/_access_control.html.erb +14 -0
- data/app/views/admin/users/_list.html.erb +62 -0
- data/app/views/admin/users/_login_form.html.erb +47 -0
- data/app/views/admin/users/deactivated.html.erb +12 -0
- data/app/views/admin/users/edit.html.erb +54 -0
- data/app/views/admin/users/index.html.erb +27 -0
- data/app/views/admin/users/login.html.erb +15 -0
- data/app/views/admin/users/new.html.erb +23 -0
- data/app/views/admin/users/new_password.html.erb +19 -0
- data/app/views/admin/users/show.html.erb +64 -0
- data/app/views/admin_mailer/comment_notification.text.erb +7 -0
- data/app/views/admin_mailer/error_report.html.erb +70 -0
- data/app/views/admin_mailer/invite.text.erb +9 -0
- data/app/views/admin_mailer/password_reset.text.erb +13 -0
- data/app/views/errors/403.html.erb +6 -0
- data/app/views/errors/404.html.erb +11 -0
- data/app/views/errors/405.html.erb +4 -0
- data/app/views/errors/500.html.erb +19 -0
- data/app/views/errors/500_critical.html.erb +7 -0
- data/app/views/errors/_generic_help.html.erb +21 -0
- data/app/views/errors/report.html.erb +4 -0
- data/app/views/feeds/pages.rss.builder +39 -0
- data/app/views/layouts/admin/_analytics.html.erb +18 -0
- data/app/views/layouts/admin/_header.html.erb +37 -0
- data/app/views/layouts/admin.html.erb +79 -0
- data/app/views/layouts/errors.html.erb +23 -0
- data/app/views/sitemaps/show.xml.builder +9 -0
- data/config/locales/en.yml +6 -0
- data/config/removed_migrations.yml +60 -0
- data/config/routes.rb +127 -0
- data/db/migrate/20111219033112_create_pages_tables.rb +281 -0
- data/db/migrate/20120627033112_rename_textbits.rb +19 -0
- data/db/migrate/20121010055412_drop_removed_tables.rb +83 -0
- data/db/migrate/20130130053932_add_queue_to_delayed_jobs.rb +11 -0
- data/db/migrate/20130303053932_remove_filter_from_localizations.rb +11 -0
- data/db/migrate/20130303160632_remove_imagesets.rb +24 -0
- data/db/migrate/20130303161732_remove_sms_subscribers.rb +16 -0
- data/db/migrate/20130823133208_update_page_redirect_to.rb +25 -0
- data/db/migrate/20140203183900_create_roles.rb +63 -0
- data/db/migrate/20140414150500_change_locale_names.rb +13 -0
- data/db/migrate/20140515130100_remove_sphinx_deltas.rb +15 -0
- data/db/migrate/20140604142100_remove_openid_url.rb +9 -0
- data/db/migrate/20140920231700_convert_images_to_dis.rb +79 -0
- data/db/migrate/20140922124600_convert_page_files_to_dis.rb +50 -0
- data/db/migrate/20141004003100_create_password_reset_tokens.rb +10 -0
- data/db/migrate/20141006181300_remove_user_cruft.rb +11 -0
- data/db/migrate/20141007173000_create_invites.rb +16 -0
- data/db/migrate/20150204130800_update_delayed_job_table.rb +9 -0
- data/db/migrate/20150401131300_localize_images.rb +39 -0
- data/db/migrate/20150520174300_add_meta_image_to_page.rb +5 -0
- data/db/migrate/20150904164200_add_pinned_to_tags.rb +5 -0
- data/lib/pages_core/admin_menu_item.rb +22 -0
- data/lib/pages_core/archive_finder.rb +75 -0
- data/lib/pages_core/cache_sweeper.rb +112 -0
- data/lib/pages_core/configuration/base.rb +85 -0
- data/lib/pages_core/configuration/pages.rb +23 -0
- data/lib/pages_core/configuration.rb +9 -0
- data/lib/pages_core/engine.rb +27 -0
- data/lib/pages_core/extensions/hash_extensions.rb +23 -0
- data/lib/pages_core/extensions/string_extensions.rb +17 -0
- data/lib/pages_core/extensions.rb +4 -0
- data/lib/pages_core/localizable/active_record_extension.rb +41 -0
- data/lib/pages_core/localizable/class_methods.rb +51 -0
- data/lib/pages_core/localizable/configuration.rb +50 -0
- data/lib/pages_core/localizable/instance_methods.rb +130 -0
- data/lib/pages_core/localizable/localizer.rb +72 -0
- data/lib/pages_core/localizable/scope_extension.rb +22 -0
- data/lib/pages_core/localizable.rb +49 -0
- data/lib/pages_core/pages_plugin.rb +14 -0
- data/lib/pages_core/paginates.rb +102 -0
- data/lib/pages_core/plugin.rb +118 -0
- data/lib/pages_core/templates/block_configuration.rb +17 -0
- data/lib/pages_core/templates/configuration.rb +81 -0
- data/lib/pages_core/templates/configuration_handler.rb +62 -0
- data/lib/pages_core/templates/configuration_proxy.rb +28 -0
- data/lib/pages_core/templates/controller_actions.rb +32 -0
- data/lib/pages_core/templates/template_configuration.rb +198 -0
- data/lib/pages_core/templates.rb +53 -0
- data/lib/pages_core/version.rb +5 -0
- data/lib/pages_core.rb +89 -0
- data/lib/rails/generators/pages_core/frontend/frontend_generator.rb +68 -0
- data/lib/rails/generators/pages_core/frontend/templates/application.css.scss.erb +3 -0
- data/lib/rails/generators/pages_core/frontend/templates/application.js.erb +16 -0
- data/lib/rails/generators/pages_core/frontend/templates/base.css.scss.erb +3 -0
- data/lib/rails/generators/pages_core/frontend/templates/breakpoints.css.scss.erb +24 -0
- data/lib/rails/generators/pages_core/frontend/templates/hidpi.css.scss.erb +8 -0
- data/lib/rails/generators/pages_core/frontend/templates/layout.html.erb +15 -0
- data/lib/rails/generators/pages_core/frontend/templates/normalize.css.erb +425 -0
- data/lib/rails/generators/pages_core/install/install_generator.rb +135 -0
- data/lib/rails/generators/pages_core/install/templates/active_job_initializer.rb +1 -0
- data/lib/rails/generators/pages_core/install/templates/application_controller.rb +11 -0
- data/lib/rails/generators/pages_core/install/templates/application_helper.rb +5 -0
- data/lib/rails/generators/pages_core/install/templates/cache_sweeper_initializer.rb +11 -0
- data/lib/rails/generators/pages_core/install/templates/default_page_template.html.erb +5 -0
- data/lib/rails/generators/pages_core/install/templates/delayed_job +7 -0
- data/lib/rails/generators/pages_core/install/templates/delayed_job_initializer.rb +3 -0
- data/lib/rails/generators/pages_core/install/templates/frontend_controller.rb +6 -0
- data/lib/rails/generators/pages_core/install/templates/frontend_helper.rb +5 -0
- data/lib/rails/generators/pages_core/install/templates/gitignore.erb +25 -0
- data/lib/rails/generators/pages_core/install/templates/page_templates_initializer.rb +67 -0
- data/lib/rails/generators/pages_core/install/templates/pages_controller.rb +4 -0
- data/lib/rails/generators/pages_core/install/templates/pages_initializer.rb +45 -0
- data/lib/rails/generators/pages_core/install/templates/thinking_sphinx.yml +12 -0
- data/lib/rails/generators/pages_core/rspec/rspec_generator.rb +34 -0
- data/lib/rails/generators/pages_core/rspec/templates/factories.rb +9 -0
- data/lib/rails/generators/pages_core/rspec/templates/mailer_macros.rb +9 -0
- data/lib/rails/generators/pages_core/rspec/templates/spec_helper.rb +51 -0
- data/lib/tasks/db.rake +96 -0
- data/lib/tasks/pages/assets.rake +65 -0
- data/lib/tasks/pages/cache.rake +16 -0
- data/lib/tasks/pages/update.rake +19 -0
- data/lib/tasks/pages.rake +76 -0
- data/template.rb +19 -0
- data/vendor/assets/javascripts/jquery.dimscreen.js +77 -0
- data/vendor/assets/javascripts/jquery.fieldselection.js +59 -0
- metadata +690 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
# The Paginates module adds syntactic sugar to a collection for
|
5
|
+
# handling pagination. The module doesn't do any pagination on it's
|
6
|
+
# own, the logic should be handled by the finders.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
# @users = User.limit(20).offset(20)
|
10
|
+
# PagesCore::Paginates.paginate(
|
11
|
+
# @users,
|
12
|
+
# current_page: 2,
|
13
|
+
# pages: 5,
|
14
|
+
# per_page: 20
|
15
|
+
# )
|
16
|
+
#
|
17
|
+
# Now, in the view, you could do:
|
18
|
+
#
|
19
|
+
# <%= link_to_unless(
|
20
|
+
# @pages.first_page?, "Previous", {page: @users.previous_page}) %>
|
21
|
+
# <% @users.pages.each do |p| %>
|
22
|
+
# <%= link_to_unless p == @users.current_page, p, {page: p} %>
|
23
|
+
# <% end %>
|
24
|
+
# <%= link_to_unless @pages.last_page? "Next", {page: @users.next_page} %>
|
25
|
+
module Paginates
|
26
|
+
attr_accessor :paginated, :current_page, :pages, :per_page, :offset
|
27
|
+
|
28
|
+
class << self
|
29
|
+
# Applies pagination to any collection.
|
30
|
+
def paginate(collection, options = {})
|
31
|
+
options = default_options.merge(options)
|
32
|
+
class << collection
|
33
|
+
include PagesCore::Paginates
|
34
|
+
end
|
35
|
+
collection.current_page = options[:current_page]
|
36
|
+
collection.pages = options[:pages]
|
37
|
+
collection.per_page = options[:per_page]
|
38
|
+
collection.offset = options[:offset]
|
39
|
+
collection.paginated = options[:per_page] ? true : false
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_options
|
43
|
+
{
|
44
|
+
current_page: 1,
|
45
|
+
pages: 1,
|
46
|
+
per_page: nil,
|
47
|
+
offset: 0
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns true if collection is paginated
|
53
|
+
def paginated?
|
54
|
+
(@paginated) ? true : false
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns next page, or nil if at last page.
|
58
|
+
def next_page
|
59
|
+
(@current_page < @pages) ? (@current_page + 1) : nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns true/false depending on if there's a next page
|
63
|
+
def next_page?
|
64
|
+
(next_page) ? true : false
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns previous page, or nil if at first page.
|
68
|
+
def previous_page
|
69
|
+
(@current_page > 1) ? (@current_page - 1) : nil
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns true/false depending on if there's a previous page
|
73
|
+
def previous_page?
|
74
|
+
(previous_page) ? true : false
|
75
|
+
end
|
76
|
+
|
77
|
+
# Number of pages
|
78
|
+
def last_page
|
79
|
+
@pages.to_i
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns true if at the last page
|
83
|
+
def last_page?
|
84
|
+
(@page == @pages) ? true : false
|
85
|
+
end
|
86
|
+
|
87
|
+
# First page
|
88
|
+
def first_page
|
89
|
+
1
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns true if at the first page
|
93
|
+
def first_page?
|
94
|
+
(@page == 1) ? true : false
|
95
|
+
end
|
96
|
+
|
97
|
+
# All pages as an array
|
98
|
+
def pages
|
99
|
+
(first_page..last_page).to_a
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# module PagesGallery
|
4
|
+
# class Plugin < PagesCore::Plugin
|
5
|
+
# paths['db/migrate'] = 'template/db/migrate'
|
6
|
+
# end
|
7
|
+
# end
|
8
|
+
|
9
|
+
module PagesCore
|
10
|
+
class Plugin
|
11
|
+
class << self
|
12
|
+
attr_accessor :called_from, :paths
|
13
|
+
|
14
|
+
def inherited(plugin)
|
15
|
+
plugin.paths ||= {
|
16
|
+
"db/migrate" => "db/migrate",
|
17
|
+
"config/removed_migrations.yml" => "config/removed_migrations.yml"
|
18
|
+
}
|
19
|
+
plugin.called_from = begin
|
20
|
+
# Remove the line number from backtraces making sure we
|
21
|
+
# don't leave anything behind
|
22
|
+
call_stack = caller.map { |p| p.sub(/:\d+.*/, "") }
|
23
|
+
File.dirname(
|
24
|
+
call_stack.detect do |p|
|
25
|
+
p !~ %r{railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack}
|
26
|
+
end
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def admin_menu_item(label, path, group = :custom, options = {})
|
32
|
+
PagesCore::AdminMenuItem.register(label, path, group, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def plugins
|
36
|
+
@plugins ||= ::PagesCore::Plugin.subclasses.map do |class_name|
|
37
|
+
class_name.to_s.split("::").inject(Object) do |klass, m|
|
38
|
+
klass.const_get(m)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def migrations
|
44
|
+
plugins.map { |p| p.new.migrations }.flatten.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
def removed_migrations
|
48
|
+
plugins.map { |p| p.new.removed_migrations }.flatten.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
def existing_removed_migrations
|
52
|
+
removed_migrations
|
53
|
+
.select { |m| File.exist?(Rails.root.join("db", "migrate", m)) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def existing_migrations
|
57
|
+
migrations
|
58
|
+
.map { |m| Rails.root.join("db", "migrate", m.basename) }
|
59
|
+
.select { |m| File.exist?(m) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove_old_migrations!
|
63
|
+
(existing_removed_migrations + existing_migrations).each do |migration|
|
64
|
+
File.unlink Rails.root.join("db", "migrate", migration)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def root
|
70
|
+
@root ||= find_root_with_subfolder("app")
|
71
|
+
end
|
72
|
+
|
73
|
+
def paths
|
74
|
+
self.class.paths
|
75
|
+
end
|
76
|
+
|
77
|
+
def migrations_path
|
78
|
+
root.join(paths["db/migrate"])
|
79
|
+
end
|
80
|
+
|
81
|
+
def removed_migrations_path
|
82
|
+
root.join(paths["config/removed_migrations.yml"])
|
83
|
+
end
|
84
|
+
|
85
|
+
def migrations?
|
86
|
+
File.exist?(migrations_path) && File.directory?(migrations_path)
|
87
|
+
end
|
88
|
+
|
89
|
+
def migrations
|
90
|
+
Dir.entries(migrations_path)
|
91
|
+
.select { |f| f =~ /\.rb$/ }
|
92
|
+
.map { |f| migrations_path.join(f) }
|
93
|
+
end
|
94
|
+
|
95
|
+
def removed_migrations
|
96
|
+
return unless File.exist?(removed_migrations_path)
|
97
|
+
YAML.load_file(removed_migrations_path)
|
98
|
+
end
|
99
|
+
|
100
|
+
protected
|
101
|
+
|
102
|
+
def find_root_with_subfolder(subfolder)
|
103
|
+
root_path = self.class.called_from
|
104
|
+
|
105
|
+
while root_path && File.directory?(root_path) &&
|
106
|
+
!File.exist?("#{root_path}/#{subfolder}")
|
107
|
+
parent = File.dirname(root_path)
|
108
|
+
root_path = parent != root_path && parent
|
109
|
+
end
|
110
|
+
|
111
|
+
unless File.exist?("#{root_path}/#{subfolder}")
|
112
|
+
fail "Could not find root path for #{self}"
|
113
|
+
end
|
114
|
+
|
115
|
+
Pathname.new(root_path).realpath
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
module Templates
|
5
|
+
# Configuration for the blocks on an individual template
|
6
|
+
class BlockConfiguration
|
7
|
+
attr_reader :name, :title, :description, :optional, :enforced
|
8
|
+
def small?
|
9
|
+
(@size == :small) ? true : false
|
10
|
+
end
|
11
|
+
|
12
|
+
def large?
|
13
|
+
(small?) ? false : true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
module Templates
|
5
|
+
class Configuration < PagesCore::Templates::ConfigurationHandler
|
6
|
+
handle :default do |instance, name, *args|
|
7
|
+
if name == :blocks
|
8
|
+
blocks_proxy = instance.blocks
|
9
|
+
args.first.call(blocks_proxy) if args.first.is_a?(Proc)
|
10
|
+
blocks_proxy
|
11
|
+
else
|
12
|
+
instance.configure_template(:_defaults, name, *args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid_template_options
|
17
|
+
[
|
18
|
+
:template, :image, :images, :files, :text_filter, :blocks,
|
19
|
+
:enabled_blocks, :sub_template, :comments, :comments_allowed, :tags
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure_block(tpl_name, block_name, title = false, options = {})
|
24
|
+
block_name = block_name.to_sym
|
25
|
+
title ||= block_name.to_s.humanize
|
26
|
+
options[:title] = title
|
27
|
+
if tpl_name == :_defaults
|
28
|
+
set([:default, :blocks, block_name], options)
|
29
|
+
else
|
30
|
+
set([:templates, tpl_name, :blocks, block_name], options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def configure_template(template_name, setting, value, options = {})
|
35
|
+
template_name = template_name.to_sym
|
36
|
+
setting = setting.to_sym
|
37
|
+
if valid_template_options.include?(setting)
|
38
|
+
value = true if value == :enabled
|
39
|
+
value = false if value == :disabled
|
40
|
+
template_config = {
|
41
|
+
setting => {
|
42
|
+
value: value,
|
43
|
+
options: options
|
44
|
+
}
|
45
|
+
}
|
46
|
+
if template_name == :_defaults
|
47
|
+
set([:default], template_config)
|
48
|
+
else
|
49
|
+
set([:templates, template_name], template_config)
|
50
|
+
end
|
51
|
+
else
|
52
|
+
fail "Invalid template configuration value: #{setting.inspect}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def blocks(template_name = :_defaults, &block)
|
57
|
+
proxy(block) do |name, *args|
|
58
|
+
configure_block(template_name, name, *args)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def templates(*tpl_args, &block)
|
63
|
+
template_names = tpl_args.flatten.map(&:to_sym)
|
64
|
+
proxy(block) do |name, *args|
|
65
|
+
if name == :blocks
|
66
|
+
proxy(args.first.is_a?(Proc) ? args.first : nil) do |n2, *a2|
|
67
|
+
template_names.each do |template_name|
|
68
|
+
configure_block(template_name, n2, *a2)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
template_names.each do |template_name|
|
73
|
+
configure_template(template_name, name, *args)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
alias_method :template, :templates
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
module Templates
|
5
|
+
class ConfigurationHandler
|
6
|
+
class << self
|
7
|
+
def handle_blocks
|
8
|
+
@handle_blocks ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def handle(method_name, &handle_block)
|
12
|
+
@handle_blocks ||= {}
|
13
|
+
@handle_blocks[method_name] = handle_block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :configuration
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@configuration = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method_name, *args, &block)
|
24
|
+
if self.class.handle_blocks.keys.include?(method_name)
|
25
|
+
proxy = PagesCore::Templates::ConfigurationProxy.new(
|
26
|
+
self.class.handle_blocks[method_name],
|
27
|
+
self
|
28
|
+
)
|
29
|
+
block.call(proxy) if block
|
30
|
+
proxy
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def proxy(proxy_block = nil, &callback)
|
37
|
+
proxy_object = PagesCore::Templates::ConfigurationProxy.new(callback)
|
38
|
+
proxy_block.call(proxy_object) if proxy_block
|
39
|
+
proxy_object
|
40
|
+
end
|
41
|
+
|
42
|
+
def set(stack, value)
|
43
|
+
@configuration ||= {}
|
44
|
+
value = true if value == :enabled
|
45
|
+
value = false if value == :disabled
|
46
|
+
stack = [stack] unless stack.is_a?(Enumerable)
|
47
|
+
partial_hash = stack.reverse.inject(value) do |hash, key|
|
48
|
+
Hash[key => hash]
|
49
|
+
end
|
50
|
+
@configuration = @configuration.deep_merge(partial_hash)
|
51
|
+
value
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(*path)
|
55
|
+
@configuration ||= {}
|
56
|
+
path.inject(@configuration) do |value, key|
|
57
|
+
(value && value.is_a?(Hash) && value.key?(key)) ? value[key] : nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
module Templates
|
5
|
+
class ConfigurationProxy
|
6
|
+
def initialize(callback, parent = nil)
|
7
|
+
@callback = callback
|
8
|
+
@parent = parent
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method_name, *args, &block)
|
12
|
+
if @parent
|
13
|
+
if block_given?
|
14
|
+
@callback.call(@parent, method_name, block)
|
15
|
+
else
|
16
|
+
@callback.call(@parent, method_name, *args)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
if block_given?
|
20
|
+
@callback.call(method_name, block)
|
21
|
+
else
|
22
|
+
@callback.call(method_name, *args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
module Templates
|
5
|
+
module ControllerActions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def template_actions
|
10
|
+
@template_actions ||= Hash.new { |hash, key| hash[key] = [] }
|
11
|
+
end
|
12
|
+
|
13
|
+
def template(*names, &block)
|
14
|
+
Array(names).each do |name|
|
15
|
+
name = name.to_s unless name == :all
|
16
|
+
template_actions[name] << block
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def template_actions_for(name)
|
21
|
+
template_actions[:all] + template_actions[name.to_s]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_template_actions_for(template, *args)
|
26
|
+
self.class.template_actions_for(template).each do |proc|
|
27
|
+
instance_exec(*args, &proc)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PagesCore
|
4
|
+
module Templates
|
5
|
+
class TemplateConfiguration
|
6
|
+
attr_reader :template_name
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def all_blocks
|
10
|
+
new(:index).all_blocks
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(template_name)
|
15
|
+
@template_name = template_name.to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
PagesCore::Templates.configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
def value(*path)
|
23
|
+
path = [path, :value].flatten
|
24
|
+
value = config.get(*[:default, path].flatten)
|
25
|
+
template_value = config.get(*[:templates, @template_name, path].flatten)
|
26
|
+
value = template_value unless template_value.nil?
|
27
|
+
value
|
28
|
+
end
|
29
|
+
|
30
|
+
def options(*path)
|
31
|
+
path = [path, :options].flatten
|
32
|
+
(config.get(*[:default, path].flatten) || {})
|
33
|
+
.deep_merge(
|
34
|
+
config.get(*[:templates, @template_name, path].flatten) || {}
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def block(block_name)
|
39
|
+
default_block_options(block_name)
|
40
|
+
.deep_merge(config.get(*[:default, :blocks, block_name]) || {})
|
41
|
+
.deep_merge(
|
42
|
+
config.get(*[:templates, @template_name, :blocks, block_name]) || {}
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def enabled_blocks
|
47
|
+
blocks = value(:enabled_blocks)
|
48
|
+
blocks = [:name] + blocks unless blocks.include?(:name)
|
49
|
+
if block_given?
|
50
|
+
blocks.each { |block_name| yield block_name, block(block_name) }
|
51
|
+
end
|
52
|
+
blocks
|
53
|
+
end
|
54
|
+
|
55
|
+
def metadata_blocks
|
56
|
+
blocks = PagesCore::Templates.metadata_block_names
|
57
|
+
if block_given?
|
58
|
+
blocks.each { |block_name| yield block_name, block(block_name) }
|
59
|
+
end
|
60
|
+
blocks
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns a list of all configured blocks
|
64
|
+
def all_blocks
|
65
|
+
(
|
66
|
+
all_templates.map { |t| configured_block_names(t) } +
|
67
|
+
all_templates.map { |t| enabled_block_names(t) }
|
68
|
+
).flatten.compact.uniq
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def configured_block_names(template)
|
74
|
+
Array(config.get(:default, :blocks).try(&:keys)) +
|
75
|
+
Array(config.get(:templates, template, :blocks).try(&:keys))
|
76
|
+
end
|
77
|
+
|
78
|
+
def enabled_block_names(template)
|
79
|
+
Array(config.get(:default, :enabled_blocks, :value)) +
|
80
|
+
Array(config.get(:templates, template, :enabled_blocks, :value))
|
81
|
+
end
|
82
|
+
|
83
|
+
def default_block_options(block_name)
|
84
|
+
{
|
85
|
+
title: block_name.to_s.humanize,
|
86
|
+
optional: true,
|
87
|
+
size: :small
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def all_templates
|
92
|
+
Array(config.get(:templates).try(&:keys))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class << self
|
97
|
+
def configure(options = {}, &_block)
|
98
|
+
if options[:reset] == :defaults
|
99
|
+
load_default_configuration
|
100
|
+
elsif options[:reset] == true
|
101
|
+
@configuration = PagesCore::Templates::Configuration.new
|
102
|
+
end
|
103
|
+
yield configuration if block_given?
|
104
|
+
end
|
105
|
+
|
106
|
+
def load_default_configuration
|
107
|
+
@configuration = PagesCore::Templates::Configuration.new
|
108
|
+
|
109
|
+
# Default template options
|
110
|
+
config.default do |default|
|
111
|
+
default.template :autodetect, root: "index"
|
112
|
+
default.image :enabled, linkable: false
|
113
|
+
default.comments :disabled
|
114
|
+
default.comments_allowed :enabled
|
115
|
+
default.files :disabled
|
116
|
+
default.images :disabled
|
117
|
+
default.text_filter :textile
|
118
|
+
default.enabled_blocks [:headline, :excerpt, :body]
|
119
|
+
default.tags :disabled
|
120
|
+
default_block_configuration(default)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def configuration
|
125
|
+
load_default_configuration unless defined? @configuration
|
126
|
+
@configuration
|
127
|
+
end
|
128
|
+
alias_method :config, :configuration
|
129
|
+
|
130
|
+
def metadata_block_names
|
131
|
+
[
|
132
|
+
:meta_title,
|
133
|
+
:meta_description,
|
134
|
+
:open_graph_title,
|
135
|
+
:open_graph_description
|
136
|
+
]
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def default_block_configuration(default)
|
142
|
+
default.blocks do |block|
|
143
|
+
block.name(
|
144
|
+
"Name",
|
145
|
+
size: :field,
|
146
|
+
description: "This is the name of the page, and it will also " \
|
147
|
+
"be the name of the link to this page.",
|
148
|
+
class: "page_title"
|
149
|
+
)
|
150
|
+
block.body(
|
151
|
+
"Body",
|
152
|
+
size: :large
|
153
|
+
)
|
154
|
+
block.headline(
|
155
|
+
"Headline",
|
156
|
+
description: "Optional, use if the headline should differ from " \
|
157
|
+
"the page name.",
|
158
|
+
size: :field
|
159
|
+
)
|
160
|
+
block.excerpt(
|
161
|
+
"Standfirst",
|
162
|
+
description: "An introductory paragraph before the start " \
|
163
|
+
"of the body."
|
164
|
+
)
|
165
|
+
block.boxout(
|
166
|
+
"Boxout",
|
167
|
+
description: "Part of the page, usually background info or " \
|
168
|
+
"facts related to the article."
|
169
|
+
)
|
170
|
+
block.meta_title(
|
171
|
+
"Title",
|
172
|
+
size: :field,
|
173
|
+
description: "Document title. Will fall back to the page name " \
|
174
|
+
"if empty. Recommended length: Up to 56 characters."
|
175
|
+
)
|
176
|
+
block.meta_description(
|
177
|
+
"Description",
|
178
|
+
size: :small,
|
179
|
+
description: "Description for search engines. Will fall back to " \
|
180
|
+
"Standfirst if empty. Recommended length: Up to 156 characters."
|
181
|
+
)
|
182
|
+
block.open_graph_title(
|
183
|
+
"Open Graph Title",
|
184
|
+
size: :field,
|
185
|
+
description: "Page title for Facebook sharing. Will fall back to " \
|
186
|
+
"the document title."
|
187
|
+
)
|
188
|
+
block.open_graph_description(
|
189
|
+
"Open Graph Description",
|
190
|
+
size: :small,
|
191
|
+
description: "Description for Facebook sharing. Will fall back " \
|
192
|
+
"to Description or Standfirst if empty."
|
193
|
+
)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
load "pages_core/templates/block_configuration.rb"
|
4
|
+
load "pages_core/templates/configuration_proxy.rb"
|
5
|
+
load "pages_core/templates/configuration_handler.rb"
|
6
|
+
load "pages_core/templates/configuration.rb"
|
7
|
+
load "pages_core/templates/controller_actions.rb"
|
8
|
+
load "pages_core/templates/template_configuration.rb"
|
9
|
+
|
10
|
+
module PagesCore
|
11
|
+
module Templates
|
12
|
+
class << self
|
13
|
+
def names
|
14
|
+
@names ||= find_all_templates
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def template_paths
|
20
|
+
[
|
21
|
+
PagesCore.plugin_root.join("app", "views", "pages", "templates"),
|
22
|
+
Rails.root.join("app", "views", "pages", "templates")
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
def template_files
|
27
|
+
template_paths
|
28
|
+
.select { |dir| File.exist?(dir) }
|
29
|
+
.flat_map { |dir| template_files_in_dir(dir) }
|
30
|
+
.uniq
|
31
|
+
.compact
|
32
|
+
.sort
|
33
|
+
.map { |f| f.gsub(/\.[\w\.]+$/, "") }
|
34
|
+
end
|
35
|
+
|
36
|
+
def template_files_in_dir(dir)
|
37
|
+
Dir.entries(dir).select { |f| template_file?(f, dir) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def template_file?(file, dir)
|
41
|
+
File.file?(File.join(dir, file)) && !file.match(/^_/)
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_all_templates
|
45
|
+
if template_files.include?("index")
|
46
|
+
["index"] + (template_files - ["index"])
|
47
|
+
else
|
48
|
+
template_files
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|