landable 1.13.1 → 1.13.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +281 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -4
- data/README.md +2 -0
- data/Rakefile +6 -3
- data/app/controllers/concerns/landable/variables_concern.rb +9 -9
- data/app/controllers/landable/api/access_tokens_controller.rb +7 -8
- data/app/controllers/landable/api/assets_controller.rb +29 -26
- data/app/controllers/landable/api/audits_controller.rb +6 -5
- data/app/controllers/landable/api/configurations_controller.rb +1 -1
- data/app/controllers/landable/api/directories_controller.rb +2 -2
- data/app/controllers/landable/api/page_revisions_controller.rb +2 -4
- data/app/controllers/landable/api/pages_controller.rb +39 -40
- data/app/controllers/landable/api/template_revisions_controller.rb +1 -2
- data/app/controllers/landable/api/templates_controller.rb +15 -14
- data/app/controllers/landable/api/themes_controller.rb +15 -14
- data/app/controllers/landable/api_controller.rb +10 -11
- data/app/controllers/landable/public/pages_controller.rb +2 -2
- data/app/controllers/landable/public/preview/page_revisions_controller.rb +2 -2
- data/app/controllers/landable/public/preview/pages_controller.rb +1 -1
- data/app/controllers/landable/public/sitemap_controller.rb +2 -2
- data/app/decorators/landable/page_decorator.rb +3 -3
- data/app/helpers/landable/pages_helper.rb +2 -2
- data/app/helpers/landable/traffic_helper.rb +2 -4
- data/app/models/concerns/landable/has_assets.rb +6 -9
- data/app/models/concerns/landable/has_templates.rb +6 -7
- data/app/models/concerns/landable/librarian.rb +5 -5
- data/app/models/concerns/landable/table_name.rb +2 -2
- data/app/models/landable/access_token.rb +1 -1
- data/app/models/landable/asset.rb +8 -8
- data/app/models/landable/asset_search_engine.rb +7 -8
- data/app/models/landable/author.rb +2 -1
- data/app/models/landable/category.rb +1 -3
- data/app/models/landable/directory.rb +2 -2
- data/app/models/landable/page.rb +44 -50
- data/app/models/landable/page_revision.rb +27 -41
- data/app/models/landable/page_search_engine.rb +5 -6
- data/app/models/landable/search_engine.rb +2 -2
- data/app/models/landable/template.rb +9 -11
- data/app/models/landable/template_revision.rb +4 -14
- data/app/models/landable/theme.rb +1 -1
- data/app/models/landable/traffic/attribution.rb +3 -1
- data/app/models/landable/traffic/page_view.rb +1 -1
- data/app/models/landable/traffic/user_agent.rb +1 -1
- data/app/models/landable/traffic/visit.rb +1 -1
- data/app/responders/landable/api_responder.rb +5 -3
- data/app/responders/landable/page_render_responder.rb +1 -1
- data/app/serializers/landable/asset_serializer.rb +1 -1
- data/app/serializers/landable/audit_serializer.rb +2 -3
- data/app/serializers/landable/directory_serializer.rb +2 -2
- data/app/serializers/landable/page_revision_serializer.rb +0 -1
- data/app/serializers/landable/page_serializer.rb +5 -5
- data/app/serializers/landable/template_serializer.rb +2 -2
- data/app/services/landable/authentication_service.rb +1 -1
- data/app/services/landable/registration_service.rb +3 -2
- data/app/services/landable/render_service.rb +16 -18
- data/app/services/landable/screenshot_service.rb +3 -4
- data/app/services/landable/tidy_service.rb +32 -37
- data/app/validators/path_validator.rb +1 -3
- data/app/validators/url_validator.rb +4 -7
- data/config/routes.rb +3 -6
- data/db/migrate/20130510221424_create_landable_schema.rb +45 -56
- data/db/migrate/20130909182713_landable_pages__add_updated_by.rb +2 -2
- data/db/migrate/20130909182715_landable_page_revisions__break_out_snapshot.rb +9 -12
- data/db/migrate/20131002220041_file_based_themes.rb +3 -3
- data/db/migrate/20131008164204_create_head_tag_on_page.rb +4 -4
- data/db/migrate/20131008193544_drop_status_codes_model.rb +1 -2
- data/db/migrate/20131028145652_add_traffic_schema.rb +5 -5
- data/db/migrate/20131101213623_add_dnt_column_to_visits.rb +1 -1
- data/db/migrate/20131106185946_add_index_on_page_revisions_path.rb +1 -1
- data/db/migrate/20131106193021_page_revisisons__path_status_code_index.rb +1 -1
- data/db/migrate/20131121150902_add_attribution_id_to_unique_index.rb +2 -2
- data/db/migrate/20131216214027_drop_browser_screenshot_tables.rb +3 -3
- data/db/migrate/20140128170659_file_backed_templates.rb +1 -1
- data/db/migrate/20140205193757_fix_status_codes.rb +3 -3
- data/db/migrate/20140220170324_add_slug_to_categories.rb +1 -1
- data/db/migrate/20140224205516_rename_traffic_schema.rb +7 -9
- data/db/migrate/20140509190128_create_template_revisions.rb +13 -15
- data/db/migrate/20140509192856_create_audits.rb +3 -3
- data/db/migrate/20140602213937_path_response_time_view.rb +20 -19
- data/features/step_definitions/asset_steps.rb +10 -12
- data/features/step_definitions/core_api_steps.rb +29 -27
- data/features/step_definitions/factory_steps.rb +16 -16
- data/features/step_definitions/html_steps.rb +1 -1
- data/features/step_definitions/liquid_steps.rb +8 -8
- data/features/step_definitions/theme_steps.rb +4 -4
- data/features/support/env.rb +5 -5
- data/landable.gemspec +2 -2
- data/lib/generators/landable/landable_generator.rb +2 -2
- data/lib/generators/templates/landable.rb +1 -1
- data/lib/landable.rb +7 -7
- data/lib/landable/configuration.rb +10 -19
- data/lib/landable/engine.rb +19 -19
- data/lib/landable/error.rb +1 -3
- data/lib/landable/layout.rb +6 -6
- data/lib/landable/liquid/asset_tags.rb +3 -5
- data/lib/landable/liquid/drops.rb +3 -8
- data/lib/landable/liquid/filters.rb +1 -3
- data/lib/landable/liquid/tags.rb +10 -10
- data/lib/landable/migration.rb +30 -30
- data/lib/landable/mime_types.rb +1 -1
- data/lib/landable/partial.rb +2 -2
- data/lib/landable/seeds.rb +3 -4
- data/lib/landable/traffic.rb +4 -8
- data/lib/landable/traffic/tracker.rb +48 -43
- data/lib/landable/traffic/user_tracker.rb +15 -10
- data/lib/landable/version.rb +1 -1
- data/lib/schema_moves.rb +15 -16
- data/lib/tasks/landable/cucumber.rake +46 -47
- data/lib/tasks/landable/data.rake +13 -14
- data/lib/tasks/landable/pgtap.rake +12 -18
- data/lib/tasks/landable/seed.rake +4 -4
- data/spec/concerns/landable/has_assets_spec.rb +15 -19
- data/spec/concerns/landable/has_templates_spec.rb +10 -13
- data/spec/concerns/landable/librarian.rb +4 -4
- data/spec/concerns/landable/table_name_spec.rb +3 -5
- data/spec/concerns/landable/traffic/table_name_spec.rb +2 -4
- data/spec/controllers/concerns/landable/variables_concern_spec.rb +11 -10
- data/spec/controllers/landable/api/assets_controller_spec.rb +15 -14
- data/spec/controllers/landable/api/audits_controller_spec.rb +104 -102
- data/spec/controllers/landable/api/categories_controller_spec.rb +36 -34
- data/spec/controllers/landable/api/configuration_controller_spec.rb +14 -12
- data/spec/controllers/landable/api/directories_controller_spec.rb +52 -50
- data/spec/controllers/landable/api/page_revisions_controller_spec.rb +20 -18
- data/spec/controllers/landable/api/pages_controller_spec.rb +204 -203
- data/spec/controllers/landable/api/template_revisions_controller_spec.rb +20 -18
- data/spec/controllers/landable/api/templates_controller_spec.rb +39 -37
- data/spec/controllers/landable/api_controller_spec.rb +24 -26
- data/spec/controllers/public/preview/page_revisions_controller_spec.rb +36 -34
- data/spec/controllers/public/preview/pages_controller_spec.rb +32 -30
- data/spec/controllers/public/sitemap_controller_spec.rb +19 -17
- data/spec/decorators/page_decorator_spec.rb +9 -9
- data/spec/dummy/app/helpers/application_helper.rb +1 -1
- data/spec/dummy/config/application.rb +5 -6
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/landable.rb +7 -6
- data/spec/factories/asset.rb +1 -1
- data/spec/factories/audit.rb +1 -1
- data/spec/factories/authors.rb +1 -1
- data/spec/factories/category.rb +1 -1
- data/spec/factories/pages.rb +4 -4
- data/spec/factories/template.rb +3 -3
- data/spec/factories/theme.rb +2 -2
- data/spec/helpers/pages_helper_spec.rb +5 -5
- data/spec/lib/landable/configuration_spec.rb +2 -4
- data/spec/lib/landable/event_publisher_spec.rb +1 -3
- data/spec/lib/landable/layout_spec.rb +4 -4
- data/spec/lib/landable/liquid_spec.rb +12 -14
- data/spec/lib/landable/migration_spec.rb +4 -4
- data/spec/lib/landable/partial_spec.rb +18 -18
- data/spec/lib/landable/tracking_spec.rb +27 -29
- data/spec/lib/landable/traffic_spec.rb +29 -33
- data/spec/models/landable/access_token_spec.rb +1 -1
- data/spec/models/landable/asset_spec.rb +9 -11
- data/spec/models/landable/directory_spec.rb +7 -7
- data/spec/models/landable/page/errors_spec.rb +1 -3
- data/spec/models/landable/page_revision_spec.rb +23 -24
- data/spec/models/landable/page_spec.rb +41 -42
- data/spec/models/landable/template_revision_spec.rb +3 -3
- data/spec/models/landable/template_spec.rb +11 -11
- data/spec/models/landable/theme_spec.rb +2 -2
- data/spec/models/landable/traffic/referer_spec.rb +3 -3
- data/spec/responders/page_render_responder_spec.rb +0 -2
- data/spec/routing/public_page_route_spec.rb +4 -5
- data/spec/services/landable/authentication_service_spec.rb +7 -7
- data/spec/services/landable/render_service_spec.rb +8 -8
- data/spec/services/landable/screenshot_service_spec.rb +3 -3
- data/spec/services/landable/tidy_service_spec.rb +20 -20
- data/spec/spec_helper.rb +3 -3
- data/spec/support/behaviors.rb +4 -4
- data/spec/support/helpers.rb +1 -1
- metadata +86 -35
- checksums.yaml +0 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'landable/application_controller'
|
2
2
|
|
3
3
|
module Landable
|
4
4
|
module Public
|
@@ -8,7 +8,7 @@ module Landable
|
|
8
8
|
host: Landable.configuration.sitemap_host || request.host,
|
9
9
|
protocol: Landable.configuration.sitemap_protocol,
|
10
10
|
exclude_categories: Landable.configuration.sitemap_exclude_categories,
|
11
|
-
sitemap_additional_paths: Landable.configuration.sitemap_additional_paths
|
11
|
+
sitemap_additional_paths: Landable.configuration.sitemap_additional_paths
|
12
12
|
)
|
13
13
|
|
14
14
|
render xml: sitemap
|
@@ -3,7 +3,7 @@ module Landable
|
|
3
3
|
include ActionView::Helpers::TagHelper
|
4
4
|
|
5
5
|
def initialize(page)
|
6
|
-
|
6
|
+
fail(TypeError, 'Use Landable::NullPageDecorator') if page.nil?
|
7
7
|
@page = page
|
8
8
|
end
|
9
9
|
|
@@ -30,9 +30,9 @@ module Landable
|
|
30
30
|
def meta_tags
|
31
31
|
return nil unless page.meta_tags?
|
32
32
|
|
33
|
-
page.meta_tags.map
|
33
|
+
page.meta_tags.map do |name, value|
|
34
34
|
tag('meta', name: name, content: value) if value.present?
|
35
|
-
|
35
|
+
end.compact.join("\n").html_safe
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
@@ -6,9 +6,9 @@ module Landable
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def current_page
|
9
|
-
if params[:controller] ==
|
9
|
+
if params[:controller] == 'landable/public/preview/page_revisions'
|
10
10
|
current_page = PageRevision.find(params[:id])
|
11
|
-
elsif params[:controller] ==
|
11
|
+
elsif params[:controller] == 'landable/public/preview/pages'
|
12
12
|
current_page = Page.find(params[:id])
|
13
13
|
else
|
14
14
|
current_page = Page.by_path(request.path)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Landable
|
2
2
|
module TrafficHelper
|
3
|
+
attr_reader :tracker
|
4
|
+
|
3
5
|
def crawl_tracker
|
4
6
|
@tracker if @tracker.is_a? Landable::Traffic::CrawlTracker
|
5
7
|
end
|
@@ -23,9 +25,5 @@ module Landable
|
|
23
25
|
def user_tracker
|
24
26
|
@tracker if @tracker.is_a? Landable::Traffic::UserTracker
|
25
27
|
end
|
26
|
-
|
27
|
-
def tracker
|
28
|
-
@tracker
|
29
|
-
end
|
30
28
|
end
|
31
29
|
end
|
@@ -36,39 +36,36 @@ module Landable
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# passthrough for body=; clears the asset_names cache in the process
|
39
|
-
def body=
|
39
|
+
def body=(body_val)
|
40
40
|
@asset_names = nil
|
41
41
|
self[:body] = body_val
|
42
42
|
end
|
43
43
|
|
44
44
|
# this looks weird; I swear it works
|
45
45
|
def save_assets!
|
46
|
-
self.assets =
|
46
|
+
self.assets = assets
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
49
|
private
|
51
50
|
|
52
|
-
def asset_names_for_node
|
51
|
+
def asset_names_for_node(node, names = [])
|
53
52
|
# set up a recursing function to search for asset tags
|
54
53
|
if node.is_a? Landable::Liquid::AssetTag
|
55
54
|
names << node.asset_name unless names.include? node.asset_name
|
56
55
|
end
|
57
56
|
|
58
|
-
if node.respond_to?
|
59
|
-
node.nodelist.each { |
|
57
|
+
if node.respond_to?(:nodelist) && node.nodelist
|
58
|
+
node.nodelist.each { |n| asset_names_for_node n, names }
|
60
59
|
end
|
61
60
|
|
62
61
|
names
|
63
62
|
end
|
64
|
-
|
65
63
|
end
|
66
64
|
|
67
65
|
module ClassMethods
|
68
66
|
def assets_join_table_name
|
69
|
-
"#{Landable.configuration.database_schema_prefix}landable.#{
|
67
|
+
"#{Landable.configuration.database_schema_prefix}landable.#{name.underscore.split('/').last}_assets"
|
70
68
|
end
|
71
69
|
end
|
72
|
-
|
73
70
|
end
|
74
71
|
end
|
@@ -23,7 +23,7 @@ module Landable
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# passthrough for body=; clears the template_names cache in the process
|
26
|
-
def body=
|
26
|
+
def body=(body_val)
|
27
27
|
@template_slug = nil
|
28
28
|
@asset_names = nil
|
29
29
|
self[:body] = body_val
|
@@ -31,29 +31,28 @@ module Landable
|
|
31
31
|
|
32
32
|
# this looks weird; I swear it works
|
33
33
|
def save_templates!
|
34
|
-
self.templates =
|
34
|
+
self.templates = templates
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def template_names_for_node
|
39
|
+
def template_names_for_node(node, names = [])
|
40
40
|
# set up a recursing function to search for template tags
|
41
41
|
if node.is_a? Landable::Liquid::TemplateTag
|
42
42
|
names << node.template_slug unless names.include? node.template_slug
|
43
43
|
end
|
44
44
|
|
45
|
-
if node.respond_to?
|
46
|
-
node.nodelist.each { |
|
45
|
+
if node.respond_to?(:nodelist) && node.nodelist
|
46
|
+
node.nodelist.each { |n| template_names_for_node n, names }
|
47
47
|
end
|
48
48
|
|
49
49
|
names
|
50
50
|
end
|
51
|
-
|
52
51
|
end
|
53
52
|
|
54
53
|
module ClassMethods
|
55
54
|
def templates_join_table_name
|
56
|
-
"#{Landable.configuration.database_schema_prefix}landable.#{
|
55
|
+
"#{Landable.configuration.database_schema_prefix}landable.#{name.underscore.split('/').last}_templates"
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -13,21 +13,21 @@ module Landable
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# validations
|
16
|
-
|
16
|
+
|
17
17
|
# standard methods
|
18
18
|
def deactivate
|
19
|
-
|
19
|
+
update_attribute(:deleted_at, Time.now)
|
20
20
|
end
|
21
21
|
|
22
22
|
# custom methods
|
23
23
|
def nuke!
|
24
|
-
|
24
|
+
destroy
|
25
25
|
end
|
26
26
|
|
27
27
|
def reactivate
|
28
|
-
|
28
|
+
update_attribute(:deleted_at, nil)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# end
|
32
32
|
end
|
33
33
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Landable
|
2
2
|
module TableName
|
3
|
-
extend ActiveSupport::Concern
|
3
|
+
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
6
|
schema = "#{Landable.configuration.database_schema_prefix}landable"
|
7
7
|
suffix = parent.name.demodulize.downcase
|
8
8
|
|
9
|
-
schema += "_#{suffix}" unless suffix ==
|
9
|
+
schema += "_#{suffix}" unless suffix == 'landable'
|
10
10
|
model_name = self.model_name.element.pluralize
|
11
11
|
self.table_name = "#{schema}.#{model_name}"
|
12
12
|
end
|
@@ -7,10 +7,10 @@ module Landable
|
|
7
7
|
class Asset < ActiveRecord::Base
|
8
8
|
include Landable::TableName
|
9
9
|
include Landable::Librarian
|
10
|
-
|
10
|
+
|
11
11
|
mount_uploader :data, Landable::AssetUploader
|
12
|
-
|
13
|
-
|
12
|
+
alias_method :file, :data
|
13
|
+
alias_method :file=, :data=
|
14
14
|
|
15
15
|
# This bit of indirection allows us to generate predictable
|
16
16
|
# URLs in the test environment.
|
@@ -25,11 +25,11 @@ module Landable
|
|
25
25
|
|
26
26
|
before_validation :write_metadata, on: :create
|
27
27
|
|
28
|
-
validates_presence_of
|
29
|
-
validates_presence_of
|
30
|
-
validates_uniqueness_of
|
28
|
+
validates_presence_of :data, :author
|
29
|
+
validates_presence_of :name, :mime_type, :md5sum, :file_size
|
30
|
+
validates_uniqueness_of :md5sum
|
31
31
|
validates_numericality_of :file_size, only_integer: true
|
32
|
-
validates_format_of
|
32
|
+
validates_format_of :name, with: /^[\w\._-]+$/, on: :create, multiline: true, message: 'can only contain alphanumeric characters, periods, underscores, and dashes'
|
33
33
|
|
34
34
|
def public_url
|
35
35
|
self.class.url_generator.call(self)
|
@@ -42,7 +42,7 @@ module Landable
|
|
42
42
|
|
43
43
|
def associated_pages
|
44
44
|
paths = []
|
45
|
-
Page.where(
|
45
|
+
Page.where('body like ?', "%#{name}%").each do |page|
|
46
46
|
paths.push(page.path)
|
47
47
|
end
|
48
48
|
paths
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require_dependency
|
2
|
-
require_dependency
|
1
|
+
require_dependency 'landable/search_engine'
|
2
|
+
require_dependency 'landable/asset'
|
3
3
|
|
4
4
|
module Landable
|
5
5
|
class AssetSearchEngine < SearchEngine
|
@@ -8,13 +8,12 @@ module Landable
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def filter_by!(filters)
|
11
|
-
|
12
|
-
|
13
|
-
end
|
11
|
+
ids = as_array(filters[:ids])
|
12
|
+
@scope = @scope.where(asset_id: ids) if ids
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
name = filters[:name].presence
|
15
|
+
return unless name
|
16
|
+
@scope = @scope.where('LOWER(name) LIKE ?', "%#{name}%".downcase)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -4,7 +4,8 @@ module Landable
|
|
4
4
|
has_many :access_tokens
|
5
5
|
|
6
6
|
def self.authenticate!(username, token_id)
|
7
|
-
|
7
|
+
author = where(username: username).first
|
8
|
+
return unless author
|
8
9
|
return unless author.access_tokens.fresh.exists?(token_id)
|
9
10
|
author
|
10
11
|
end
|
@@ -12,16 +12,14 @@ module Landable
|
|
12
12
|
def to_liquid
|
13
13
|
{
|
14
14
|
'name' => name,
|
15
|
-
'pages' => pages.published
|
15
|
+
'pages' => pages.published
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
protected
|
21
20
|
|
22
21
|
def set_slug
|
23
22
|
self.slug = name.downcase.gsub(/[^\w]/, '_').gsub(/_{2,}/, '_')
|
24
23
|
end
|
25
|
-
|
26
24
|
end
|
27
25
|
end
|
@@ -3,11 +3,11 @@ module Landable
|
|
3
3
|
include ActiveModel::SerializerSupport
|
4
4
|
|
5
5
|
def self.listing(parent)
|
6
|
-
parent_with_slash = parent.gsub(
|
6
|
+
parent_with_slash = parent.gsub(%r{^(.*?)\/?$}, '\1/')
|
7
7
|
pages = Page.where('path LIKE ?', "#{parent_with_slash}%").to_a
|
8
8
|
subdirs = pages.group_by { |page| page.directory_after(parent_with_slash) }
|
9
9
|
notdirs = subdirs.delete(nil) || []
|
10
|
-
subdirs = subdirs.map { |name,
|
10
|
+
subdirs = subdirs.map { |name, _contents| Directory.new("#{parent}/#{name}") }
|
11
11
|
Directory.new(parent, subdirs.sort_by(&:path), notdirs.sort_by(&:path))
|
12
12
|
end
|
13
13
|
|
data/app/models/landable/page.rb
CHANGED
@@ -13,10 +13,10 @@ module Landable
|
|
13
13
|
include Landable::TableName
|
14
14
|
include Landable::Librarian
|
15
15
|
|
16
|
-
validates_presence_of
|
17
|
-
validates_presence_of
|
16
|
+
validates_presence_of :path, :status_code
|
17
|
+
validates_presence_of :redirect_url, if: -> page { page.redirect? }
|
18
18
|
|
19
|
-
validates_inclusion_of
|
19
|
+
validates_inclusion_of :status_code, in: [200, 301, 302, 410]
|
20
20
|
|
21
21
|
validates_with PathValidator, fields: [:path]
|
22
22
|
validates_uniqueness_of :path
|
@@ -35,21 +35,23 @@ module Landable
|
|
35
35
|
belongs_to :category, class_name: 'Landable::Category'
|
36
36
|
belongs_to :updated_by_author, class_name: 'Landable::Author'
|
37
37
|
belongs_to :hero_asset, class_name: 'Landable::Asset'
|
38
|
-
has_many
|
39
|
-
has_many
|
40
|
-
has_many
|
38
|
+
has_many :revisions, class_name: 'Landable::PageRevision'
|
39
|
+
has_many :screenshots, class_name: 'Landable::Screenshot', as: :screenshotable
|
40
|
+
has_many :audits, class_name: 'Landable::Audit', as: :auditable
|
41
41
|
|
42
42
|
delegate :republish!, to: :published_revision
|
43
43
|
|
44
|
-
scope :imported, -> { where(
|
45
|
-
scope :sitemappable,
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
scope :imported, -> { where('imported_at IS NOT NULL') }
|
45
|
+
scope :sitemappable, lambda {
|
46
|
+
where("COALESCE(meta_tags -> 'robots' NOT LIKE '%noindex%', TRUE)")
|
47
|
+
.where('published_revision_id is NOT NULL')
|
48
|
+
.where(status_code: 200)
|
49
|
+
}
|
50
|
+
scope :published, -> { where('published_revision_id is NOT NULL') }
|
49
51
|
|
50
52
|
before_validation :downcase_path!
|
51
53
|
|
52
|
-
before_save
|
54
|
+
before_save lambda { |page|
|
53
55
|
page.lock_version ||= 0
|
54
56
|
page.is_publishable = true unless page.published_revision_id_changed?
|
55
57
|
}
|
@@ -68,9 +70,9 @@ module Landable
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def with_fuzzy_path(path)
|
71
|
-
select("*, similarity(path, #{Page.sanitize path}) _sml")
|
72
|
-
where('path LIKE ?', "%#{path}%")
|
73
|
-
order('_sml DESC, path ASC')
|
73
|
+
select("*, similarity(path, #{Page.sanitize path}) _sml")
|
74
|
+
.where('path LIKE ?', "%#{path}%")
|
75
|
+
.order('_sml DESC, path ASC')
|
74
76
|
end
|
75
77
|
|
76
78
|
def example(attrs)
|
@@ -82,15 +84,14 @@ module Landable
|
|
82
84
|
new defaults.merge(attrs)
|
83
85
|
end
|
84
86
|
|
85
|
-
|
86
87
|
def generate_sitemap(options = {})
|
87
88
|
pages = Landable::Page.sitemappable
|
88
|
-
xml = Builder::XmlMarkup.new(
|
89
|
-
xml.instruct! :xml, encoding:
|
90
|
-
xml.urlset(xmlns:
|
89
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
90
|
+
xml.instruct! :xml, encoding: 'UTF-8'
|
91
|
+
xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do |markup|
|
91
92
|
pages.each do |page|
|
92
93
|
next if options[:exclude_categories].to_a.include? page.category.try(:name)
|
93
|
-
|
94
|
+
markup.url do |p|
|
94
95
|
p.loc "#{options[:protocol]}://#{options[:host]}#{page.path}"
|
95
96
|
p.lastmod page.updated_at.to_time.iso8601
|
96
97
|
p.changefreq 'weekly'
|
@@ -100,7 +101,7 @@ module Landable
|
|
100
101
|
|
101
102
|
if options[:sitemap_additional_paths].present?
|
102
103
|
options[:sitemap_additional_paths].each do |page|
|
103
|
-
|
104
|
+
markup.url do |p|
|
104
105
|
p.loc "#{options[:protocol]}://#{options[:host]}#{page}"
|
105
106
|
p.changefreq 'weekly'
|
106
107
|
p.priority '1'
|
@@ -133,9 +134,9 @@ module Landable
|
|
133
134
|
end
|
134
135
|
|
135
136
|
def deactivate
|
136
|
-
|
137
|
-
|
138
|
-
publish!(author_id: updated_by_author.id, notes:
|
137
|
+
update_attribute(:status_code, 410)
|
138
|
+
|
139
|
+
publish!(author_id: updated_by_author.id, notes: 'This page has been trashed')
|
139
140
|
|
140
141
|
super
|
141
142
|
end
|
@@ -145,7 +146,7 @@ module Landable
|
|
145
146
|
end
|
146
147
|
|
147
148
|
def directory_after(prefix)
|
148
|
-
remainder = path.gsub(
|
149
|
+
remainder = path.gsub(%r{^#{prefix}\/?}, '')
|
149
150
|
segments = remainder.split('/', 2)
|
150
151
|
if segments.length == 1
|
151
152
|
nil
|
@@ -160,15 +161,13 @@ module Landable
|
|
160
161
|
|
161
162
|
def path=(name)
|
162
163
|
# if not present, add a leading slash for a non-empty path
|
163
|
-
|
164
|
-
name = name.gsub(/^\/?(.*)/, '/\1')
|
165
|
-
end
|
164
|
+
name = name.gsub(%r{^\/?(.*)}, '/\1') if name && !name.empty?
|
166
165
|
|
167
166
|
self[:path] = name
|
168
167
|
end
|
169
168
|
|
170
169
|
def hero_asset_name
|
171
|
-
|
170
|
+
hero_asset.try(:name)
|
172
171
|
end
|
173
172
|
|
174
173
|
def hero_asset_name=(name)
|
@@ -178,7 +177,7 @@ module Landable
|
|
178
177
|
end
|
179
178
|
|
180
179
|
def hero_asset_url
|
181
|
-
|
180
|
+
hero_asset.try(:public_url)
|
182
181
|
end
|
183
182
|
|
184
183
|
def publish!(options)
|
@@ -216,39 +215,35 @@ module Landable
|
|
216
215
|
end
|
217
216
|
|
218
217
|
def forbid_changing_path
|
219
|
-
errors[:path] =
|
218
|
+
errors[:path] = 'can not be changed!' if self.path_changed?
|
220
219
|
end
|
221
220
|
|
222
221
|
def body_strip_search
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
errors[:body] = 'had a problem: ' + error.message
|
229
|
-
end
|
222
|
+
RenderService.call(self)
|
223
|
+
rescue ::Liquid::Error
|
224
|
+
errors[:body] = 'contains a Liquid syntax error'
|
225
|
+
rescue StandardError => error
|
226
|
+
errors[:body] = 'had a problem: ' + error.message
|
230
227
|
end
|
231
228
|
|
232
229
|
def page_name_byte_size
|
233
|
-
|
234
|
-
|
235
|
-
end
|
230
|
+
return unless page_name.present? && page_name.bytesize > 100
|
231
|
+
errors[:page_name] = 'Invalid PageName, bytesize is too big!'
|
236
232
|
end
|
237
233
|
|
238
234
|
def hero_asset_existence
|
239
235
|
return true if @hero_asset_name.blank?
|
240
|
-
|
241
|
-
|
242
|
-
end
|
236
|
+
return if Asset.find_by_name(@hero_asset_name)
|
237
|
+
errors[:hero_asset_name] = "System can't find an asset with this name"
|
243
238
|
end
|
244
239
|
|
245
240
|
def to_liquid
|
246
241
|
{
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
242
|
+
'title' => title,
|
243
|
+
'url' => path,
|
244
|
+
'hero_asset' => hero_asset ? true : false,
|
245
|
+
'hero_asset_url' => hero_asset_url,
|
246
|
+
'abstract' => abstract
|
252
247
|
}
|
253
248
|
end
|
254
249
|
|
@@ -276,6 +271,5 @@ module Landable
|
|
276
271
|
end
|
277
272
|
|
278
273
|
include Errors
|
279
|
-
|
280
274
|
end
|
281
275
|
end
|