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/lib/humpyard.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
####
|
2
|
+
# Welcome to Humpyard
|
3
|
+
require 'cancan'
|
4
|
+
require 'humpyard_form'
|
5
|
+
|
6
|
+
module Humpyard
|
7
|
+
# This is the actual version of the Humpyard gem
|
8
|
+
VERSION = ::File.read(::File.join(::File.dirname(__FILE__), "..", "VERSION")).strip
|
9
|
+
|
10
|
+
def self.load options = {} #:nodoc:
|
11
|
+
require ::File.expand_path('../humpyard/rake_tasks', __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
# This is the path to the Humpyard gem's root directory
|
15
|
+
def base_directory
|
16
|
+
::File.expand_path(::File.join(::File.dirname(__FILE__), '..'))
|
17
|
+
end
|
18
|
+
|
19
|
+
# This is the path to the Humpyard gem's lib directory
|
20
|
+
def lib_directory
|
21
|
+
::File.expand_path(::File.join(::File.dirname(__FILE__)))
|
22
|
+
end
|
23
|
+
|
24
|
+
module_function :base_directory, :lib_directory
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# To access the actual configuration of your Humpyard, you can call this.
|
28
|
+
#
|
29
|
+
# An example would be <tt>Humpyard.config.www_prefix = 'cms/:locale/'</tt>
|
30
|
+
#
|
31
|
+
# See Humpyard::Config for configuration options.
|
32
|
+
def config
|
33
|
+
@config ||= Humpyard::Config.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def uri_parser
|
37
|
+
@uri_parser ||= Humpyard::UriParser
|
38
|
+
end
|
39
|
+
|
40
|
+
# Configure the Humpyard
|
41
|
+
# See Humpyard::Config.configure for details
|
42
|
+
def configure(&block)
|
43
|
+
config.configure(&block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
require File.expand_path('../humpyard/config', __FILE__)
|
49
|
+
require File.expand_path('../humpyard/engine', __FILE__)
|
50
|
+
require File.expand_path('../humpyard/compass', __FILE__)
|
51
|
+
require File.expand_path('../humpyard/uri_parser', __FILE__)
|
52
|
+
require File.expand_path('../humpyard/uri_parser/pages_uri_parser', __FILE__)
|
53
|
+
require File.expand_path('../humpyard/uri_parser/assets_uri_parser', __FILE__)
|
54
|
+
|
55
|
+
require 'i18n'
|
56
|
+
I18n.load_path += Dir.glob("#{File.dirname(__FILE__)}/../config/locales/*.yml")
|
57
|
+
I18n.backend.reload!
|
58
|
+
puts "=> #{I18n.t :'humpyard_cms.start', :version => Humpyard::VERSION, :raise => true}"
|
59
|
+
|
60
|
+
require File.expand_path('../humpyard/action_controller/base', __FILE__)
|
61
|
+
require File.expand_path('../humpyard/active_model/validators/publish_range', __FILE__)
|
62
|
+
require File.expand_path('../humpyard/active_model/translation', __FILE__)
|
63
|
+
require File.expand_path('../humpyard/active_model/naming', __FILE__)
|
64
|
+
require File.expand_path('../humpyard/active_record/acts/element', __FILE__)
|
65
|
+
require File.expand_path('../humpyard/active_record/acts/container_element', __FILE__)
|
66
|
+
require File.expand_path('../humpyard/active_record/acts/page', __FILE__)
|
67
|
+
require File.expand_path('../humpyard/active_record/acts/asset', __FILE__)
|
68
|
+
require File.expand_path('../humpyard/active_record/has/title_for_url', __FILE__)
|
69
|
+
|
70
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActionController #:nodoc:
|
3
|
+
module Base #:nodoc:
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.module_eval do
|
7
|
+
helper_attr :humpyard_user
|
8
|
+
helper_attr :humpyard_logout_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def humpyard_user
|
13
|
+
current_user
|
14
|
+
end
|
15
|
+
|
16
|
+
def humpyard_logout_path
|
17
|
+
"?user="
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActionController::Base.send :include, Humpyard::ActionController::Base
|
24
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveModel #:nodoc:
|
3
|
+
module Name #:nodoc:
|
4
|
+
def self.included(base)
|
5
|
+
base.alias_method_chain :human, :namespaces
|
6
|
+
end
|
7
|
+
|
8
|
+
def human_with_namespaces(options={})
|
9
|
+
# Rails orig
|
10
|
+
return @human unless @klass.respond_to?(:lookup_ancestors) &&
|
11
|
+
@klass.respond_to?(:i18n_scope)
|
12
|
+
|
13
|
+
# Namespace patch
|
14
|
+
defaults = @klass.lookup_ancestors.map do |klass|
|
15
|
+
klass.model_name.underscore.gsub('/','.').to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
# Rails orig
|
19
|
+
defaults << options.delete(:default) if options[:default]
|
20
|
+
defaults << @human
|
21
|
+
|
22
|
+
options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults
|
23
|
+
I18n.translate(defaults.shift, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveModel::Name.send :include, Humpyard::ActiveModel::Name
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_model/translation'
|
2
|
+
|
3
|
+
module ActiveModel #:nodoc:
|
4
|
+
module Translation #:nodoc:
|
5
|
+
def human_attribute_name_with_namespaces(attribute, options = {})
|
6
|
+
# Namespace patch
|
7
|
+
defaults = []
|
8
|
+
lookup_ancestors.each do |klass|
|
9
|
+
name = klass.model_name.underscore.split('/')
|
10
|
+
while name.size > 0
|
11
|
+
defaults << :"#{self.i18n_scope}.attributes.#{name * '.'}.#{attribute}"
|
12
|
+
name.pop
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Rails orig
|
17
|
+
defaults << :"attributes.#{attribute}"
|
18
|
+
defaults << options.delete(:default) if options[:default]
|
19
|
+
defaults << attribute.to_s.humanize
|
20
|
+
|
21
|
+
options.reverse_merge! :count => 1, :default => defaults
|
22
|
+
I18n.translate(defaults.shift, options)
|
23
|
+
end
|
24
|
+
alias_method_chain :human_attribute_name, :namespaces
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveModel
|
3
|
+
class PublishRangeValidator < ::ActiveModel::EachValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
if attribute == :display_from and not record.display_from.blank? and not record.display_until.blank? and record.display_until < record.display_from
|
6
|
+
record.errors.add attribute, :cannot_be_after_display_until
|
7
|
+
end
|
8
|
+
if attribute == :display_until and not record.display_until.blank? and not record.display_from.blank? and record.display_until <= record.display_from
|
9
|
+
record.errors.add attribute, :cannot_be_before_display_from
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveRecord
|
3
|
+
module Acts
|
4
|
+
module Asset
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.has_one :asset, :as => :content_data, :class_name => 'Humpyard::Asset', :autosave => true
|
8
|
+
base.validate :asset_must_be_valid
|
9
|
+
|
10
|
+
begin
|
11
|
+
all_attributes = Humpyard::Asset.column_names.map{|a| a.to_s}
|
12
|
+
rescue
|
13
|
+
# Table not migrated
|
14
|
+
all_attributes = []
|
15
|
+
end
|
16
|
+
ignored_attributes = ['id', 'created_at', 'updated_at', 'content_data_id', 'content_data_type']
|
17
|
+
attributes_to_delegate = all_attributes - ignored_attributes
|
18
|
+
attributes_to_delegate.each do |attrib|
|
19
|
+
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :asset
|
20
|
+
if attrib.match /_id$/
|
21
|
+
attrib = attrib.gsub /(_id)$/, ''
|
22
|
+
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :asset
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Humpyard::Asset.attr_accessible.each do |attr|
|
27
|
+
base.attr_accessible attr
|
28
|
+
end
|
29
|
+
|
30
|
+
base.extend ClassMethods
|
31
|
+
|
32
|
+
base.alias_method_chain :asset, :autobuild
|
33
|
+
base.alias_method_chain :column_for_attribute, :asset_column_for_attribute
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def asset_with_autobuild
|
38
|
+
asset_without_autobuild || build_asset
|
39
|
+
end
|
40
|
+
|
41
|
+
def column_for_attribute_with_asset_column_for_attribute(attr)
|
42
|
+
ret = column_for_attribute_without_asset_column_for_attribute(attr) || Humpyard::Asset.new.column_for_attribute(attr)
|
43
|
+
end
|
44
|
+
|
45
|
+
module ClassMethods
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
def asset_must_be_valid
|
51
|
+
unless asset.valid?
|
52
|
+
asset.errors.each do |attr, message|
|
53
|
+
errors.add(attr, message)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class ActiveRecord::Base
|
64
|
+
def self.acts_as_humpyard_asset(options = {})
|
65
|
+
set_table_name "#{Humpyard::config.table_name_prefix}assets_#{name.split('::').last.underscore.pluralize}" if options[:system_asset]
|
66
|
+
include Humpyard::ActiveRecord::Acts::Asset
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveRecord
|
3
|
+
module Acts
|
4
|
+
module ContainerElement
|
5
|
+
def self.included(base)
|
6
|
+
base.delegate "elements", "elements=", "elements?", :to => :element
|
7
|
+
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def is_humpyard_container_element?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActiveRecord::Base
|
22
|
+
def self.acts_as_humpyard_container_element(options = {})
|
23
|
+
acts_as_humpyard_element options
|
24
|
+
include Humpyard::ActiveRecord::Acts::ContainerElement
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveRecord
|
3
|
+
module Acts
|
4
|
+
module Element
|
5
|
+
def self.included(base)
|
6
|
+
base.has_one :element, :as => :content_data, :class_name => 'Humpyard::Element', :autosave => true
|
7
|
+
base.validate :element_must_be_valid
|
8
|
+
base.alias_method_chain :element, :autobuild
|
9
|
+
base.alias_method_chain :column_for_attribute, :element_column_for_attribute
|
10
|
+
|
11
|
+
begin
|
12
|
+
all_attributes = Humpyard::Element.column_names
|
13
|
+
rescue
|
14
|
+
# Table not migrated
|
15
|
+
all_attributes = []
|
16
|
+
end
|
17
|
+
ignored_attributes = ['id', 'created_at', 'updated_at', 'content_data_id', 'content_data_type']
|
18
|
+
attributes_to_delegate = all_attributes - ignored_attributes
|
19
|
+
attributes_to_delegate.each do |attrib|
|
20
|
+
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :element
|
21
|
+
if attrib.match /_id$/
|
22
|
+
attrib = attrib.gsub /(_id)$/, ''
|
23
|
+
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :element
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Humpyard::Element.attr_accessible.each do |attr|
|
28
|
+
base.attr_accessible attr
|
29
|
+
end
|
30
|
+
|
31
|
+
base.extend ClassMethods
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def element_with_autobuild
|
36
|
+
element_without_autobuild || build_element
|
37
|
+
end
|
38
|
+
|
39
|
+
def column_for_attribute_with_element_column_for_attribute(attr)
|
40
|
+
ret = column_for_attribute_without_element_column_for_attribute(attr) || element.column_for_attribute(attr)
|
41
|
+
end
|
42
|
+
|
43
|
+
def is_humpyard_element?
|
44
|
+
self.class.is_humpyard_element?
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_humpyard_container_element?
|
48
|
+
self.class.is_humpyard_container_element?
|
49
|
+
end
|
50
|
+
|
51
|
+
# def method_missing(meth, *args, &blk)
|
52
|
+
# element.send(meth, *args, &blk)
|
53
|
+
# rescue NoMethodError
|
54
|
+
# super
|
55
|
+
# end
|
56
|
+
|
57
|
+
module ClassMethods
|
58
|
+
def is_humpyard_element?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_humpyard_container_element?
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
module InstanceMethods
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
def element_must_be_valid
|
73
|
+
unless element.valid?
|
74
|
+
element.errors.each do |attr, message|
|
75
|
+
errors.add(attr, message)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class ActiveRecord::Base
|
85
|
+
def self.acts_as_humpyard_element(options = {})
|
86
|
+
set_table_name "#{Humpyard::config.table_name_prefix}elements_#{name.split('::').last.underscore.pluralize}" if options[:system_element]
|
87
|
+
include Humpyard::ActiveRecord::Acts::Element
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveRecord
|
3
|
+
module Acts
|
4
|
+
module Page
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.has_one :page, :as => :content_data, :class_name => 'Humpyard::Page', :autosave => true
|
8
|
+
base.validate :page_must_be_valid
|
9
|
+
|
10
|
+
begin
|
11
|
+
all_attributes = Humpyard::Page.column_names + Humpyard::Page.translated_attribute_names.map{|a| a.to_s}
|
12
|
+
rescue
|
13
|
+
# Table not migrated
|
14
|
+
all_attributes = []
|
15
|
+
end
|
16
|
+
ignored_attributes = ['id', 'created_at', 'updated_at', 'content_data_id', 'content_data_type']
|
17
|
+
attributes_to_delegate = all_attributes - ignored_attributes
|
18
|
+
attributes_to_delegate.each do |attrib|
|
19
|
+
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :page
|
20
|
+
if attrib.match /_id$/
|
21
|
+
attrib = attrib.gsub /(_id)$/, ''
|
22
|
+
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :page
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Humpyard::Page.attr_accessible.each do |attr|
|
27
|
+
base.attr_accessible attr
|
28
|
+
end
|
29
|
+
|
30
|
+
base.extend ClassMethods
|
31
|
+
|
32
|
+
base.alias_method_chain :page, :autobuild
|
33
|
+
base.alias_method_chain :column_for_attribute, :page_column_for_attribute
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def page_with_autobuild
|
38
|
+
page_without_autobuild || build_page
|
39
|
+
end
|
40
|
+
|
41
|
+
def column_for_attribute_with_page_column_for_attribute(attr)
|
42
|
+
ret = column_for_attribute_without_page_column_for_attribute(attr) || Humpyard::Page.new.column_for_attribute(attr) || Humpyard::Page.translation_class.new.column_for_attribute(attr)
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_path(path)
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def is_humpyard_page?
|
50
|
+
self.class.is_humpyard_page?
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_humpyard_dynamic_page?
|
54
|
+
self.class.is_humpyard_dynamic_page?
|
55
|
+
end
|
56
|
+
|
57
|
+
def is_humpyard_virtual_page?
|
58
|
+
self.class.is_humpyard_virtual_page?
|
59
|
+
end
|
60
|
+
|
61
|
+
# Return the logical modification time for the page, suitable for http caching, generational cache keys, etc.
|
62
|
+
def last_modified
|
63
|
+
rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
|
64
|
+
timestamps = [rails_root_mtime, self.updated_at] + self.page.elements.collect{|e| e.last_modified}
|
65
|
+
timestamps.sort.last
|
66
|
+
end
|
67
|
+
|
68
|
+
module ClassMethods
|
69
|
+
def is_humpyard_page?
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_humpyard_dynamic_page?
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
def is_humpyard_virtual_page?
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
def page_must_be_valid
|
84
|
+
unless page.valid?
|
85
|
+
page.errors.each do |attr, message|
|
86
|
+
errors.add(attr, message)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class ActiveRecord::Base
|
97
|
+
def self.acts_as_humpyard_page(options = {})
|
98
|
+
set_table_name "#{Humpyard::config.table_name_prefix}pages_#{name.split('::').last.underscore.pluralize}" if options[:system_page]
|
99
|
+
include Humpyard::ActiveRecord::Acts::Page
|
100
|
+
end
|
101
|
+
end
|