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.
Files changed (197) hide show
  1. data/Gemfile +28 -0
  2. data/README.rdoc +61 -0
  3. data/VERSION +1 -0
  4. data/app/controllers/humpyard/assets_controller.rb +123 -0
  5. data/app/controllers/humpyard/elements_controller.rb +200 -0
  6. data/app/controllers/humpyard/errors_controller.rb +8 -0
  7. data/app/controllers/humpyard/pages_controller.rb +365 -0
  8. data/app/helpers/humpyard/pages_helper.rb +19 -0
  9. data/app/models/humpyard/asset.rb +22 -0
  10. data/app/models/humpyard/assets/paperclip_asset.rb +48 -0
  11. data/app/models/humpyard/assets/youtube_asset.rb +38 -0
  12. data/app/models/humpyard/element.rb +57 -0
  13. data/app/models/humpyard/elements/box_element.rb +15 -0
  14. data/app/models/humpyard/elements/media_element.rb +13 -0
  15. data/app/models/humpyard/elements/news_element.rb +13 -0
  16. data/app/models/humpyard/elements/sitemap_element.rb +11 -0
  17. data/app/models/humpyard/elements/text_element.rb +49 -0
  18. data/app/models/humpyard/news_item.rb +42 -0
  19. data/app/models/humpyard/page.rb +153 -0
  20. data/app/models/humpyard/pages/news_page.rb +71 -0
  21. data/app/models/humpyard/pages/static_page.rb +25 -0
  22. data/app/models/humpyard/pages/virtual_page.rb +30 -0
  23. data/app/views/humpyard/assets/_edit.html.haml +15 -0
  24. data/app/views/humpyard/assets/_index.html.haml +24 -0
  25. data/app/views/humpyard/assets/_list.html.haml +4 -0
  26. data/app/views/humpyard/assets/_list_item.html.haml +1 -0
  27. data/app/views/humpyard/assets/_show.html.haml +38 -0
  28. data/app/views/humpyard/assets/_show_asset.html.haml +3 -0
  29. data/app/views/humpyard/assets/destroy.js.erb +4 -0
  30. data/app/views/humpyard/assets/paperclip_assets/_edit.html.haml +4 -0
  31. data/app/views/humpyard/assets/paperclip_assets/_info_table.html.haml +10 -0
  32. data/app/views/humpyard/assets/paperclip_assets/_show.html.haml +12 -0
  33. data/app/views/humpyard/assets/youtube_assets/_edit.html.haml +4 -0
  34. data/app/views/humpyard/assets/youtube_assets/_show.html.haml +5 -0
  35. data/app/views/humpyard/common/_head.html.haml +8 -0
  36. data/app/views/humpyard/common/_page_construct.html.haml +45 -0
  37. data/app/views/humpyard/elements/_edit.html.haml +25 -0
  38. data/app/views/humpyard/elements/_inline_edit.haml +0 -0
  39. data/app/views/humpyard/elements/_new.html.haml +1 -0
  40. data/app/views/humpyard/elements/_show.html.haml +29 -0
  41. data/app/views/humpyard/elements/_show_container.html.haml +3 -0
  42. data/app/views/humpyard/elements/_show_view.html.haml +2 -0
  43. data/app/views/humpyard/elements/box_elements/_edit.html.haml +4 -0
  44. data/app/views/humpyard/elements/box_elements/_inline_edit.html.haml +0 -0
  45. data/app/views/humpyard/elements/box_elements/_show.html.haml +5 -0
  46. data/app/views/humpyard/elements/destroy.js.erb +1 -0
  47. data/app/views/humpyard/elements/error.js.erb +1 -0
  48. data/app/views/humpyard/elements/media_elements/_edit.html.haml +7 -0
  49. data/app/views/humpyard/elements/media_elements/_show.html.haml +8 -0
  50. data/app/views/humpyard/elements/news_elements/_edit.html.haml +5 -0
  51. data/app/views/humpyard/elements/news_elements/_inline_edit.html.haml +0 -0
  52. data/app/views/humpyard/elements/news_elements/_show.html.haml +4 -0
  53. data/app/views/humpyard/elements/sitemap_elements/_edit.html.haml +5 -0
  54. data/app/views/humpyard/elements/sitemap_elements/_inline_edit.html.haml +0 -0
  55. data/app/views/humpyard/elements/sitemap_elements/_show.html.haml +3 -0
  56. data/app/views/humpyard/elements/sitemap_elements/_show_part.html.haml +12 -0
  57. data/app/views/humpyard/elements/text_elements/_edit.html.haml +4 -0
  58. data/app/views/humpyard/elements/text_elements/_inline_edit.html.haml +0 -0
  59. data/app/views/humpyard/elements/text_elements/_show.html.haml +4 -0
  60. data/app/views/humpyard/pages/_content.html.haml +2 -0
  61. data/app/views/humpyard/pages/_edit.html.haml +39 -0
  62. data/app/views/humpyard/pages/_index.html.haml +23 -0
  63. data/app/views/humpyard/pages/_show.html.haml +16 -0
  64. data/app/views/humpyard/pages/_subtree.html.haml +6 -0
  65. data/app/views/humpyard/pages/_tree.html.haml +3 -0
  66. data/app/views/humpyard/pages/destroy.js.erb +4 -0
  67. data/app/views/humpyard/pages/news_pages/_detail.html.haml +10 -0
  68. data/app/views/humpyard/pages/news_pages/_edit.html.haml +3 -0
  69. data/app/views/humpyard/pages/news_pages/_show.html.haml +5 -0
  70. data/app/views/humpyard/pages/show.html.haml +3 -0
  71. data/app/views/humpyard/pages/static_pages/_edit.html.haml +1 -0
  72. data/app/views/humpyard/pages/static_pages/_show.html.haml +1 -0
  73. data/app/views/humpyard/pages/virtual_pages/_edit.html.haml +7 -0
  74. data/app/views/humpyard/pages/virtual_pages/_show.html.haml +4 -0
  75. data/app/views/humpyard/pages/welcome.html.haml +13 -0
  76. data/compass/stylesheets/_humpyard.scss +12 -0
  77. data/compass/stylesheets/humpyard/_backend.scss +1 -0
  78. data/compass/stylesheets/humpyard/_base.scss +144 -0
  79. data/compass/stylesheets/humpyard/_ie.scss +1 -0
  80. data/compass/stylesheets/humpyard/_jquery_ui_overrides.scss +380 -0
  81. data/compass/stylesheets/humpyard/_print.scss +3 -0
  82. data/config/locales/de.yml +84 -0
  83. data/config/locales/en.yml +81 -0
  84. data/config/routes.rb +38 -0
  85. data/db/migrate/20100321134138_base.rb +60 -0
  86. data/db/migrate/20100330204700_create_box_element.rb +24 -0
  87. data/db/migrate/20100401153655_page_template.rb +11 -0
  88. data/db/migrate/20100409195732_page_types.rb +26 -0
  89. data/db/migrate/20100413230623_element_yield.rb +14 -0
  90. data/db/migrate/20100415132312_news_page.rb +48 -0
  91. data/db/migrate/20100415193423_page_i18n_name.rb +27 -0
  92. data/db/migrate/20100415213700_create_news_element.rb +12 -0
  93. data/db/migrate/20100703120000_shared_elements.rb +9 -0
  94. data/db/migrate/20101001142534_page_modified_at.rb +11 -0
  95. data/db/migrate/20101003100138_create_sitemap_elements.rb +13 -0
  96. data/db/migrate/20101003122108_create_humpyard_pages_virtual_pages.rb +11 -0
  97. data/db/migrate/20101006070503_page_cache_control.rb +9 -0
  98. data/db/migrate/20101104173743_create_media.rb +36 -0
  99. data/db/migrate/20110425230524_media_with_link.rb +9 -0
  100. data/lib/generators/humpyard.rb +114 -0
  101. data/lib/generators/humpyard/auth/auth_generator.rb +191 -0
  102. data/lib/generators/humpyard/auth/templates/authlogic/README +9 -0
  103. data/lib/generators/humpyard/auth/templates/authlogic/controllers/user_sessions_controller.rb +22 -0
  104. data/lib/generators/humpyard/auth/templates/authlogic/migration.rb +17 -0
  105. data/lib/generators/humpyard/auth/templates/authlogic/models/ability.rb +12 -0
  106. data/lib/generators/humpyard/auth/templates/authlogic/models/user.rb +7 -0
  107. data/lib/generators/humpyard/auth/templates/authlogic/models/user_session.rb +6 -0
  108. data/lib/generators/humpyard/auth/templates/authlogic/views/user_sessions/new.html.haml +12 -0
  109. data/lib/generators/humpyard/auth/templates/custom/README +8 -0
  110. data/lib/generators/humpyard/auth/templates/devise/README +14 -0
  111. data/lib/generators/humpyard/auth/templates/devise/models/ability.rb +14 -0
  112. data/lib/generators/humpyard/auth/templates/fake/README +0 -0
  113. data/lib/generators/humpyard/auth/templates/fake/models/ability.rb +12 -0
  114. data/lib/generators/humpyard/auth/templates/simple/README +16 -0
  115. data/lib/generators/humpyard/auth/templates/simple/config/humpyard_users.yml +2 -0
  116. data/lib/generators/humpyard/auth/templates/simple/controllers/user_sessions_controller.rb +39 -0
  117. data/lib/generators/humpyard/auth/templates/simple/models/ability.rb +12 -0
  118. data/lib/generators/humpyard/auth/templates/simple/views/user_sessions/new.html.haml +15 -0
  119. data/lib/generators/humpyard/element/USAGE +7 -0
  120. data/lib/generators/humpyard/element/element_generator.rb +82 -0
  121. data/lib/generators/humpyard/element/templates/_edit.html.haml +12 -0
  122. data/lib/generators/humpyard/element/templates/_inline_edit.html.haml +0 -0
  123. data/lib/generators/humpyard/element/templates/_show.html.haml +9 -0
  124. data/lib/generators/humpyard/element/templates/fixtures.yml +23 -0
  125. data/lib/generators/humpyard/element/templates/migration.rb +16 -0
  126. data/lib/generators/humpyard/element/templates/model.rb +11 -0
  127. data/lib/generators/humpyard/element/templates/tests/rspec/model.rb +7 -0
  128. data/lib/generators/humpyard/element/templates/tests/shoulda/model.rb +7 -0
  129. data/lib/generators/humpyard/element/templates/tests/test_unit/model.rb +7 -0
  130. data/lib/generators/humpyard/page/USAGE +7 -0
  131. data/lib/generators/humpyard/page/page_generator.rb +80 -0
  132. data/lib/generators/humpyard/page/templates/_edit.html.haml +7 -0
  133. data/lib/generators/humpyard/page/templates/_show.html.haml +4 -0
  134. data/lib/generators/humpyard/page/templates/fixtures.yml +23 -0
  135. data/lib/generators/humpyard/page/templates/migration.rb +16 -0
  136. data/lib/generators/humpyard/page/templates/model.rb +37 -0
  137. data/lib/generators/humpyard/page/templates/tests/rspec/model.rb +7 -0
  138. data/lib/generators/humpyard/page/templates/tests/shoulda/model.rb +7 -0
  139. data/lib/generators/humpyard/page/templates/tests/test_unit/model.rb +7 -0
  140. data/lib/generators/humpyard/skeleton/USAGE +6 -0
  141. data/lib/generators/humpyard/skeleton/skeleton_generator.rb +99 -0
  142. data/lib/generators/humpyard/skeleton/templates/compass.config +14 -0
  143. data/lib/generators/humpyard/skeleton/templates/images/ajax-loader.gif +0 -0
  144. data/lib/generators/humpyard/skeleton/templates/images/grid.png +0 -0
  145. data/lib/generators/humpyard/skeleton/templates/initializers/compass.rb +16 -0
  146. data/lib/generators/humpyard/skeleton/templates/initializers/haml.rb +3 -0
  147. data/lib/generators/humpyard/skeleton/templates/initializers/humpyard.rb +20 -0
  148. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/d.png +0 -0
  149. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/throbber.gif +0 -0
  150. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-1.5.1.js +8316 -0
  151. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-humpyard.js +790 -0
  152. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-rails.js +157 -0
  153. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-ui-1.8.10.js +11544 -0
  154. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.form-2.64.js +803 -0
  155. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.jstree.js +3510 -0
  156. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  157. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  158. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  159. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  160. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  161. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  162. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  163. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  164. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
  165. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  166. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
  167. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
  168. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  169. data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/jquery-ui-1.8.10.css +573 -0
  170. data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.sass +15 -0
  171. data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.scss +16 -0
  172. data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.sass +12 -0
  173. data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.scss +11 -0
  174. data/lib/generators/humpyard/skeleton/templates/stylesheets/print.sass +3 -0
  175. data/lib/generators/humpyard/skeleton/templates/stylesheets/print.scss +3 -0
  176. data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.sass +78 -0
  177. data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.scss +90 -0
  178. data/lib/generators/humpyard/skeleton/templates/views/layout.html.haml +28 -0
  179. data/lib/html_to_textile.rb +220 -0
  180. data/lib/humpyard.rb +70 -0
  181. data/lib/humpyard/action_controller/base.rb +24 -0
  182. data/lib/humpyard/active_model/naming.rb +29 -0
  183. data/lib/humpyard/active_model/translation.rb +26 -0
  184. data/lib/humpyard/active_model/validators/publish_range.rb +14 -0
  185. data/lib/humpyard/active_record/acts/asset.rb +68 -0
  186. data/lib/humpyard/active_record/acts/container_element.rb +26 -0
  187. data/lib/humpyard/active_record/acts/element.rb +89 -0
  188. data/lib/humpyard/active_record/acts/page.rb +101 -0
  189. data/lib/humpyard/active_record/has/title_for_url.rb +75 -0
  190. data/lib/humpyard/compass.rb +6 -0
  191. data/lib/humpyard/config.rb +235 -0
  192. data/lib/humpyard/engine.rb +7 -0
  193. data/lib/humpyard/uri_parser.rb +16 -0
  194. data/lib/humpyard/uri_parser/assets_uri_parser.rb +15 -0
  195. data/lib/humpyard/uri_parser/pages_uri_parser.rb +15 -0
  196. data/lib/tasks/humpyard.rake +103 -0
  197. 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