hancock_cms_pages 1.0.0
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/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/hancock/pages/init.coffee +2 -0
- data/app/assets/javascripts/hancock/pages/scrolling.coffee +55 -0
- data/app/assets/javascripts/hancock/pages.coffee +6 -0
- data/app/assets/stylesheets/hancock/pages.sass +1 -0
- data/app/controllers/concerns/hancock/pages/blocksetable.rb +104 -0
- data/app/controllers/concerns/hancock/pages/decorators/pages.rb +15 -0
- data/app/controllers/concerns/hancock/pages/localizeable.rb +66 -0
- data/app/controllers/concerns/hancock/pages/nav_menu.rb +91 -0
- data/app/controllers/concerns/hancock/pages/seo_pages.rb +99 -0
- data/app/controllers/hancock/pages/pages_controller.rb +7 -0
- data/app/helpers/hancock/pages/canonical_helper.rb +12 -0
- data/app/helpers/hancock/pages/pages_helpers.rb +2 -0
- data/app/models/concerns/hancock/pages/canonicalable.rb +22 -0
- data/app/models/concerns/hancock/pages/connectable.rb +36 -0
- data/app/models/concerns/hancock/pages/decorators/block.rb +39 -0
- data/app/models/concerns/hancock/pages/decorators/blockset.rb +39 -0
- data/app/models/concerns/hancock/pages/decorators/menu.rb +39 -0
- data/app/models/concerns/hancock/pages/decorators/page.rb +39 -0
- data/app/models/hancock/pages/block.rb +13 -0
- data/app/models/hancock/pages/blockset.rb +13 -0
- data/app/models/hancock/pages/menu.rb +16 -0
- data/app/models/hancock/pages/page.rb +16 -0
- data/app/views/blocks/_header.html.slim +4 -0
- data/app/views/hancock/pages/pages/show.html.slim +1 -0
- data/app/views/rails_admin/main/_hancock_connectable.html.slim +56 -0
- data/app/views/shared/_obj.html.slim +26 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/initializers/hancock_pages.rb +3 -0
- data/config/locales/hancock.pages.ru.yml +54 -0
- data/hancock_cms_pages.gemspec +37 -0
- data/lib/generators/hancock/pages/config/install_generator.rb +13 -0
- data/lib/generators/hancock/pages/config/templates/hancock_pages.erb +14 -0
- data/lib/generators/hancock/pages/migration_generator.rb +18 -0
- data/lib/generators/hancock/pages/models/block_generator.rb +39 -0
- data/lib/generators/hancock/pages/models/blockset_generator.rb +39 -0
- data/lib/generators/hancock/pages/models/decorators_generator.rb +24 -0
- data/lib/generators/hancock/pages/models/menu_generator.rb +39 -0
- data/lib/generators/hancock/pages/models/page_generator.rb +39 -0
- data/lib/generators/hancock/pages/models/templates/block.erb +37 -0
- data/lib/generators/hancock/pages/models/templates/blockset.erb +34 -0
- data/lib/generators/hancock/pages/models/templates/menu.erb +37 -0
- data/lib/generators/hancock/pages/models/templates/page.erb +43 -0
- data/lib/generators/hancock/pages/templates/migration_blocks.rb +42 -0
- data/lib/generators/hancock/pages/templates/migration_pages.rb +48 -0
- data/lib/hancock/pages/admin/block.rb +81 -0
- data/lib/hancock/pages/admin/blockset.rb +72 -0
- data/lib/hancock/pages/admin/menu.rb +48 -0
- data/lib/hancock/pages/admin/page.rb +105 -0
- data/lib/hancock/pages/admin.rb +45 -0
- data/lib/hancock/pages/configuration.rb +35 -0
- data/lib/hancock/pages/controllers/pages.rb +33 -0
- data/lib/hancock/pages/engine.rb +5 -0
- data/lib/hancock/pages/models/active_record/block.rb +16 -0
- data/lib/hancock/pages/models/active_record/blockset.rb +19 -0
- data/lib/hancock/pages/models/active_record/menu.rb +20 -0
- data/lib/hancock/pages/models/active_record/page.rb +22 -0
- data/lib/hancock/pages/models/block.rb +190 -0
- data/lib/hancock/pages/models/blockset.rb +69 -0
- data/lib/hancock/pages/models/menu.rb +48 -0
- data/lib/hancock/pages/models/mongoid/block.rb +34 -0
- data/lib/hancock/pages/models/mongoid/blockset.rb +22 -0
- data/lib/hancock/pages/models/mongoid/menu.rb +16 -0
- data/lib/hancock/pages/models/mongoid/page.rb +43 -0
- data/lib/hancock/pages/models/page.rb +159 -0
- data/lib/hancock/pages/rails_admin_ext/hancock_connectable.rb +33 -0
- data/lib/hancock/pages/rails_admin_ext/menu.rb +147 -0
- data/lib/hancock/pages/routes.rb +46 -0
- data/lib/hancock/pages/version.rb +5 -0
- data/lib/hancock_cms_pages.rb +54 -0
- data/release.sh +6 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3df1e024159d2a4e0fd87514fb997a63e6fe8417
|
4
|
+
data.tar.gz: 105ab60abf6d5ce295777269cd8cf56b352d4847
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b01a03fa00d94eeeee6260b335d931dabd438b655cd4f97c33b02820f5b44fc4020c86e7f4387dfa8963299439c2c612e182ff4d40ca3bd1e51be20784d022fe
|
7
|
+
data.tar.gz: a8243f8ba5ec40debc06e99a94a0c72f236c6a58c5b1467ace1f2e33c81b3552d9a7a414fc5b9e180bb1b57fc21e564eba11747726c2e352d816f7572702739a
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hancock_pages
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alexander Kiseliev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# HancockCmsPages
|
2
|
+
|
3
|
+
### Remaded from [EnjoyCMSPages](https://github.com/enjoycreative/enjoy_cms_pages)
|
4
|
+
|
5
|
+
Menu([Simple Navigation](https://github.com/codeplant/simple-navigation)), pages and html blocks for [HancockCMS](https://github.com/red-rocks/hancock_cms).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'hancock_cms_pages'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hancock_cms_pages
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Add in config/routes.rb
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
hancock_cms_pages_routes
|
29
|
+
```
|
30
|
+
|
31
|
+
Recommendation: add this line at the end fo routes.rb.
|
32
|
+
This method has route
|
33
|
+
```ruby
|
34
|
+
get '*slug'
|
35
|
+
```
|
36
|
+
so all requests will go here.
|
37
|
+
[More](https://github.com/red-rocks/hancock_cms_pages/blob/master/lib/hancock/pages/routes.rb)
|
38
|
+
|
39
|
+
Then execute
|
40
|
+
|
41
|
+
$ rails g hancock:goto:config
|
42
|
+
|
43
|
+
and now you can edit config/initializers/hancock_pages.rb
|
44
|
+
|
45
|
+
### Views
|
46
|
+
Render navigation for blockset with name 'main':
|
47
|
+
```ruby
|
48
|
+
render_navigation &blockset_navigation(:main)
|
49
|
+
```
|
50
|
+
Render blockset(set of blocks which can have html code, partials or files) with name 'main':
|
51
|
+
```ruby
|
52
|
+
render_blockset(self, :main)
|
53
|
+
```
|
54
|
+
Render navigation menu with name 'main':
|
55
|
+
```ruby
|
56
|
+
render_navigation &navigation(:main)
|
57
|
+
```
|
58
|
+
[More](https://github.com/red-rocks/hancock_cms_pages/tree/master/app/controllers/concerns/hancock/pages)
|
59
|
+
|
60
|
+
### Localization
|
61
|
+
|
62
|
+
Add to application_controller.rb:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class ApplicationController < ActionController::Base
|
66
|
+
include Hancock::Controller
|
67
|
+
include Hancock::Pages::Localizeable
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/hancock_cms_pages.
|
80
|
+
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
window.hancock_cms.pages.scrolling_menu_for = ( menu_selector = "#main_menu",
|
2
|
+
menu_item_selector = "#main_menu a",
|
3
|
+
header_height = 100,
|
4
|
+
px_per_ms = 4,
|
5
|
+
set_block_to_center = true,
|
6
|
+
time_for_animate = 1000)->
|
7
|
+
$(window).scroll ->
|
8
|
+
y = $(this).scrollTop()
|
9
|
+
$(menu_item_selector).each (event) ->
|
10
|
+
_target = $($(this).attr('href'))
|
11
|
+
if set_block_to_center
|
12
|
+
_target_position = _target.offset().top - ($(window).height() / 2)
|
13
|
+
else
|
14
|
+
_target_position = _target.offset().top
|
15
|
+
|
16
|
+
_target_position = 0 if _target_position < 0
|
17
|
+
if _target.length > 0 and y >= _target_position - header_height
|
18
|
+
$(menu_item_selector).not(this).removeClass 'active'
|
19
|
+
$(this).addClass 'active'
|
20
|
+
|
21
|
+
|
22
|
+
$(document).delegate menu_item_selector, 'click', (e)->
|
23
|
+
e.preventDefault()
|
24
|
+
_menu = $(e.currentTarget)
|
25
|
+
window.history.pushState({}, (document.title = _menu.data('history-title')), e.currentTarget.href)
|
26
|
+
|
27
|
+
if location.pathname.replace(/^\//, '') == @pathname.replace(/^\//, '') and location.hostname == @hostname
|
28
|
+
target = $(@hash)
|
29
|
+
target = if target.length then target else $('[name=' + @hash.slice(1) + ']')
|
30
|
+
target = if target.length then target else $(_menu.data('pageblock-selector'))
|
31
|
+
|
32
|
+
if target.length > 0
|
33
|
+
if px_per_ms and px_per_ms > 0
|
34
|
+
if set_block_to_center
|
35
|
+
target_top = target.offset().top - ($(window).height() / 2) + header_height
|
36
|
+
else
|
37
|
+
target_top = target.offset().top + header_height
|
38
|
+
|
39
|
+
current_top = window.scrollY
|
40
|
+
animate_length = Math.abs(target_top - current_top)
|
41
|
+
time_for_animate = animate_length / px_per_ms
|
42
|
+
|
43
|
+
$('html,body').animate { scrollTop: target_top }, time_for_animate
|
44
|
+
return false
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
load = ->
|
49
|
+
if window.location.hash
|
50
|
+
$(menu_item_selector).filter("[href='" + window.location.hash + "']").click()
|
51
|
+
|
52
|
+
$(window).load ->
|
53
|
+
load()
|
54
|
+
$(document).bind "page:load", ->
|
55
|
+
load()
|
@@ -0,0 +1 @@
|
|
1
|
+
#= require_self
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Hancock::Pages::Blocksetable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
helper_method :render_blockset
|
5
|
+
helper_method :blockset_navigation
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def blockset_navigation(type)
|
10
|
+
Proc.new do |primary|
|
11
|
+
SimpleNavigation.config.autogenerate_item_ids = false
|
12
|
+
begin
|
13
|
+
blockset_nav_extra_data_before(type, primary)
|
14
|
+
all_items = blockset_nav_get_menu_items(type)
|
15
|
+
items = all_items#.select { |i| i.parent_id.nil? && !i.name.blank? && i.enabled }
|
16
|
+
items.each do |item|
|
17
|
+
# render_with_subs(all_items, primary, item)
|
18
|
+
blockset_navigation_item(primary, item)
|
19
|
+
end
|
20
|
+
blockset_nav_extra_data_after(type, primary)
|
21
|
+
rescue Exception => exception
|
22
|
+
Rails.logger.error exception.message
|
23
|
+
Rails.logger.error exception.backtrace.join("\n")
|
24
|
+
puts exception.message
|
25
|
+
puts exception.backtrace.join("\n")
|
26
|
+
capture_exception(exception) if respond_to?(:capture_exception)
|
27
|
+
items || []
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_blockset(view, type)
|
33
|
+
ret = []
|
34
|
+
begin
|
35
|
+
blockset = get_blockset(type)
|
36
|
+
blocks = blockset_get_blocks_for_render(blockset)
|
37
|
+
blocks.each do |block|
|
38
|
+
ret << block.render_or_content_html(view) do |html|
|
39
|
+
after_render_blockset_block block, html
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ret = blockset.render(view, ret.join.html_safe) do |html|
|
43
|
+
after_render_blockset blockset, html
|
44
|
+
end
|
45
|
+
rescue Exception => exception
|
46
|
+
Rails.logger.error exception.message
|
47
|
+
Rails.logger.error exception.backtrace.join("\n")
|
48
|
+
puts exception.message
|
49
|
+
puts exception.backtrace.join("\n")
|
50
|
+
capture_exception(exception) if respond_to?(:capture_exception)
|
51
|
+
# ret << blocks || []
|
52
|
+
end
|
53
|
+
ret.is_a?(Array) ? ret.join.html_safe : ret
|
54
|
+
end
|
55
|
+
|
56
|
+
def after_render_blockset_block(block, html)
|
57
|
+
html
|
58
|
+
end
|
59
|
+
|
60
|
+
def after_render_blockset(blockset, html)
|
61
|
+
html
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_blockset(type)
|
65
|
+
type.is_a?(Hancock::Pages::Blockset) ? type : blockset_class.find(type.to_s)
|
66
|
+
end
|
67
|
+
|
68
|
+
def blockset_get_blocks(type)
|
69
|
+
blockset = get_blockset type
|
70
|
+
blockset.blocks.enabled.show_in_menu.sorted.to_a if blockset
|
71
|
+
end
|
72
|
+
|
73
|
+
def blockset_get_blocks_for_render(type)
|
74
|
+
blockset = get_blockset type
|
75
|
+
blockset.blocks.enabled.sorted.to_a if blockset
|
76
|
+
end
|
77
|
+
|
78
|
+
def blockset_class_name
|
79
|
+
"Hancock::Pages::Blockset"
|
80
|
+
end
|
81
|
+
def blockset_class
|
82
|
+
blockset_class_name.constantize
|
83
|
+
end
|
84
|
+
|
85
|
+
def blockset_navigation_item(primary, item, block=nil)
|
86
|
+
url = item.pageblock_selector.blank? ? item.slug : item.pageblock_selector #"javascript:;"
|
87
|
+
content = item.menu_link_content.blank? ? item.name : item.menu_link_content.html_safe
|
88
|
+
if block.nil?
|
89
|
+
primary.item(item.slug, content, url, item.nav_options)
|
90
|
+
else
|
91
|
+
primary.item(item.slug, content, url, item.nav_options, &block)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def blockset_nav_get_menu_items(type)
|
96
|
+
blockset_get_blocks(type)
|
97
|
+
end
|
98
|
+
def blockset_nav_extra_data_before(type, primary)
|
99
|
+
# override for additional config or items
|
100
|
+
end
|
101
|
+
def blockset_nav_extra_data_after(type, primary)
|
102
|
+
# override for additional config or items
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Hancock::Pages::Localizeable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
before_filter do
|
5
|
+
I18n.locale = params[:locale] || I18n.default_locale
|
6
|
+
Settings.ns_default = "main_#{I18n.locale}".freeze
|
7
|
+
Settings.ns_fallback = "main".freeze
|
8
|
+
end
|
9
|
+
end
|
10
|
+
private
|
11
|
+
def default_url_options(options={})
|
12
|
+
{locale: I18n.locale}
|
13
|
+
end
|
14
|
+
def nav_get_menu_items(type)
|
15
|
+
pages = menu_class.find(type.to_s).pages.enabled
|
16
|
+
if Hancock.mongoid?
|
17
|
+
pages = pages.where(:"name.#{I18n.locale}".exists => true)
|
18
|
+
elsif Hancock.active_record?
|
19
|
+
pages = pages.where(["EXIST(name_translations, ?) = TRUE AND name_translations -> ? != ''", I18n.locale, I18n.locale])
|
20
|
+
end
|
21
|
+
pages.sorted.to_a
|
22
|
+
end
|
23
|
+
def nav_get_url(item)
|
24
|
+
_connectable = item.connectable
|
25
|
+
if _connectable and _connectable.enabled
|
26
|
+
begin
|
27
|
+
_routes_namespace = _connectable.respond_to?(:routes_namespace) ? _connectable.routes_namespace : :main_app
|
28
|
+
_url = send(_routes_namespace.to_sym).url_for([_connectable, {only_path: true}])
|
29
|
+
rescue Exception => exception
|
30
|
+
Rails.logger.error exception.message
|
31
|
+
Rails.logger.error exception.backtrace.join("\n")
|
32
|
+
puts exception.message
|
33
|
+
puts exception.backtrace.join("\n")
|
34
|
+
capture_exception(exception) if respond_to?(:capture_exception)
|
35
|
+
|
36
|
+
_url = item.redirect.blank? ? item.fullpath : item.redirect
|
37
|
+
end
|
38
|
+
else
|
39
|
+
_url = item.redirect.blank? ? item.fullpath : item.redirect
|
40
|
+
end
|
41
|
+
_localizable_regexp = Regexp.new("^(#{I18n.available_locales.map { |l| "\\/#{l}"}.join("|")})")
|
42
|
+
((params[:locale].blank? or _url =~ _localizable_regexp) ? "" : "/#{params[:locale]}") + _url
|
43
|
+
end
|
44
|
+
def find_seo_extra(path)
|
45
|
+
_localizable_regexp = Regexp.new("^(#{I18n.available_locales.map { |l| "\\/#{l}"}.join("|")})")
|
46
|
+
_path = path.sub(_localizable_regexp, "")
|
47
|
+
if _path[0] != '/'
|
48
|
+
_path = '/' + _path
|
49
|
+
end
|
50
|
+
page_class.enabled.where(fullpath: _path).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def page_class_name
|
54
|
+
"Hancock::Pages::Page"
|
55
|
+
end
|
56
|
+
def page_class
|
57
|
+
page_class_name.constantize
|
58
|
+
end
|
59
|
+
|
60
|
+
def menu_class_name
|
61
|
+
"Hancock::Pages::Menu"
|
62
|
+
end
|
63
|
+
def menu_class
|
64
|
+
menu_class_name.constantize
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Hancock::Pages::NavMenu
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
helper_method :navigation
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def render_with_subs(items, primary, item)
|
9
|
+
subs = items.select { |i| i.parent_id == item.id && !i.name.blank? && i.enabled }
|
10
|
+
if subs.empty?
|
11
|
+
block = nil
|
12
|
+
else
|
13
|
+
block = Proc.new do |sub_nav|
|
14
|
+
subs.each { |sub|
|
15
|
+
render_with_subs(items, sub_nav, sub)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# cr = item.clean_regexp
|
20
|
+
navigation_item(primary, item, block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def navigation_item(primary, item, block=nil)
|
24
|
+
url = nav_get_url(item)
|
25
|
+
if block.nil?
|
26
|
+
primary.item(item.slug, item.name, url, item.nav_options)
|
27
|
+
else
|
28
|
+
primary.item(item.slug, item.name, url, item.nav_options, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def navigation(type)
|
33
|
+
Proc.new do |primary|
|
34
|
+
SimpleNavigation.config.autogenerate_item_ids = false
|
35
|
+
begin
|
36
|
+
nav_extra_data_before(type, primary)
|
37
|
+
all_items = nav_get_menu_items(type)
|
38
|
+
items = all_items.select { |i| i.parent_id.nil? && !i.name.blank? && i.enabled }
|
39
|
+
items.each do |item|
|
40
|
+
render_with_subs(all_items, primary, item)
|
41
|
+
end
|
42
|
+
nav_extra_data_after(type, primary)
|
43
|
+
rescue Exception => exception
|
44
|
+
Rails.logger.error exception.message
|
45
|
+
Rails.logger.error exception.backtrace.join("\n")
|
46
|
+
puts exception.message
|
47
|
+
puts exception.backtrace.join("\n")
|
48
|
+
capture_exception(exception) if respond_to?(:capture_exception)
|
49
|
+
items || []
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def nav_get_url(item)
|
55
|
+
_connectable = item.connectable
|
56
|
+
if _connectable and _connectable.enabled
|
57
|
+
begin
|
58
|
+
_routes_namespace = _connectable.respond_to?(:routes_namespace) ? _connectable.routes_namespace : :main_app
|
59
|
+
_url = send(_routes_namespace.to_sym).url_for([_connectable, {only_path: true}])
|
60
|
+
_url
|
61
|
+
rescue Exception => exception
|
62
|
+
Rails.logger.error exception.message
|
63
|
+
Rails.logger.error exception.backtrace.join("\n")
|
64
|
+
puts exception.message
|
65
|
+
puts exception.backtrace.join("\n")
|
66
|
+
capture_exception(exception) if respond_to?(:capture_exception)
|
67
|
+
|
68
|
+
item.redirect.blank? ? item.fullpath : item.redirect
|
69
|
+
end
|
70
|
+
else
|
71
|
+
item.redirect.blank? ? item.fullpath : item.redirect
|
72
|
+
end
|
73
|
+
end
|
74
|
+
def nav_get_menu_items(type)
|
75
|
+
menu = menu_class.find(type.to_s)
|
76
|
+
menu.pages.enabled.sorted.to_a if menu
|
77
|
+
end
|
78
|
+
def nav_extra_data_before(type, primary)
|
79
|
+
# override for additional config or items
|
80
|
+
end
|
81
|
+
def nav_extra_data_after(type, primary)
|
82
|
+
# override for additional config or items
|
83
|
+
end
|
84
|
+
|
85
|
+
def menu_class_name
|
86
|
+
"Hancock::Pages::Menu"
|
87
|
+
end
|
88
|
+
def menu_class
|
89
|
+
menu_class_name.constantize
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Hancock::Pages::SeoPages
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
before_filter :find_page
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def find_page
|
9
|
+
return if rails_admin?
|
10
|
+
@seo_page = find_seo_page request.path
|
11
|
+
if !@seo_page.nil? && !@seo_page.redirect.blank?
|
12
|
+
redirect_to @seo_page.redirect, status: :moved_permanently
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_seo_page(path)
|
17
|
+
do_redirect = false
|
18
|
+
if path[0] != '/'
|
19
|
+
path = '/' + path
|
20
|
+
end
|
21
|
+
if path.length > 1 && path[-1] == '/'
|
22
|
+
path = path[0..-2]
|
23
|
+
do_redirect = true
|
24
|
+
end
|
25
|
+
page = page_class.enabled.where(fullpath: path).first
|
26
|
+
|
27
|
+
if page.nil? && !params[:slug].blank?
|
28
|
+
page = page_class.enabled.where(fullpath: "/" + params[:slug]).first
|
29
|
+
end
|
30
|
+
|
31
|
+
if page.nil?
|
32
|
+
page = find_seo_extra(path)
|
33
|
+
end
|
34
|
+
|
35
|
+
if page.nil?
|
36
|
+
do_redirect = true
|
37
|
+
spath = path.chomp(File.extname(path))
|
38
|
+
if spath != path and spath != "/" + params[:slug]
|
39
|
+
page = page_class.enabled.where(fullpath: spath).first
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if !page.nil? && do_redirect
|
44
|
+
redirect_to path, status: :moved_permanently
|
45
|
+
end
|
46
|
+
|
47
|
+
page
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_seo_page_with_redirect(path)
|
51
|
+
do_redirect = false
|
52
|
+
if path[0] != '/'
|
53
|
+
path = '/' + path
|
54
|
+
end
|
55
|
+
if path.length > 1 && path[-1] == '/'
|
56
|
+
path = path[0..-2]
|
57
|
+
do_redirect = true
|
58
|
+
end
|
59
|
+
|
60
|
+
page = page_class.enabled.any_of({fullpath: path}, {redirect: path}).first
|
61
|
+
if page.nil?
|
62
|
+
do_redirect = true
|
63
|
+
spath = path.chomp(File.extname(path))
|
64
|
+
if spath != path
|
65
|
+
page = page_class.enabled.any_of({fullpath: spath}, {redirect: spath}).first
|
66
|
+
end
|
67
|
+
end
|
68
|
+
if !page.nil? && do_redirect
|
69
|
+
redirect_to path, status: :moved_permanently
|
70
|
+
end
|
71
|
+
|
72
|
+
page
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def page_title
|
77
|
+
if @seo_page.nil?
|
78
|
+
Settings ? Settings.default_title : "" #temp
|
79
|
+
else
|
80
|
+
@seo_page.page_title
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def find_seo_extra(path)
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def page_class_name
|
90
|
+
"Hancock::Pages::Page"
|
91
|
+
end
|
92
|
+
def page_class
|
93
|
+
page_class_name.constantize
|
94
|
+
end
|
95
|
+
|
96
|
+
def rails_admin?
|
97
|
+
self.is_a?(RailsAdmin::ApplicationController) || self.is_a?(RailsAdmin::MainController)
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Hancock::Pages::CanonicalHelper
|
2
|
+
def hancock_canonical_tag(url = "")
|
3
|
+
return if url.blank?
|
4
|
+
tag(:link, href: url, rel: :canonical)
|
5
|
+
end
|
6
|
+
|
7
|
+
def hancock_canonical_tag_for(obj)
|
8
|
+
return unless obj.use_hancock_canonicalable
|
9
|
+
url = obj.hancock_canonical_url
|
10
|
+
hancock_canonical_tag(url) unless url.blank?
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Hancock::Pages::Canonicalable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def hancock_canonical_fields(default = true)
|
6
|
+
if Hancock::Pages.mongoid?
|
7
|
+
field :use_hancock_canonicalable, type: Mongoid::Boolean, default: default
|
8
|
+
belongs_to :hancock_canonicalable, polymorphic: true
|
9
|
+
field :hancock_canonicalable_url, type: String, default: ""
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
included do
|
15
|
+
hancock_canonical_fields
|
16
|
+
def hancock_canonical_url(view_object)
|
17
|
+
return hancock_canonicalable_url unless hancock_canonicalable_url.blank?
|
18
|
+
return view_object.url_for hancock_canonicalable unless hancock_canonicalable.nil?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Hancock::Pages::Connectable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def hancock_connectable_field (name = :connected_pages, opts = {})
|
6
|
+
class_name = opts.delete(:class_name)
|
7
|
+
class_name ||= "Hancock::Pages::Page"
|
8
|
+
routes_namespace = opts.delete(:routes_namespace)
|
9
|
+
routes_namespace ||= :main_app
|
10
|
+
autocreate_page = opts.delete(:autocreate_page)
|
11
|
+
autocreate_page = false if autocreate_page.nil?
|
12
|
+
|
13
|
+
has_many name, as: :hancock_connectable, class_name: class_name
|
14
|
+
class_eval <<-EVAL
|
15
|
+
def routes_namespace
|
16
|
+
:#{routes_namespace}
|
17
|
+
end
|
18
|
+
EVAL
|
19
|
+
|
20
|
+
if autocreate_page
|
21
|
+
attr_accessor :hancock_connectable_autocreate_page
|
22
|
+
_name_attr = Hancock::Pages.config.localize ? "name_translations" : "name"
|
23
|
+
class_eval <<-EVAL
|
24
|
+
after_create do
|
25
|
+
if [true, 1, "1", "true", "t"].include?(self.hancock_connectable_autocreate_page)
|
26
|
+
_p = #{class_name}.new
|
27
|
+
_p.#{_name_attr} = self.#{_name_attr}
|
28
|
+
_p.connectable = self
|
29
|
+
_p.save
|
30
|
+
end
|
31
|
+
end
|
32
|
+
EVAL
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|