humpyard 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,19 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module PagesHelper
|
3
|
+
def page_body(options={}, &block)
|
4
|
+
render :partial => '/humpyard/common/page_construct', :locals => {:options => options, :block => block}
|
5
|
+
end
|
6
|
+
|
7
|
+
def title(page_title)
|
8
|
+
@content_for_title = page_title.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def stylesheet(*args)
|
12
|
+
content_for(:head) { stylesheet_link_tag(*args) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def javascript(*args)
|
16
|
+
content_for(:head) { javascript_include_tag(*args) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Humpyard
|
2
|
+
class Asset < ::ActiveRecord::Base
|
3
|
+
attr_accessible :width, :height
|
4
|
+
attr_accessible :content_data, :content_data_id, :content_data_type
|
5
|
+
|
6
|
+
belongs_to :content_data, :polymorphic => true, :dependent => :destroy
|
7
|
+
|
8
|
+
set_table_name "#{Humpyard::config.table_name_prefix}assets"
|
9
|
+
|
10
|
+
def title
|
11
|
+
content_data.title
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
content_data.url
|
16
|
+
end
|
17
|
+
|
18
|
+
def content_type
|
19
|
+
content_data.content_type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Assets
|
3
|
+
class PaperclipAsset < ::ActiveRecord::Base
|
4
|
+
attr_accessible :media
|
5
|
+
|
6
|
+
acts_as_humpyard_asset :system_asset => true
|
7
|
+
|
8
|
+
# ToDo render styles - not working for non-images like mp3
|
9
|
+
|
10
|
+
begin
|
11
|
+
has_attached_file(
|
12
|
+
:media,
|
13
|
+
:default_style => :original,
|
14
|
+
#:styles => {:preview => ['500x500>', :jpg], :thumb => ['200x100>', :jpg]},
|
15
|
+
:path => ":rails_root/public/system/media/:id/:basename.:extension",
|
16
|
+
:url => "/system/media/:id/:basename.:extension"
|
17
|
+
)
|
18
|
+
validates_attachment_presence :media
|
19
|
+
after_post_process :update_media_dimensions
|
20
|
+
rescue
|
21
|
+
puts "Paperclip not usable."
|
22
|
+
end
|
23
|
+
|
24
|
+
def title
|
25
|
+
media_file_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def url
|
29
|
+
media.url
|
30
|
+
end
|
31
|
+
|
32
|
+
def content_type
|
33
|
+
media_content_type
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_media_dimensions
|
37
|
+
begin
|
38
|
+
size = Paperclip::Geometry.from_file media.queued_for_write[:original]
|
39
|
+
asset.width = size.width.to_i
|
40
|
+
asset.height = size.height.to_i
|
41
|
+
rescue
|
42
|
+
asset.width = nil
|
43
|
+
asset.height = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Assets
|
3
|
+
class YoutubeAsset < ::ActiveRecord::Base
|
4
|
+
attr_accessible :youtube_video_id
|
5
|
+
|
6
|
+
acts_as_humpyard_asset :system_asset => true
|
7
|
+
|
8
|
+
validates_presence_of :youtube_video_id
|
9
|
+
before_save :update_youtube_data
|
10
|
+
|
11
|
+
def url
|
12
|
+
"http://www.youtube.com/watch?v=#{youtube_video_id}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def title
|
16
|
+
youtube_title || "YouTube #{youtube_video_id}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def content_type
|
20
|
+
'video/youtube'
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_youtube_data
|
24
|
+
begin
|
25
|
+
require 'net/http'
|
26
|
+
|
27
|
+
xml = Net::HTTP.get_response(URI.parse("http://gdata.youtube.com/feeds/api/videos/#{youtube_video_id}")).body
|
28
|
+
|
29
|
+
title = xml.force_encoding("UTF-8").scan(/<title.*>(.+?)<\/title>/).first.first
|
30
|
+
|
31
|
+
self.youtube_title = title
|
32
|
+
rescue
|
33
|
+
self.youtube_title = "YouTube #{youtube_video_id}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Humpyard
|
2
|
+
####
|
3
|
+
# Humpyard::Element is a model of an element to display on a Humpyard::Page.
|
4
|
+
class Element < ::ActiveRecord::Base
|
5
|
+
attr_accessible :page, :page_id, :content_data, :content_data_id, :content_data_type, :page_yield_name, :container, :container_id, :display_until, :display_from, :shared_state
|
6
|
+
|
7
|
+
set_table_name "#{Humpyard::config.table_name_prefix}elements"
|
8
|
+
|
9
|
+
belongs_to :page, :class_name => 'Humpyard::Page'
|
10
|
+
belongs_to :container, :class_name => 'Humpyard::Element'
|
11
|
+
belongs_to :content_data, :polymorphic => true, :dependent => :destroy
|
12
|
+
has_many :elements, :class_name => 'Humpyard::Element', :foreign_key => :container_id, :order => :position
|
13
|
+
|
14
|
+
delegate :'is_humpyard_container_element?', :'is_humpyard_element?', :to => :content_data
|
15
|
+
|
16
|
+
validates_with Humpyard::ActiveModel::PublishRangeValidator, {:attributes => [:display_from, :display_until]}
|
17
|
+
|
18
|
+
after_create :stamp_page_modified_now
|
19
|
+
after_update :stamp_page_modified_now
|
20
|
+
after_destroy :stamp_page_modified_now
|
21
|
+
|
22
|
+
def stamp_page_modified_now
|
23
|
+
# Set page's modified_at to now without changing it's last_updated_at column
|
24
|
+
Page.update_all ['modified_at = ?', Time.now], ['id = ?', page.id]
|
25
|
+
|
26
|
+
# TODO: set other pages' modified_at if element is shared
|
27
|
+
end
|
28
|
+
|
29
|
+
# Elements can be shared on other pages. this adds #unshared?, #shared_on_siblings?, shared_on_children? getters
|
30
|
+
# plus #to_unshared, #to_shared_on_siblings, #to_shared_on_children "setters"
|
31
|
+
#
|
32
|
+
SHARED_STATES = {
|
33
|
+
:unshared => 0,
|
34
|
+
:shared_on_siblings => 1,
|
35
|
+
:shared_on_children => 2
|
36
|
+
}.each_pair do |key, value|
|
37
|
+
define_method "#{key}?" do
|
38
|
+
shared_state.to_i == value
|
39
|
+
end
|
40
|
+
define_method "to_#{key}" do
|
41
|
+
update_attribute :shared_state, value.to_i unless state == value # no point in troubling the database if the state is already == value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Return the logical modification time for the element.
|
47
|
+
#
|
48
|
+
def last_modified
|
49
|
+
rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
|
50
|
+
timestamps = [rails_root_mtime, self.updated_at]
|
51
|
+
timestamps.sort.last
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Elements
|
3
|
+
####
|
4
|
+
# Humpyard::Elements::BoxElement is a model of a container element with a box frame.
|
5
|
+
class BoxElement < ::ActiveRecord::Base
|
6
|
+
acts_as_humpyard_container_element :system_element => true
|
7
|
+
|
8
|
+
attr_accessible :title
|
9
|
+
|
10
|
+
require 'globalize'
|
11
|
+
|
12
|
+
translates :title
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Elements
|
3
|
+
class MediaElement < ::ActiveRecord::Base
|
4
|
+
attr_accessible :asset, :asset_id, :float, :uri
|
5
|
+
|
6
|
+
set_table_name "#{Humpyard::config.table_name_prefix}elements_media_elements"
|
7
|
+
|
8
|
+
acts_as_humpyard_element
|
9
|
+
|
10
|
+
belongs_to :asset, :class_name => 'Humpyard::Asset'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Elements
|
3
|
+
####
|
4
|
+
# Humpyard::Elements::TextElement is a model of a text element.
|
5
|
+
class NewsElement < ::ActiveRecord::Base
|
6
|
+
acts_as_humpyard_element :system_element => true
|
7
|
+
|
8
|
+
attr_accessible :news_page, :news_page_id
|
9
|
+
|
10
|
+
belongs_to :news_page, :class_name => 'Humpyard::Pages::NewsPage'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Elements
|
3
|
+
class SitemapElement < ::ActiveRecord::Base
|
4
|
+
set_table_name "#{Humpyard::config.table_name_prefix}elements_sitemap_elements"
|
5
|
+
|
6
|
+
acts_as_humpyard_element :system_element => true
|
7
|
+
|
8
|
+
attr_accessible :levels, :show_description
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module Elements
|
3
|
+
####
|
4
|
+
# Humpyard::Elements::TextElement is a model of a text element.
|
5
|
+
class TextElement < ::ActiveRecord::Base
|
6
|
+
acts_as_humpyard_element :system_element => true
|
7
|
+
|
8
|
+
attr_accessible :content, :html_content
|
9
|
+
|
10
|
+
require 'globalize'
|
11
|
+
|
12
|
+
translates :content
|
13
|
+
validates_presence_of :content
|
14
|
+
|
15
|
+
def html_content(options = {})
|
16
|
+
if content.blank?
|
17
|
+
html = ''
|
18
|
+
else
|
19
|
+
if Object.const_defined?('RedCloth')
|
20
|
+
html = RedCloth.new(content).to_html
|
21
|
+
else
|
22
|
+
html = content.gsub("\n", "<br />")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless html.blank?
|
27
|
+
html = Humpyard.uri_parser.substitute html if options[:parse_uris]
|
28
|
+
|
29
|
+
html.gsub(/(href="[a-z]*:\/\/)/,'target="blank" \1').html_safe
|
30
|
+
else
|
31
|
+
''
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def html_content= content
|
36
|
+
if content.blank?
|
37
|
+
self.content = ''
|
38
|
+
else
|
39
|
+
if Object.const_defined?('RedCloth')
|
40
|
+
require 'html_to_textile'
|
41
|
+
self.content = HtmlToTextile.new(content.gsub("\n", ' ')).to_textile
|
42
|
+
else
|
43
|
+
self.content = content.gsub(/<br[^>]*>/, "\n").gsub(/<[^>]*>/, '')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Humpyard
|
2
|
+
class NewsItem < ::ActiveRecord::Base
|
3
|
+
set_table_name "#{Humpyard::config.table_name_prefix}news_items"
|
4
|
+
|
5
|
+
belongs_to :news_page, :class_name => "Humpyard::Pages::NewsPage", :foreign_key => "news_page_id"
|
6
|
+
|
7
|
+
require 'globalize'
|
8
|
+
|
9
|
+
translates :title, :title_for_url, :content
|
10
|
+
has_title_for_url
|
11
|
+
|
12
|
+
validates_presence_of :title
|
13
|
+
|
14
|
+
|
15
|
+
# Return the human readable URL for the page.
|
16
|
+
#
|
17
|
+
# Posible options values are
|
18
|
+
# <tt>:locale</tt>::
|
19
|
+
# A locale given in the Humpyard::Config.locales.
|
20
|
+
# If no <tt>:locale</tt> is given the option will be ::I18n.locale by default
|
21
|
+
def human_url(options={})
|
22
|
+
options[:locale] ||= ::I18n.locale
|
23
|
+
options[:format] ||= :html
|
24
|
+
|
25
|
+
unless Humpyard::config.locales.include? options[:locale].to_sym
|
26
|
+
options[:locale] = Humpyard::config.locales.first
|
27
|
+
end
|
28
|
+
|
29
|
+
if options[:path_format]
|
30
|
+
format = "/"
|
31
|
+
else
|
32
|
+
format = ".#{options[:format].to_s}"
|
33
|
+
end
|
34
|
+
|
35
|
+
page_options = options
|
36
|
+
page_options[:path_format] = true
|
37
|
+
|
38
|
+
"#{news_page.page.human_url(page_options)}#{created_at.strftime '%Y/%m/%d'}/#{query_title_for_url(options[:locale])}#{format}"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
module Humpyard
|
2
|
+
####
|
3
|
+
# Humpyard::Page is the model for your pages. It holds the
|
4
|
+
# Humpyard::Elements containing the content of your page
|
5
|
+
# and some meta data for the page itself.
|
6
|
+
class Page < ::ActiveRecord::Base
|
7
|
+
set_table_name "#{Humpyard::config.table_name_prefix}pages"
|
8
|
+
require 'acts_as_tree'
|
9
|
+
require 'globalize'
|
10
|
+
|
11
|
+
attr_accessible :title, :title_for_url, :description
|
12
|
+
attr_accessible :template_name, :content_data, :content_data_id, :content_data_type
|
13
|
+
attr_accessible :parent, :parent_id, :in_menu, :in_sitemap, :searchable
|
14
|
+
attr_accessible :display_from, :display_until
|
15
|
+
attr_accessible :modified_at, :refresh_scheduled_at
|
16
|
+
attr_accessible :updated_at, :always_refresh
|
17
|
+
|
18
|
+
translates :title, :title_for_url, :description
|
19
|
+
has_title_for_url
|
20
|
+
|
21
|
+
acts_as_tree :order => :position
|
22
|
+
|
23
|
+
belongs_to :content_data, :polymorphic => true, :dependent => :destroy
|
24
|
+
has_many :elements, :class_name => 'Humpyard::Element', :dependent => :destroy
|
25
|
+
|
26
|
+
validates_with Humpyard::ActiveModel::PublishRangeValidator, {:attributes => [:display_from, :display_until]}
|
27
|
+
validates_presence_of :title
|
28
|
+
|
29
|
+
def self.root_page(options = {})
|
30
|
+
if options[:force_reload]
|
31
|
+
@root_page = Humpyard::Page.select(:id).with_translated_attribute(:title_for_url, :index).first
|
32
|
+
else
|
33
|
+
@root_page ||= Humpyard::Page.select(:id).with_translated_attribute(:title_for_url, :index).first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_root_page?
|
38
|
+
self.id and Humpyard::Page.root_page and self.id == Humpyard::Page.root_page.id
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return the elements on a yield container. Includes shared elemenents from siblings or parents
|
42
|
+
#
|
43
|
+
def root_elements(yield_name = 'main')
|
44
|
+
# my own elements
|
45
|
+
ret = elements.where('container_id IS NULL and page_yield_name = ?', yield_name.to_s).order('position ASC')
|
46
|
+
# sibling shared elements
|
47
|
+
unless siblings.empty?
|
48
|
+
ret += Humpyard::Element.where('container_id IS NULL and page_id in (?) and page_yield_name = ? and shared_state = ?', siblings, yield_name.to_s, Humpyard::Element::SHARED_STATES[:shared_on_siblings]).order('position ASC')
|
49
|
+
end
|
50
|
+
# ancestors shared elements
|
51
|
+
unless ancestor_pages.empty?
|
52
|
+
ret += Humpyard::Element.where('container_id IS NULL and page_id in (?) and page_yield_name = ? and shared_state = ?', ancestor_pages, yield_name.to_s, Humpyard::Element::SHARED_STATES[:shared_on_children]).order('position ASC')
|
53
|
+
end
|
54
|
+
ret
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_path(path)
|
58
|
+
content_data.parse_path(path)
|
59
|
+
end
|
60
|
+
|
61
|
+
def template_name
|
62
|
+
self[:template_name] || Humpyard::config.default_template_name
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# Return the human readable URL for the page.
|
67
|
+
#
|
68
|
+
# Posible options values are
|
69
|
+
# <tt>:locale</tt>::
|
70
|
+
# A locale given in the Humpyard::Config.locales.
|
71
|
+
# If no <tt>:locale</tt> is given the option will be ::I18n.locale by default
|
72
|
+
def human_url(options={})
|
73
|
+
options[:locale] ||= ::I18n.locale
|
74
|
+
options[:format] ||= :html
|
75
|
+
|
76
|
+
unless Humpyard::config.locales.include? options[:locale].to_sym
|
77
|
+
options[:locale] = Humpyard::config.locales.first
|
78
|
+
end
|
79
|
+
|
80
|
+
if options[:path_format]
|
81
|
+
format = "/"
|
82
|
+
else
|
83
|
+
format = ".#{options[:format].to_s}"
|
84
|
+
end
|
85
|
+
|
86
|
+
if self.title_for_url == 'index' or self.is_root_page?
|
87
|
+
"/#{Humpyard::config.parsed_www_prefix(options).gsub(/[^\/]*$/, '')}"
|
88
|
+
else
|
89
|
+
"/#{Humpyard::config.parsed_www_prefix(options)}#{((self.ancestors.reverse + [self]).collect{|p| p.query_title_for_url(options[:locale])} - ['index']) * '/'}#{format}".gsub(/^index\//,'')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def suggested_title_for_url_with_index(locale = I18n.locale)
|
95
|
+
return 'index' if self.is_root_page? or Humpyard::Page.count == 0
|
96
|
+
suggested_title_for_url_without_index(locale)
|
97
|
+
end
|
98
|
+
alias_method_chain :suggested_title_for_url, :index
|
99
|
+
|
100
|
+
# Find the child pages
|
101
|
+
def child_pages options={}
|
102
|
+
if content_data.is_humpyard_dynamic_page?
|
103
|
+
content_data.child_pages
|
104
|
+
else
|
105
|
+
if options[:single_root] and is_root_page?
|
106
|
+
Page.where(["parent_id = ? or parent_id IS NULL and NOT id = ?", id, id])
|
107
|
+
else
|
108
|
+
children
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Get the parent page (even on dynamic pages)
|
114
|
+
def parent_page options={}
|
115
|
+
if options[:single_root]
|
116
|
+
if parent
|
117
|
+
parent
|
118
|
+
elsif is_root_page?
|
119
|
+
nil
|
120
|
+
else
|
121
|
+
Humpyard::Page.root_page
|
122
|
+
end
|
123
|
+
else
|
124
|
+
parent
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Get all ancestor pages
|
129
|
+
def ancestor_pages options={}
|
130
|
+
if parent_page
|
131
|
+
parent_page.ancestor_pages(options) + [parent_page(options)]
|
132
|
+
else
|
133
|
+
[]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Is the given page an ancestor of the actual page
|
138
|
+
def is_ancestor_page_of? page
|
139
|
+
page.ancestor_pages.include? self
|
140
|
+
end
|
141
|
+
|
142
|
+
# Return the logical modification time for the page, suitable for http caching, generational cache keys, etc.
|
143
|
+
def last_modified options = {}
|
144
|
+
changed_at = [Time.zone.at(::File.new("#{Rails.root}").mtime), created_at, updated_at, modified_at]
|
145
|
+
|
146
|
+
if(options[:include_pages])
|
147
|
+
changed_at << Humpyard::Page.select('updated_at').order('updated_at DESC').first.updated_at
|
148
|
+
end
|
149
|
+
|
150
|
+
(changed_at - [nil]).max.utc
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|