humpyard 0.0.1
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.
- data/Gemfile +28 -0
- data/README.rdoc +61 -0
- data/VERSION +1 -0
- data/app/controllers/humpyard/assets_controller.rb +123 -0
- data/app/controllers/humpyard/elements_controller.rb +200 -0
- data/app/controllers/humpyard/errors_controller.rb +8 -0
- data/app/controllers/humpyard/pages_controller.rb +365 -0
- data/app/helpers/humpyard/pages_helper.rb +19 -0
- data/app/models/humpyard/asset.rb +22 -0
- data/app/models/humpyard/assets/paperclip_asset.rb +48 -0
- data/app/models/humpyard/assets/youtube_asset.rb +38 -0
- data/app/models/humpyard/element.rb +57 -0
- data/app/models/humpyard/elements/box_element.rb +15 -0
- data/app/models/humpyard/elements/media_element.rb +13 -0
- data/app/models/humpyard/elements/news_element.rb +13 -0
- data/app/models/humpyard/elements/sitemap_element.rb +11 -0
- data/app/models/humpyard/elements/text_element.rb +49 -0
- data/app/models/humpyard/news_item.rb +42 -0
- data/app/models/humpyard/page.rb +153 -0
- data/app/models/humpyard/pages/news_page.rb +71 -0
- data/app/models/humpyard/pages/static_page.rb +25 -0
- data/app/models/humpyard/pages/virtual_page.rb +30 -0
- data/app/views/humpyard/assets/_edit.html.haml +15 -0
- data/app/views/humpyard/assets/_index.html.haml +24 -0
- data/app/views/humpyard/assets/_list.html.haml +4 -0
- data/app/views/humpyard/assets/_list_item.html.haml +1 -0
- data/app/views/humpyard/assets/_show.html.haml +38 -0
- data/app/views/humpyard/assets/_show_asset.html.haml +3 -0
- data/app/views/humpyard/assets/destroy.js.erb +4 -0
- data/app/views/humpyard/assets/paperclip_assets/_edit.html.haml +4 -0
- data/app/views/humpyard/assets/paperclip_assets/_info_table.html.haml +10 -0
- data/app/views/humpyard/assets/paperclip_assets/_show.html.haml +12 -0
- data/app/views/humpyard/assets/youtube_assets/_edit.html.haml +4 -0
- data/app/views/humpyard/assets/youtube_assets/_show.html.haml +5 -0
- data/app/views/humpyard/common/_head.html.haml +8 -0
- data/app/views/humpyard/common/_page_construct.html.haml +45 -0
- data/app/views/humpyard/elements/_edit.html.haml +25 -0
- data/app/views/humpyard/elements/_inline_edit.haml +0 -0
- data/app/views/humpyard/elements/_new.html.haml +1 -0
- data/app/views/humpyard/elements/_show.html.haml +29 -0
- data/app/views/humpyard/elements/_show_container.html.haml +3 -0
- data/app/views/humpyard/elements/_show_view.html.haml +2 -0
- data/app/views/humpyard/elements/box_elements/_edit.html.haml +4 -0
- data/app/views/humpyard/elements/box_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/box_elements/_show.html.haml +5 -0
- data/app/views/humpyard/elements/destroy.js.erb +1 -0
- data/app/views/humpyard/elements/error.js.erb +1 -0
- data/app/views/humpyard/elements/media_elements/_edit.html.haml +7 -0
- data/app/views/humpyard/elements/media_elements/_show.html.haml +8 -0
- data/app/views/humpyard/elements/news_elements/_edit.html.haml +5 -0
- data/app/views/humpyard/elements/news_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/news_elements/_show.html.haml +4 -0
- data/app/views/humpyard/elements/sitemap_elements/_edit.html.haml +5 -0
- data/app/views/humpyard/elements/sitemap_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/sitemap_elements/_show.html.haml +3 -0
- data/app/views/humpyard/elements/sitemap_elements/_show_part.html.haml +12 -0
- data/app/views/humpyard/elements/text_elements/_edit.html.haml +4 -0
- data/app/views/humpyard/elements/text_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/text_elements/_show.html.haml +4 -0
- data/app/views/humpyard/pages/_content.html.haml +2 -0
- data/app/views/humpyard/pages/_edit.html.haml +39 -0
- data/app/views/humpyard/pages/_index.html.haml +23 -0
- data/app/views/humpyard/pages/_show.html.haml +16 -0
- data/app/views/humpyard/pages/_subtree.html.haml +6 -0
- data/app/views/humpyard/pages/_tree.html.haml +3 -0
- data/app/views/humpyard/pages/destroy.js.erb +4 -0
- data/app/views/humpyard/pages/news_pages/_detail.html.haml +10 -0
- data/app/views/humpyard/pages/news_pages/_edit.html.haml +3 -0
- data/app/views/humpyard/pages/news_pages/_show.html.haml +5 -0
- data/app/views/humpyard/pages/show.html.haml +3 -0
- data/app/views/humpyard/pages/static_pages/_edit.html.haml +1 -0
- data/app/views/humpyard/pages/static_pages/_show.html.haml +1 -0
- data/app/views/humpyard/pages/virtual_pages/_edit.html.haml +7 -0
- data/app/views/humpyard/pages/virtual_pages/_show.html.haml +4 -0
- data/app/views/humpyard/pages/welcome.html.haml +13 -0
- data/compass/stylesheets/_humpyard.scss +12 -0
- data/compass/stylesheets/humpyard/_backend.scss +1 -0
- data/compass/stylesheets/humpyard/_base.scss +144 -0
- data/compass/stylesheets/humpyard/_ie.scss +1 -0
- data/compass/stylesheets/humpyard/_jquery_ui_overrides.scss +380 -0
- data/compass/stylesheets/humpyard/_print.scss +3 -0
- data/config/locales/de.yml +84 -0
- data/config/locales/en.yml +81 -0
- data/config/routes.rb +38 -0
- data/db/migrate/20100321134138_base.rb +60 -0
- data/db/migrate/20100330204700_create_box_element.rb +24 -0
- data/db/migrate/20100401153655_page_template.rb +11 -0
- data/db/migrate/20100409195732_page_types.rb +26 -0
- data/db/migrate/20100413230623_element_yield.rb +14 -0
- data/db/migrate/20100415132312_news_page.rb +48 -0
- data/db/migrate/20100415193423_page_i18n_name.rb +27 -0
- data/db/migrate/20100415213700_create_news_element.rb +12 -0
- data/db/migrate/20100703120000_shared_elements.rb +9 -0
- data/db/migrate/20101001142534_page_modified_at.rb +11 -0
- data/db/migrate/20101003100138_create_sitemap_elements.rb +13 -0
- data/db/migrate/20101003122108_create_humpyard_pages_virtual_pages.rb +11 -0
- data/db/migrate/20101006070503_page_cache_control.rb +9 -0
- data/db/migrate/20101104173743_create_media.rb +36 -0
- data/db/migrate/20110425230524_media_with_link.rb +9 -0
- data/lib/generators/humpyard.rb +114 -0
- data/lib/generators/humpyard/auth/auth_generator.rb +191 -0
- data/lib/generators/humpyard/auth/templates/authlogic/README +9 -0
- data/lib/generators/humpyard/auth/templates/authlogic/controllers/user_sessions_controller.rb +22 -0
- data/lib/generators/humpyard/auth/templates/authlogic/migration.rb +17 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/user.rb +7 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/user_session.rb +6 -0
- data/lib/generators/humpyard/auth/templates/authlogic/views/user_sessions/new.html.haml +12 -0
- data/lib/generators/humpyard/auth/templates/custom/README +8 -0
- data/lib/generators/humpyard/auth/templates/devise/README +14 -0
- data/lib/generators/humpyard/auth/templates/devise/models/ability.rb +14 -0
- data/lib/generators/humpyard/auth/templates/fake/README +0 -0
- data/lib/generators/humpyard/auth/templates/fake/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/simple/README +16 -0
- data/lib/generators/humpyard/auth/templates/simple/config/humpyard_users.yml +2 -0
- data/lib/generators/humpyard/auth/templates/simple/controllers/user_sessions_controller.rb +39 -0
- data/lib/generators/humpyard/auth/templates/simple/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/simple/views/user_sessions/new.html.haml +15 -0
- data/lib/generators/humpyard/element/USAGE +7 -0
- data/lib/generators/humpyard/element/element_generator.rb +82 -0
- data/lib/generators/humpyard/element/templates/_edit.html.haml +12 -0
- data/lib/generators/humpyard/element/templates/_inline_edit.html.haml +0 -0
- data/lib/generators/humpyard/element/templates/_show.html.haml +9 -0
- data/lib/generators/humpyard/element/templates/fixtures.yml +23 -0
- data/lib/generators/humpyard/element/templates/migration.rb +16 -0
- data/lib/generators/humpyard/element/templates/model.rb +11 -0
- data/lib/generators/humpyard/element/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/humpyard/element/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/humpyard/element/templates/tests/test_unit/model.rb +7 -0
- data/lib/generators/humpyard/page/USAGE +7 -0
- data/lib/generators/humpyard/page/page_generator.rb +80 -0
- data/lib/generators/humpyard/page/templates/_edit.html.haml +7 -0
- data/lib/generators/humpyard/page/templates/_show.html.haml +4 -0
- data/lib/generators/humpyard/page/templates/fixtures.yml +23 -0
- data/lib/generators/humpyard/page/templates/migration.rb +16 -0
- data/lib/generators/humpyard/page/templates/model.rb +37 -0
- data/lib/generators/humpyard/page/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/humpyard/page/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/humpyard/page/templates/tests/test_unit/model.rb +7 -0
- data/lib/generators/humpyard/skeleton/USAGE +6 -0
- data/lib/generators/humpyard/skeleton/skeleton_generator.rb +99 -0
- data/lib/generators/humpyard/skeleton/templates/compass.config +14 -0
- data/lib/generators/humpyard/skeleton/templates/images/ajax-loader.gif +0 -0
- data/lib/generators/humpyard/skeleton/templates/images/grid.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/compass.rb +16 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/haml.rb +3 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/humpyard.rb +20 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/d.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/throbber.gif +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-1.5.1.js +8316 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-humpyard.js +790 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-rails.js +157 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-ui-1.8.10.js +11544 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.form-2.64.js +803 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.jstree.js +3510 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/jquery-ui-1.8.10.css +573 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.sass +15 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.scss +16 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.sass +12 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.scss +11 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/print.sass +3 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/print.scss +3 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.sass +78 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.scss +90 -0
- data/lib/generators/humpyard/skeleton/templates/views/layout.html.haml +28 -0
- data/lib/html_to_textile.rb +220 -0
- data/lib/humpyard.rb +70 -0
- data/lib/humpyard/action_controller/base.rb +24 -0
- data/lib/humpyard/active_model/naming.rb +29 -0
- data/lib/humpyard/active_model/translation.rb +26 -0
- data/lib/humpyard/active_model/validators/publish_range.rb +14 -0
- data/lib/humpyard/active_record/acts/asset.rb +68 -0
- data/lib/humpyard/active_record/acts/container_element.rb +26 -0
- data/lib/humpyard/active_record/acts/element.rb +89 -0
- data/lib/humpyard/active_record/acts/page.rb +101 -0
- data/lib/humpyard/active_record/has/title_for_url.rb +75 -0
- data/lib/humpyard/compass.rb +6 -0
- data/lib/humpyard/config.rb +235 -0
- data/lib/humpyard/engine.rb +7 -0
- data/lib/humpyard/uri_parser.rb +16 -0
- data/lib/humpyard/uri_parser/assets_uri_parser.rb +15 -0
- data/lib/humpyard/uri_parser/pages_uri_parser.rb +15 -0
- data/lib/tasks/humpyard.rake +103 -0
- metadata +331 -0
data/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem "rails", '>=3.0.0'
|
4
|
+
gem 'builder'
|
5
|
+
gem 'haml', '>=3.0.0'
|
6
|
+
gem 'compass', '>=0.10.0'
|
7
|
+
gem 'acts_as_tree', '>=0.1.1'
|
8
|
+
gem 'cancan', '>=1.6.4'
|
9
|
+
gem 'globalize3', '>=0.0.7'
|
10
|
+
gem 'humpyard_form', :git => 'http://github.com/humpyard/humpyard_form.git'
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem 'test-unit'
|
14
|
+
gem 'rspec-rails', '>=2.0.0.beta.22'
|
15
|
+
gem 'capybara', '>=0.3.7'
|
16
|
+
gem 'database_cleaner', '>=0.5.2'
|
17
|
+
gem 'cucumber', '>=0.8.5'
|
18
|
+
gem 'cucumber-rails', '>=0.3.2'
|
19
|
+
gem 'pickle', '>=0.4.2'
|
20
|
+
gem 'factory_girl', '>=1.3.2'
|
21
|
+
gem 'markup_validity', '>=1.1.0'
|
22
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
23
|
+
gem 'thin'
|
24
|
+
end
|
25
|
+
|
26
|
+
if RUBY_VERSION < '1.9'
|
27
|
+
gem 'ruby-debug', '>=0.10.3'
|
28
|
+
end
|
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= humpyard
|
2
|
+
|
3
|
+
Humpyard is a CMS in a gem for Rails 3.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
* Add Humpyard to your Rails application's Gemfile. It does require edge rails at the moment.
|
8
|
+
gem "rails", '>=3.0.0'
|
9
|
+
gem 'builder'
|
10
|
+
gem 'haml', '>=3.0.0'
|
11
|
+
gem 'compass', '>=0.10.0'
|
12
|
+
gem 'acts_as_tree', '>=0.1.1'
|
13
|
+
gem 'cancan', '>=1.3.4'
|
14
|
+
gem 'globalize3', '>=0.0.7'
|
15
|
+
gem 'humpyard_form', '>=0.0.4'
|
16
|
+
gem 'humpyard', :git => 'git://github.com/humpyard/humpyard.git'
|
17
|
+
|
18
|
+
* If you want to use textil syntax on TextElements also add RedCloth to the Gemfile.
|
19
|
+
gem 'RedCloth', '>=4.2.3'
|
20
|
+
|
21
|
+
* Change into your Rails application's directory
|
22
|
+
|
23
|
+
* Generate Humpyard skeleton
|
24
|
+
rails generate humpyard:skeleton
|
25
|
+
A full documentation of options for creating a humpyard skeleton can be
|
26
|
+
found at the Humpyard::Generators::ElementGenerator section of this documentation.
|
27
|
+
|
28
|
+
* Use an Auth Framework
|
29
|
+
|
30
|
+
rails generate humpyard:auth
|
31
|
+
At the moment there is only a fake user framework for toggling if the admin-user
|
32
|
+
is logged in or not. There are going to be generators for both, Authlogic and Devise,
|
33
|
+
as soon as we get those to work with edge Rails.
|
34
|
+
|
35
|
+
As the abilities in Humpyard are defined by CanCan, it should be possible to use any
|
36
|
+
auth framework to authentice your users.
|
37
|
+
|
38
|
+
* Migrate the Humpyard database tables
|
39
|
+
rake humpyard:db:migrate
|
40
|
+
|
41
|
+
* Create an initial root page (recommended)
|
42
|
+
rake humpyard:pages:create_root
|
43
|
+
|
44
|
+
== API Documentation
|
45
|
+
|
46
|
+
* API Documentation can be created by running
|
47
|
+
rake rdoc
|
48
|
+
from the humpyard project directory.
|
49
|
+
* There is an auto-generated, up-to-the-hour online_documentation[http://humpyard.org/rdoc] of the API Documentation.
|
50
|
+
|
51
|
+
== Note on Patches/Pull Requests
|
52
|
+
|
53
|
+
* Fork the project.
|
54
|
+
* Make your feature addition or bug fix.
|
55
|
+
* Add tests for it. No discussion. No tests, no game. We use rspec and cucumber with associated addons.
|
56
|
+
* Commit, do not mess with rakefile, version, or history. If you want to have your own version, thats fine. But bump your version in a seperate commit that can be ignored when pulling.
|
57
|
+
* Send me a pull request. Bonus points for topic branches.
|
58
|
+
|
59
|
+
== Copyright
|
60
|
+
|
61
|
+
Copyright (c) 2010 Sven G. Brönstrup. See LICENSE for details.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module Humpyard
|
2
|
+
class AssetsController < ::ApplicationController
|
3
|
+
def index
|
4
|
+
@assets = Humpyard::Asset.all
|
5
|
+
|
6
|
+
render :partial => 'index'
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@asset = Humpyard::config.asset_types[params[:type]].new()
|
11
|
+
|
12
|
+
authorize! :create, @asset.asset
|
13
|
+
|
14
|
+
@asset_type = params[:type]
|
15
|
+
|
16
|
+
render :partial => 'edit'
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
@asset = Humpyard::config.asset_types[params[:type]].new params[:asset]
|
21
|
+
|
22
|
+
unless can? :create, @asset.asset
|
23
|
+
render :json => {
|
24
|
+
:status => :failed
|
25
|
+
}, :status => 403
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
if @asset.save
|
30
|
+
@assets = Humpyard::Asset.all
|
31
|
+
render :json => {
|
32
|
+
:status => :ok,
|
33
|
+
:replace => [{
|
34
|
+
:element => "hy-asset-listview",
|
35
|
+
:content => render_to_string(:partial => "list.html", :locals => {:assets => @assets, :asset => @asset})
|
36
|
+
}],
|
37
|
+
:flash => {
|
38
|
+
:level => 'info',
|
39
|
+
:content => I18n.t('humpyard_form.flashes.create_success', :model => Humpyard::Asset.model_name.human)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
else
|
43
|
+
render :json => {
|
44
|
+
:status => :failed,
|
45
|
+
:errors => @asset.errors,
|
46
|
+
:flash => {
|
47
|
+
:level => 'error',
|
48
|
+
:content => I18n.t('humpyard_form.flashes.create_fail', :model => Humpyard::Asset.model_name.human)
|
49
|
+
}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def edit
|
55
|
+
@asset = Humpyard::Asset.find(params[:id]).content_data
|
56
|
+
|
57
|
+
authorize! :update, @asset.asset
|
58
|
+
|
59
|
+
render :partial => 'edit'
|
60
|
+
end
|
61
|
+
|
62
|
+
def update
|
63
|
+
@asset = Humpyard::Asset.find(params[:id])
|
64
|
+
if @asset
|
65
|
+
unless can? :update, @asset
|
66
|
+
render :json => {
|
67
|
+
:status => :failed
|
68
|
+
}, :status => 403
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
72
|
+
if @asset.content_data.update_attributes params[:asset]
|
73
|
+
render :json => {
|
74
|
+
:status => :ok,
|
75
|
+
:replace => [
|
76
|
+
{
|
77
|
+
:element => "hy-asset-listview-text-#{@asset.id}",
|
78
|
+
:content => render_to_string(:partial =>'list_item.html', :locals => {:asset => @asset, :active => true})
|
79
|
+
}
|
80
|
+
],
|
81
|
+
:flash => {
|
82
|
+
:level => 'info',
|
83
|
+
:content => I18n.t('humpyard_form.flashes.update_success', :model => Humpyard::Asset.model_name.human)
|
84
|
+
}
|
85
|
+
}
|
86
|
+
else
|
87
|
+
render :json => {
|
88
|
+
:status => :failed,
|
89
|
+
:errors => @asset.content_data.errors,
|
90
|
+
:flash => {
|
91
|
+
:level => 'error',
|
92
|
+
:content => I18n.t('humpyard_form.flashes.update_fail', :model => Humpyard::Asset.model_name.human)
|
93
|
+
}
|
94
|
+
}
|
95
|
+
end
|
96
|
+
else
|
97
|
+
render :json => {
|
98
|
+
:status => :failed,
|
99
|
+
:flash => {
|
100
|
+
:level => 'error',
|
101
|
+
:content => I18n.t('humpyard_form.flashes.not_found', :model => Humpyard::Asset.model_name.human)
|
102
|
+
}
|
103
|
+
}, :status => 404
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def show
|
108
|
+
@asset = Humpyard::Asset.find(params[:id]).content_data
|
109
|
+
|
110
|
+
authorize! :show, @asset.asset
|
111
|
+
|
112
|
+
render :partial => 'show'
|
113
|
+
end
|
114
|
+
|
115
|
+
def destroy
|
116
|
+
@asset = Humpyard::Asset.find(params[:id])
|
117
|
+
|
118
|
+
authorize! :destroy, @asset
|
119
|
+
|
120
|
+
@asset.destroy
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
module Humpyard
|
2
|
+
####
|
3
|
+
# Humpyard::ElementController is the controller for editing your elements
|
4
|
+
class ElementsController < ::ApplicationController
|
5
|
+
|
6
|
+
# Dialog content for a new element
|
7
|
+
def new
|
8
|
+
@element = Humpyard::config.element_types[params[:type]].new(
|
9
|
+
:page_id => params[:page_id],
|
10
|
+
:container_id => params[:container_id].to_i > 0 ? params[:container_id].to_i : nil,
|
11
|
+
:page_yield_name => params[:yield_name].blank? ? 'main' : params[:yield_name],
|
12
|
+
:shared_state => 0)
|
13
|
+
|
14
|
+
authorize! :create, @element.element
|
15
|
+
|
16
|
+
@element_type = params[:type]
|
17
|
+
@prev = Humpyard::Element.find_by_id(params[:prev_id])
|
18
|
+
@next = Humpyard::Element.find_by_id(params[:next_id])
|
19
|
+
|
20
|
+
render :partial => 'edit'
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create a new element
|
24
|
+
def create
|
25
|
+
@element = Humpyard::config.element_types[params[:type]].new params[:element]
|
26
|
+
|
27
|
+
unless can? :create, @element.element
|
28
|
+
render :json => {
|
29
|
+
:status => :failed
|
30
|
+
}, :status => 403
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
if @element.save
|
35
|
+
@prev = Humpyard::Element.find_by_id(params[:prev_id])
|
36
|
+
@next = Humpyard::Element.find_by_id(params[:next_id])
|
37
|
+
|
38
|
+
do_move(@element, @prev, @next)
|
39
|
+
|
40
|
+
insert_options = {
|
41
|
+
:element => "hy-id-#{@element.element.id}",
|
42
|
+
:url => humpyard_element_path(@element.element),
|
43
|
+
:parent => @element.container ? "hy-id-#{@element.container.id}" : "hy-content-#{@element.page_yield_name}"
|
44
|
+
}
|
45
|
+
|
46
|
+
insert_options[:before] = "hy-id-#{@next.id}" if @next
|
47
|
+
insert_options[:after] = "hy-id-#{@prev.id}" if not @next and @prev
|
48
|
+
|
49
|
+
render :json => {
|
50
|
+
:status => :ok,
|
51
|
+
:dialog => :close,
|
52
|
+
:insert => [insert_options]
|
53
|
+
}
|
54
|
+
else
|
55
|
+
render :json => {
|
56
|
+
:status => :failed,
|
57
|
+
:errors => @element.errors
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Inline edit content for an existing element
|
63
|
+
def inline_edit
|
64
|
+
@element = Humpyard::Element.find(params[:id]).content_data
|
65
|
+
|
66
|
+
authorize! :update, @element.element
|
67
|
+
|
68
|
+
render :partial => 'inline_edit'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Dialog content for an existing element
|
72
|
+
def edit
|
73
|
+
@element = Humpyard::Element.find(params[:id]).content_data
|
74
|
+
|
75
|
+
authorize! :update, @element.element
|
76
|
+
|
77
|
+
render :partial => 'edit'
|
78
|
+
end
|
79
|
+
|
80
|
+
# Update an existing element
|
81
|
+
def update
|
82
|
+
@element = Humpyard::Element.find(params[:id])
|
83
|
+
if @element
|
84
|
+
unless can? :update, @element
|
85
|
+
render :json => {
|
86
|
+
:status => :failed
|
87
|
+
}, :status => 403
|
88
|
+
return
|
89
|
+
end
|
90
|
+
|
91
|
+
if @element.content_data.update_attributes params[:element]
|
92
|
+
render :json => {
|
93
|
+
:status => :ok,
|
94
|
+
:dialog => :close,
|
95
|
+
:replace => [
|
96
|
+
{
|
97
|
+
:element => "hy-id-#{@element.id}",
|
98
|
+
:url => humpyard_element_path(@element)
|
99
|
+
}
|
100
|
+
]
|
101
|
+
}
|
102
|
+
else
|
103
|
+
render :json => {
|
104
|
+
:status => :failed,
|
105
|
+
:errors => @element.content_data.errors
|
106
|
+
}
|
107
|
+
end
|
108
|
+
else
|
109
|
+
render :json => {
|
110
|
+
:status => :failed
|
111
|
+
}, :status => 404
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Move an element
|
116
|
+
def move
|
117
|
+
@element = Humpyard::Element.find(params[:id])
|
118
|
+
|
119
|
+
if @element
|
120
|
+
unless can? :update, @element
|
121
|
+
render :json => {
|
122
|
+
:status => :failed
|
123
|
+
}, :status => 403
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
@element.update_attributes(
|
128
|
+
:container => Humpyard::Element.find_by_id(params[:container_id]),
|
129
|
+
:page_yield_name => params[:yield_name]
|
130
|
+
)
|
131
|
+
@prev = Humpyard::Element.find_by_id(params[:prev_id])
|
132
|
+
@next = Humpyard::Element.find_by_id(params[:next_id])
|
133
|
+
|
134
|
+
do_move(@element, @prev, @next)
|
135
|
+
|
136
|
+
render :json => {
|
137
|
+
:status => :ok
|
138
|
+
}
|
139
|
+
else
|
140
|
+
render :json => {
|
141
|
+
:status => :failed
|
142
|
+
}, :status => 404
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Destroy an element
|
147
|
+
def destroy
|
148
|
+
@element = Humpyard::Element.find_by_id(params[:id])
|
149
|
+
|
150
|
+
if can? :destroy, @element
|
151
|
+
@element.destroy
|
152
|
+
else
|
153
|
+
@error = "You have no permission to delete this element (id: #{@element.class}:#{params[:id]})"
|
154
|
+
render :error
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Render a given element
|
159
|
+
def show
|
160
|
+
@element = Humpyard::Element.find(params[:id])
|
161
|
+
|
162
|
+
authorize! :read, @element
|
163
|
+
|
164
|
+
render :partial => 'show', :locals => {:element => @element}
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
def do_move(element, prev_element, next_element) #:nodoc#
|
169
|
+
if element.container
|
170
|
+
neighbours = element.container.elements
|
171
|
+
else
|
172
|
+
neighbours = element.page.root_elements(element.page_yield_name)
|
173
|
+
end
|
174
|
+
|
175
|
+
#p "before #{next_id} and after #{prev_id}"
|
176
|
+
p "page_yield: #{element.page_yield_name}"
|
177
|
+
|
178
|
+
position = 0
|
179
|
+
neighbours.each do |el|
|
180
|
+
if next_element == el
|
181
|
+
p "insert element #{element.id} before #{el.id}"
|
182
|
+
element.update_attribute :position, position
|
183
|
+
position += 1
|
184
|
+
end
|
185
|
+
if element != el
|
186
|
+
p "process #{el.id} to position #{position}"
|
187
|
+
el.update_attribute :position, position unless element.position == position
|
188
|
+
end
|
189
|
+
if not next_element and prev_element == el
|
190
|
+
p "insert element #{element.id} after #{el.id}"
|
191
|
+
position += 1
|
192
|
+
element.update_attribute :position, position
|
193
|
+
end
|
194
|
+
if element != el
|
195
|
+
position += 1
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,365 @@
|
|
1
|
+
module Humpyard
|
2
|
+
####
|
3
|
+
# Humpyard::PagesController is the controller for editing and viewing pages
|
4
|
+
class PagesController < ::ApplicationController
|
5
|
+
helper 'humpyard::pages'
|
6
|
+
|
7
|
+
# Probably unneccassary - may be removed later
|
8
|
+
def index
|
9
|
+
authorize! :manage, Humpyard::Page
|
10
|
+
|
11
|
+
@root_page = Humpyard::Page.root
|
12
|
+
@page = Humpyard::Page.find_by_id(params[:actual_page_id])
|
13
|
+
|
14
|
+
unless @page.nil?
|
15
|
+
@page = @page.content_data
|
16
|
+
end
|
17
|
+
render :partial => 'index'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Dialog content for a new page
|
21
|
+
def new
|
22
|
+
@page = Humpyard::config.page_types[params[:type]].new
|
23
|
+
|
24
|
+
unless can? :create, @page.page
|
25
|
+
render :json => {
|
26
|
+
:status => :failed
|
27
|
+
}, :status => 403
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
@page_type = params[:type]
|
32
|
+
@prev = Humpyard::Page.find_by_id(params[:prev_id])
|
33
|
+
@next = Humpyard::Page.find_by_id(params[:next_id])
|
34
|
+
|
35
|
+
render :partial => 'edit'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create a new page
|
39
|
+
def create
|
40
|
+
@page = Humpyard::config.page_types[params[:type]].new params[:page]
|
41
|
+
@page.title_for_url = @page.page.suggested_title_for_url
|
42
|
+
|
43
|
+
authorize! :create, @page.page
|
44
|
+
|
45
|
+
if @page.save
|
46
|
+
@prev = Humpyard::Page.find_by_id(params[:prev_id])
|
47
|
+
@next = Humpyard::Page.find_by_id(params[:next_id])
|
48
|
+
|
49
|
+
#do_move(@page, @prev, @next)
|
50
|
+
|
51
|
+
# insert_options = {
|
52
|
+
# :element => "hy-id-#{@page.id}",
|
53
|
+
# :url => @page.page.human_url,
|
54
|
+
# :parent => @page.parent ? "hy-page-dialog-item-#{@page.id}" : "hy-page-dialog-pages"
|
55
|
+
# }
|
56
|
+
|
57
|
+
# insert_options[:before] = "hy-page-dialog-item-#{@next.id}" if @next
|
58
|
+
# insert_options[:after] = "hy-page-dialog-item-#{@prev.id}" if not @next and @prev
|
59
|
+
|
60
|
+
# just reload the tree
|
61
|
+
|
62
|
+
replace_options = {
|
63
|
+
:element => "hy-page-treeview",
|
64
|
+
:content => render_to_string(:partial => "tree.html", :locals => {:page => @page})
|
65
|
+
}
|
66
|
+
|
67
|
+
render :json => {
|
68
|
+
:status => :ok,
|
69
|
+
#:dialog => :close,
|
70
|
+
# :insert => [insert_options],
|
71
|
+
:replace => [replace_options],
|
72
|
+
:flash => {
|
73
|
+
:level => 'info',
|
74
|
+
:content => I18n.t('humpyard_form.flashes.create_success', :model => Humpyard::Page.model_name.human)
|
75
|
+
}
|
76
|
+
}
|
77
|
+
else
|
78
|
+
render :json => {
|
79
|
+
:status => :failed,
|
80
|
+
:errors => @page.errors,
|
81
|
+
:flash => {
|
82
|
+
:level => 'error',
|
83
|
+
:content => I18n.t('humpyard_form.flashes.create_fail', :model => Humpyard::Page.model_name.human)
|
84
|
+
}
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Dialog content for an existing page
|
90
|
+
def edit
|
91
|
+
@page = Humpyard::Page.find(params[:id]).content_data
|
92
|
+
|
93
|
+
authorize! :update, @page.page
|
94
|
+
|
95
|
+
render :partial => 'edit'
|
96
|
+
end
|
97
|
+
|
98
|
+
# Update an existing page
|
99
|
+
def update
|
100
|
+
@page = Humpyard::Page.find(params[:id]).content_data
|
101
|
+
|
102
|
+
if @page
|
103
|
+
unless can? :update, @page.page
|
104
|
+
render :json => {
|
105
|
+
:status => :failed
|
106
|
+
}, :status => 403
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
if @page.update_attributes params[:page]
|
111
|
+
@page.title_for_url = @page.page.suggested_title_for_url
|
112
|
+
@page.save
|
113
|
+
render :json => {
|
114
|
+
:status => :ok,
|
115
|
+
# :dialog => :close,
|
116
|
+
:replace => [
|
117
|
+
{
|
118
|
+
:element => "hy-page-treeview-text-#{@page.id}",
|
119
|
+
:content => @page.title
|
120
|
+
}
|
121
|
+
],
|
122
|
+
:flash => {
|
123
|
+
:level => 'info',
|
124
|
+
:content => I18n.t('humpyard_form.flashes.update_success', :model => Humpyard::Page.model_name.human)
|
125
|
+
}
|
126
|
+
}
|
127
|
+
else
|
128
|
+
render :json => {
|
129
|
+
:status => :failed,
|
130
|
+
:errors => @page.errors,
|
131
|
+
:flash => {
|
132
|
+
:level => 'error',
|
133
|
+
:content => I18n.t('humpyard_form.flashes.update_fail', :model => Humpyard::Page.model_name.human)
|
134
|
+
}
|
135
|
+
}
|
136
|
+
end
|
137
|
+
else
|
138
|
+
render :json => {
|
139
|
+
:status => :failed
|
140
|
+
}, :status => 404
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
# Move a page
|
146
|
+
def move
|
147
|
+
@page = Humpyard::Page.find(params[:id])
|
148
|
+
|
149
|
+
if @page
|
150
|
+
unless can? :update, @page
|
151
|
+
render :json => {
|
152
|
+
:status => :failed
|
153
|
+
}, :status => 403
|
154
|
+
return
|
155
|
+
end
|
156
|
+
|
157
|
+
parent = Humpyard::Page.find_by_id(params[:parent_id])
|
158
|
+
# by default, make it possible to move page to root, uncomment to do otherwise:
|
159
|
+
#unless parent
|
160
|
+
# parent = Humpyard::Page.root_page
|
161
|
+
#end
|
162
|
+
@page.update_attribute :parent, parent
|
163
|
+
@prev = Humpyard::Page.find_by_id(params[:prev_id])
|
164
|
+
@next = Humpyard::Page.find_by_id(params[:next_id])
|
165
|
+
|
166
|
+
do_move(@page, @prev, @next)
|
167
|
+
|
168
|
+
replace_options = {
|
169
|
+
:element => "hy-page-treeview",
|
170
|
+
:content => render_to_string(:partial => "tree.html", :locals => {:page => @page})
|
171
|
+
}
|
172
|
+
|
173
|
+
render :json => {
|
174
|
+
:status => :ok,
|
175
|
+
:replace => [replace_options]
|
176
|
+
}
|
177
|
+
else
|
178
|
+
render :json => {
|
179
|
+
:status => :failed
|
180
|
+
}, :status => 404
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Destroy a page
|
185
|
+
def destroy
|
186
|
+
@page = Humpyard::Page.find(params[:id])
|
187
|
+
|
188
|
+
authorize! :destroy, @page
|
189
|
+
|
190
|
+
@page.destroy
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
# Render a given page
|
195
|
+
#
|
196
|
+
# When a "webpath" parameter is given it will render the page with that name.
|
197
|
+
# This is what happens when you call a page with it's pretty URL.
|
198
|
+
#
|
199
|
+
# When no "name" is given and an "id" parameter is given it will render the
|
200
|
+
# page with the given id.
|
201
|
+
#
|
202
|
+
# When no "name" nor "id" parameter is given it will render the root page.
|
203
|
+
def show
|
204
|
+
# No page found at the beginning
|
205
|
+
@page = nil
|
206
|
+
|
207
|
+
if params[:locale] and Humpyard.config.locales.include? params[:locale].to_sym
|
208
|
+
I18n.locale = params[:locale]
|
209
|
+
elsif session[:humpyard_locale]
|
210
|
+
I18n.locale = session[:humpyard_locale]
|
211
|
+
else
|
212
|
+
I18n.locale = Humpyard.config.locales.first
|
213
|
+
end
|
214
|
+
|
215
|
+
# Find page by name
|
216
|
+
if not params[:webpath].blank?
|
217
|
+
dyn_page_path = false
|
218
|
+
parent_page = nil
|
219
|
+
params[:webpath].split('/').each do |path_part|
|
220
|
+
# Ignore multiple slashes in URLs
|
221
|
+
unless(path_part.blank?)
|
222
|
+
if(dyn_page_path)
|
223
|
+
dyn_page_path << path_part
|
224
|
+
else
|
225
|
+
# Find page by name and parent; parent=nil means page on root level
|
226
|
+
@page = Page.with_translated_attribute(:title_for_url, CGI::escape(path_part), I18n.locale).first
|
227
|
+
# Raise 404 if no page was found for the URL or subpart
|
228
|
+
raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (X4201) [#{path_part}]" if @page.nil?
|
229
|
+
raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (X4202)" if not (@page.parent == parent_page or @page.parent == Humpyard::Page.root_page)
|
230
|
+
|
231
|
+
parent_page = @page unless @page.is_root_page?
|
232
|
+
dyn_page_path = [] if @page.content_data.is_humpyard_dynamic_page?
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
if @page.content_data.is_humpyard_dynamic_page? and dyn_page_path.size > 0
|
238
|
+
@sub_page = @page.parse_path(dyn_page_path)
|
239
|
+
|
240
|
+
# Raise 404 if no page was found for the sub_page part
|
241
|
+
raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (D4201)" if @sub_page.blank?
|
242
|
+
|
243
|
+
@page_partial = "/humpyard/pages/#{@page.content_data_type.split('::').last.underscore.pluralize}/#{@sub_page[:partial]}" if @sub_page[:partial]
|
244
|
+
@local_vars = {:page => @page}.merge(@sub_page[:locals]) if @sub_page[:locals] and @sub_page[:locals].class == Hash
|
245
|
+
|
246
|
+
# render partial only if request was an AJAX-call
|
247
|
+
if request.xhr?
|
248
|
+
respond_to do |format|
|
249
|
+
format.html {
|
250
|
+
render :partial => @page_partial, :locals => @local_vars
|
251
|
+
}
|
252
|
+
end
|
253
|
+
return
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
# Find page by id
|
258
|
+
elsif not params[:id].blank?
|
259
|
+
# Render page by id if not webpath was given but an id
|
260
|
+
@page = Page.find(params[:id])
|
261
|
+
# Find root page
|
262
|
+
else
|
263
|
+
# Render index page if neither id or webpath was given
|
264
|
+
@page = Page.root_page :force_reload => true
|
265
|
+
unless @page
|
266
|
+
@page = Page.new
|
267
|
+
render '/humpyard/pages/welcome'
|
268
|
+
return false
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
# Raise 404 if no page was found
|
273
|
+
raise ::ActionController::RoutingError, "No route matches \"#{request.path}\"" if @page.nil? or @page.content_data.is_humpyard_virtual_page?
|
274
|
+
|
275
|
+
response.headers['X-Humpyard-Page'] = "#{@page.id}"
|
276
|
+
response.headers['X-Humpyard-Modified'] = "#{@page.last_modified}"
|
277
|
+
response.headers['X-Humpyard-ServerTime'] = "#{Time.now.utc}"
|
278
|
+
|
279
|
+
@page_partial ||= "/humpyard/pages/#{@page.content_data_type.split('::').last.underscore.pluralize}/show"
|
280
|
+
@local_vars ||= {:page => @page}
|
281
|
+
|
282
|
+
self.class.layout(@page.template_name)
|
283
|
+
|
284
|
+
if Rails.application.config.action_controller.perform_caching and not @page.always_refresh
|
285
|
+
fresh_when :etag => "#{humpyard_user.nil? ? '' : humpyard_user}p#{@page.id}m#{@page.last_modified}", :last_modified => @page.last_modified(:include_pages => true), :public => @humpyard_user.nil?
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# Render the sitemap.xml for robots
|
290
|
+
def sitemap
|
291
|
+
require 'builder'
|
292
|
+
|
293
|
+
xml = ::Builder::XmlMarkup.new :indent => 2
|
294
|
+
xml.instruct!
|
295
|
+
xml.tag! :urlset, {
|
296
|
+
'xmlns'=>"http://www.sitemaps.org/schemas/sitemap/0.9",
|
297
|
+
'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
|
298
|
+
'xsi:schemaLocation'=>"http://www.sitemaps.org/schemas/sitemap/0.9\nhttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
|
299
|
+
} do
|
300
|
+
|
301
|
+
base_url = "#{request.protocol}#{request.host}#{request.port==80 ? '' : ":#{request.port}"}"
|
302
|
+
|
303
|
+
if root_page = Page.root_page
|
304
|
+
Humpyard.config.locales.each do |locale|
|
305
|
+
add_to_sitemap xml, base_url, locale, [{
|
306
|
+
:index => true,
|
307
|
+
:url => root_page.human_url(:locale => locale),
|
308
|
+
:lastmod => root_page.last_modified,
|
309
|
+
:children => []
|
310
|
+
}] + root_page.child_pages(:single_root => true).map{|p| p.content_data.site_map(locale)}
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
render :xml => xml.target!
|
315
|
+
end
|
316
|
+
|
317
|
+
private
|
318
|
+
def add_to_sitemap xml, base_url, locale, pages, priority=0.8, changefreq='daily'
|
319
|
+
pages.each do |page|
|
320
|
+
if page
|
321
|
+
unless page[:hidden]
|
322
|
+
xml.tag! :url do
|
323
|
+
xml.tag! :loc, "#{base_url}#{page[:url]}"
|
324
|
+
xml.tag! :lastmod, page[:lastmod].nil? ? nil : page[:lastmod].to_time.strftime("%FT%T%z").gsub(/00$/,':00')
|
325
|
+
xml.tag! :changefreq, page[:changefreq] ? page[:changefreq] : changefreq
|
326
|
+
xml.tag! :priority, page[:index] ? 1.0 : priority
|
327
|
+
end
|
328
|
+
end
|
329
|
+
add_to_sitemap xml, base_url, locale, page[:children], priority/2
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def do_move(page, prev_page, next_page) #:nodoc#
|
335
|
+
if page.parent
|
336
|
+
neighbours = page.parent.child_pages
|
337
|
+
else
|
338
|
+
neighbours = Humpyard::Page.where('parent_id IS NULL')
|
339
|
+
end
|
340
|
+
|
341
|
+
#p "before #{next_id} and after #{prev_id}"
|
342
|
+
|
343
|
+
position = 0
|
344
|
+
neighbours.each do |p|
|
345
|
+
if next_page == p
|
346
|
+
puts "insert page #{page.id} before #{p.id}"
|
347
|
+
page.update_attribute :position, position
|
348
|
+
position += 1
|
349
|
+
end
|
350
|
+
if page != p
|
351
|
+
puts "process page #{p.id} to position #{position}"
|
352
|
+
p.update_attribute :position, position
|
353
|
+
end
|
354
|
+
if not next_page and prev_page == p
|
355
|
+
puts "insert page #{page.id} after #{p.id}"
|
356
|
+
position += 1
|
357
|
+
page.update_attribute :position, position
|
358
|
+
end
|
359
|
+
if page != p
|
360
|
+
position += 1
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|