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,75 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module ActiveRecord
|
3
|
+
module Has
|
4
|
+
module TitleForUrl
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
base.before_save :assign_title_for_url
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def find_by_title_for_url(url, options = {})
|
12
|
+
options[:locale] ||= ::I18n.locale
|
13
|
+
|
14
|
+
unless Humpyard::config.locales.include? options[:locale].to_sym
|
15
|
+
options[:locale] = Humpyard::config.locales.first
|
16
|
+
end
|
17
|
+
|
18
|
+
if options[:skip_fallbacks]
|
19
|
+
locales = [options[:locale].to_sym]
|
20
|
+
else
|
21
|
+
locales = [options[:locale].to_sym] + (Humpyard::config.locales.map{|l| l.to_sym} - [options[:locale].to_sym])
|
22
|
+
end
|
23
|
+
|
24
|
+
locales.each do |l|
|
25
|
+
#t = self.with_locale(l){find_first_by_translated_attr_and_locales(:title_for_url, url)}
|
26
|
+
t = self.translation_class.where('locale = ? AND title_for_url = ?', l.to_s, url.to_s).first
|
27
|
+
|
28
|
+
if t
|
29
|
+
return self.find(t["#{self.name.underscore.gsub('/', '_')}_id"])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def query_title_for_url(locale = I18n.locale)
|
38
|
+
given = translations.all
|
39
|
+
([locale.to_sym] + (Humpyard::config.locales.map{|l| l.to_sym} - [locale.to_sym])).each do |l|
|
40
|
+
t = given.select{|tx| tx.locale.to_sym == l}.first
|
41
|
+
return t.title_for_url if t and not t.title_for_url.blank?
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def suggested_title_for_url(locale = I18n.locale)
|
47
|
+
return nil if title.blank?
|
48
|
+
|
49
|
+
title_for_url = (self.title(locale) ? self.title(locale) : self.title).parameterize('_').to_s
|
50
|
+
|
51
|
+
# Check if parameterized totally failed
|
52
|
+
if title_for_url == ''
|
53
|
+
title_for_url = CGI::escape(self.title.gsub(/[a-z0-9\-_\x00-\x7F]+/, '_'))
|
54
|
+
end
|
55
|
+
|
56
|
+
while obj = self.class.find_by_title_for_url(title_for_url, :skip_fallbacks => true, :locale => locale) and obj.id != self.id do
|
57
|
+
title_for_url += '_'
|
58
|
+
end
|
59
|
+
return title_for_url
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
def assign_title_for_url
|
64
|
+
self.title_for_url = suggested_title_for_url
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ActiveRecord::Base
|
72
|
+
def self.has_title_for_url(options = {})
|
73
|
+
include Humpyard::ActiveRecord::Has::TitleForUrl
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
require 'compass'
|
2
|
+
|
3
|
+
options = Hash.new
|
4
|
+
options[:stylesheets_directory] = ::File.expand_path(::File.join(::File.dirname(__FILE__), '..', '..', 'compass', 'stylesheets'))
|
5
|
+
options[:templates_directory] = ::File.expand_path(::File.join(File.dirname(__FILE__), '..', '..', 'compass', 'templates'))
|
6
|
+
::Compass::Frameworks.register('humpyard', options)
|
@@ -0,0 +1,235 @@
|
|
1
|
+
module Humpyard
|
2
|
+
####
|
3
|
+
# Humpyard::Config is responsible for holding and managing the configuration
|
4
|
+
# for your Humpyard Rails Application.
|
5
|
+
#
|
6
|
+
# Possible configuration options are:
|
7
|
+
# +table_name_prefix+::
|
8
|
+
# The prefix for the SQL tables
|
9
|
+
#
|
10
|
+
# The default value is <tt>"humpyard_"</tt>
|
11
|
+
# +www_prefix+::
|
12
|
+
# The prefix for the pages in your routes
|
13
|
+
#
|
14
|
+
# You may use some variables that will be replaced by
|
15
|
+
# Humpyard::Page.human_url
|
16
|
+
# <tt>":locale"</tt>:: The current ::I18n.locale
|
17
|
+
#
|
18
|
+
# Leading slashes ("/") as it would result in invalid URLs and will be ignored.
|
19
|
+
#
|
20
|
+
# A tailing slash ("/") indicates, that the value should be a path.
|
21
|
+
# Without the tailing slash the last part would become a prefix
|
22
|
+
# to the pages URL.
|
23
|
+
# A page with the path "about/config.html" with the ::I18n.locale="en"
|
24
|
+
# and the given prefix will result in:
|
25
|
+
# <tt>":locale/"</tt>:: <tt>"/en/about/config.html"</tt>
|
26
|
+
# <tt>":locale/cms_"</tt>:: <tt>"/en/cms_about_config.html"</tt>
|
27
|
+
# <tt>"cms/"</tt>:: <tt>"/cms/about/config.html"</tt>
|
28
|
+
# <tt>""</tt>: <tt>"/about/config.html"</tt>
|
29
|
+
#
|
30
|
+
# The default value is <tt>":locale/"</tt>
|
31
|
+
# +admin_prefix+::
|
32
|
+
# The prefix for the admin controllers
|
33
|
+
#
|
34
|
+
# The default value is <tt>"admin"</tt>
|
35
|
+
# +locales+::
|
36
|
+
# The locales used for the pages
|
37
|
+
#
|
38
|
+
# This option can be configured by giving an Array or comma separated String,
|
39
|
+
# e.g. <tt>'en,de,fr'</tt> or <tt>['en', 'de', 'fr']</tt>.
|
40
|
+
#
|
41
|
+
# Setting this option will also alter the HumpyardForm.config.locales to the
|
42
|
+
# given value
|
43
|
+
#
|
44
|
+
#
|
45
|
+
# The default value is <tt>['en']</tt>
|
46
|
+
class Config
|
47
|
+
attr_writer :table_name_prefix, :element_types, :page_types # :nodoc:
|
48
|
+
attr_writer :templates, :default_template, :browser_title_prefix, :browser_title_postfix # :nodoc:
|
49
|
+
attr_writer :users_framework, :js_framework, :compass_format, :compass_stylesheet_link_tag_path # :nodoc:
|
50
|
+
|
51
|
+
def initialize(&block) #:nodoc:
|
52
|
+
configure(&block) if block_given?
|
53
|
+
end
|
54
|
+
|
55
|
+
# Configure your Humpyard Rails Application with the given parameters in
|
56
|
+
# the block. For possible options see above.
|
57
|
+
def configure(&block)
|
58
|
+
yield(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def table_name_prefix #:nodoc:
|
62
|
+
@table_name_prefix ||= 'humpyard_'
|
63
|
+
end
|
64
|
+
|
65
|
+
def www_prefix #:nodoc:
|
66
|
+
@www_prefix ||= ':locale/'
|
67
|
+
end
|
68
|
+
|
69
|
+
def www_prefix=(prefix)
|
70
|
+
if prefix
|
71
|
+
@www_prefix = prefix.gsub /^\//, ''
|
72
|
+
else
|
73
|
+
@www_prefix = nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def element_types #:nodoc:
|
78
|
+
@element_types ||= {
|
79
|
+
'box_element' => Humpyard::Elements::BoxElement,
|
80
|
+
'text_element' => Humpyard::Elements::TextElement,
|
81
|
+
'media_element' => Humpyard::Elements::MediaElement,
|
82
|
+
'news_element' => Humpyard::Elements::NewsElement,
|
83
|
+
'sitemap_element' => Humpyard::Elements::SitemapElement
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def page_types #:nodoc:
|
88
|
+
@page_types ||= {
|
89
|
+
'static' => Humpyard::Pages::StaticPage,
|
90
|
+
'virtual' => Humpyard::Pages::VirtualPage,
|
91
|
+
'news' => Humpyard::Pages::NewsPage
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def asset_types #:nodoc:
|
96
|
+
@asset_types ||= {
|
97
|
+
'paperclip' => Humpyard::Assets::PaperclipAsset,
|
98
|
+
'youtube' => Humpyard::Assets::YoutubeAsset
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def templates #:nodoc:
|
103
|
+
@templates ||= {
|
104
|
+
'application' => {:yields => [:sidebar]}
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def toolbar_actions #:nodoc:
|
109
|
+
@toolbar_actions ||= {
|
110
|
+
#'edit' => {
|
111
|
+
# :title => 'humpyard_cms.toolbar.edit',
|
112
|
+
# :command => 'toggleEditMode',
|
113
|
+
# :icon => 'ui-icon-pencil'
|
114
|
+
#},
|
115
|
+
'hy_pages' => {
|
116
|
+
:title => 'humpyard_cms.toolbar.pages',
|
117
|
+
:controller => '/humpyard/pages',
|
118
|
+
:action => :index,
|
119
|
+
:dialog => "size:800x700;dialog_id:pages-dialog",
|
120
|
+
:icon => 'ui-icon-document',
|
121
|
+
:class => Humpyard::Page
|
122
|
+
},
|
123
|
+
'hy_assets' => {
|
124
|
+
:title => 'humpyard_cms.toolbar.assets',
|
125
|
+
:controller => '/humpyard/assets',
|
126
|
+
:action => :index,
|
127
|
+
:dialog => "size:800x700;dialog_id:assets-dialog",
|
128
|
+
:icon => 'ui-icon-video',
|
129
|
+
:class => Humpyard::Asset
|
130
|
+
}
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
def default_template #:nodoc:
|
135
|
+
@default_template ||= templates.keys.first
|
136
|
+
end
|
137
|
+
|
138
|
+
def default_template_name
|
139
|
+
default_template.to_s
|
140
|
+
end
|
141
|
+
|
142
|
+
def browser_title_prefix #:nodoc:
|
143
|
+
@browser_title_prefix ||= ''
|
144
|
+
end
|
145
|
+
|
146
|
+
def browser_title_postfix #:nodoc:
|
147
|
+
@browser_title_postfix ||= ''
|
148
|
+
end
|
149
|
+
|
150
|
+
# Get the prefix of your pages with interpreted variables given as params.
|
151
|
+
# You normally don't want to call it yourself. Instead use the
|
152
|
+
# Humpyard::Page.human_url which will put the current ::I18n.locale into
|
153
|
+
# the params.
|
154
|
+
def parsed_www_prefix(params)
|
155
|
+
prefix = "#{www_prefix}"
|
156
|
+
params.each do |key,value|
|
157
|
+
prefix.gsub!(":#{key}", value.to_s)
|
158
|
+
end
|
159
|
+
prefix
|
160
|
+
end
|
161
|
+
|
162
|
+
def admin_prefix #:nodoc:
|
163
|
+
@admin_prefix.blank? ? 'admin' : @admin_prefix
|
164
|
+
end
|
165
|
+
|
166
|
+
def admin_prefix=(prefix)
|
167
|
+
if prefix
|
168
|
+
@admin_prefix = prefix.gsub /^\//, ''
|
169
|
+
else
|
170
|
+
@admin_prefix = nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def locales=(locales) #:nodoc:
|
175
|
+
if locales.nil?
|
176
|
+
@locales = nil
|
177
|
+
elsif locales.class == Array
|
178
|
+
@locales = locales.map{|l| l.to_sym}
|
179
|
+
else
|
180
|
+
@locales = locales.split(',').collect{|l| l.to_sym}
|
181
|
+
end
|
182
|
+
|
183
|
+
# Keep HumpyardForm locales in sync
|
184
|
+
HumpyardForm.config.locales = locales
|
185
|
+
end
|
186
|
+
|
187
|
+
def locales #:nodoc:
|
188
|
+
@locales ||= [:en]
|
189
|
+
end
|
190
|
+
|
191
|
+
# Get the given locales as Regexp constraint.
|
192
|
+
# This may be used to see if a locale matches the configured locales.
|
193
|
+
# Usage is e.g. in the routes.
|
194
|
+
def locales_contraint
|
195
|
+
Regexp.new locales * '|'
|
196
|
+
end
|
197
|
+
|
198
|
+
def users_framework
|
199
|
+
@users_framework ||= 'simple'
|
200
|
+
end
|
201
|
+
|
202
|
+
def js_framework
|
203
|
+
@js_framework ||= 'jquery-ui-18'
|
204
|
+
end
|
205
|
+
|
206
|
+
def compass_format
|
207
|
+
@compass_format ||= 'scss'
|
208
|
+
end
|
209
|
+
|
210
|
+
def compass_stylesheet_link_tag_path
|
211
|
+
@compass_stylesheet_link_tag_path ||= 'compiled/'
|
212
|
+
end
|
213
|
+
|
214
|
+
def page_formats=(formats) #:nodoc:
|
215
|
+
if formats.nil?
|
216
|
+
@page_formats = nil
|
217
|
+
elsif formats.class == Array
|
218
|
+
@page_formats = formats.map{|l| l.to_sym}
|
219
|
+
else
|
220
|
+
@page_formats = formats.split(',').collect{|l| l.to_sym}
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def page_formats #:nodoc:
|
225
|
+
@page_formats ||= [:html]
|
226
|
+
end
|
227
|
+
|
228
|
+
# Get the given locales as Regexp constraint.
|
229
|
+
# This may be used to see if a locale matches the configured locales.
|
230
|
+
# Usage is e.g. in the routes.
|
231
|
+
def page_formats_contraint
|
232
|
+
Regexp.new page_formats * '|'
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module UriParser
|
3
|
+
class << self
|
4
|
+
def parsers
|
5
|
+
@parsers ||= [::Humpyard::UriParser::PagesUriParser, ::Humpyard::UriParser::AssetsUriParser]
|
6
|
+
end
|
7
|
+
|
8
|
+
def substitute content, options = {}
|
9
|
+
parsers.each do |parser|
|
10
|
+
content = parser.substitute content, options
|
11
|
+
end
|
12
|
+
return content
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module UriParser
|
3
|
+
class AssetsUriParser
|
4
|
+
def self.substitute content, options = {}
|
5
|
+
content.gsub(/humpyard:\/\/asset\/([0-9]*)/) do |uri|
|
6
|
+
begin
|
7
|
+
"#{options[:prefix]}#{Asset.find($1).url}#{options[:postfix]}"
|
8
|
+
rescue
|
9
|
+
''
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Humpyard
|
2
|
+
module UriParser
|
3
|
+
class PagesUriParser
|
4
|
+
def self.substitute content, options = {}
|
5
|
+
content.gsub(/humpyard:\/\/page\/([0-9]*)/) do |uri|
|
6
|
+
begin
|
7
|
+
"#{options[:prefix]}#{Page.find($1).human_url}#{options[:postfix]}"
|
8
|
+
rescue
|
9
|
+
"#{options[:prefix]}#{Page.root_page.human_url}#{options[:postfix]}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
namespace :humpyard do
|
2
|
+
namespace :db do
|
3
|
+
desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
4
|
+
task :migrate => [:environment, :prepare_namespace] do
|
5
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
6
|
+
ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../../db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
7
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
8
|
+
end
|
9
|
+
|
10
|
+
task :prepare_namespace do
|
11
|
+
require 'active_record'
|
12
|
+
puts 'prepage humpyard table_name_prefix'
|
13
|
+
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
14
|
+
|
15
|
+
class ActiveRecord::Base
|
16
|
+
self.table_name_prefix = "#{::ActiveRecord::Base.table_name_prefix}#{Humpyard::config.table_name_prefix}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :remove_namespace do
|
21
|
+
puts 'remove humpyard table_name_prefix'
|
22
|
+
|
23
|
+
class ActiveRecord::Base
|
24
|
+
self.table_name_prefix = "#{::ActiveRecord::Base.table_name_prefix[Humpyard::config.table_name_prefix.length,1000]}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :migrate do
|
29
|
+
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
|
30
|
+
task :redo => [:environment, :prepare_namespace] do
|
31
|
+
if ENV["VERSION"]
|
32
|
+
Rake::Task["humpyard:db:migrate:down"].invoke
|
33
|
+
Rake::Task["humpyard:db:migrate:up"].invoke
|
34
|
+
else
|
35
|
+
Rake::Task["humpyard:db:rollback"].invoke
|
36
|
+
Rake::Task["humpyard:db:migrate"].invoke
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Runs the "up" for a given migration VERSION.'
|
41
|
+
task :up => [:environment, :prepare_namespace] do
|
42
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
43
|
+
raise "VERSION is required" unless version
|
44
|
+
ActiveRecord::Migrator.run(:up, "#{File.dirname(__FILE__)}/../../db/migrate/", version)
|
45
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Runs the "down" for a given migration VERSION.'
|
49
|
+
task :down => [:environment, :prepare_namespace] do
|
50
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
51
|
+
raise "VERSION is required" unless version
|
52
|
+
ActiveRecord::Migrator.run(:down, "#{File.dirname(__FILE__)}/../../db/migrate/", version)
|
53
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
58
|
+
task :rollback => [:environment, :prepare_namespace] do
|
59
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
60
|
+
ActiveRecord::Migrator.rollback("#{File.dirname(__FILE__)}/../../db/migrate/", step)
|
61
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
|
65
|
+
task :forward => [:environment, :prepare_namespace] do
|
66
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
67
|
+
ActiveRecord::Migrator.forward("#{File.dirname(__FILE__)}/../../db/migrate/", step)
|
68
|
+
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Retrieves the current schema version number"
|
72
|
+
task :version => [:environment, :prepare_namespace] do
|
73
|
+
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "Raises an error if there are pending migrations"
|
77
|
+
task :abort_if_pending_migrations => [:environment, :prepare_namespace] do
|
78
|
+
if defined? ActiveRecord
|
79
|
+
pending_migrations = ActiveRecord::Migrator.new(:up, "#{File.dirname(__FILE__)}/../../db/migrate/").pending_migrations
|
80
|
+
if pending_migrations.any?
|
81
|
+
puts "You have #{pending_migrations.size} pending migrations:"
|
82
|
+
pending_migrations.each do |pending_migration|
|
83
|
+
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
84
|
+
end
|
85
|
+
abort %{Run "rake humpyard:db:migrate" to update your database then try again.}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
namespace :pages do
|
92
|
+
desc "Create root page if it does not exists"
|
93
|
+
task :create_root => [:environment] do
|
94
|
+
if Humpyard::Page.root_page
|
95
|
+
puts "There is already a root page"
|
96
|
+
else
|
97
|
+
Humpyard::Pages::StaticPage.create :title => 'index'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
task :'db:migrate' => [:'humpyard:db:migrate', :'humpyard:db:remove_namespace']
|