From dd114e2a59088d53c891028d09444d012a9e561b Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 1 Jul 2011 12:39:14 +0200 Subject: [PATCH 01/86] defining var --- assets/javascripts/preview.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/javascripts/preview.js b/assets/javascripts/preview.js index 5024a2c99e..48ab9fdddb 100644 --- a/assets/javascripts/preview.js +++ b/assets/javascripts/preview.js @@ -103,6 +103,8 @@ function initAlchemyPreviewMode() { // if (typeof(jQuery) === 'undefined') { + var thisPageUsingOtherJSLibrary = false; + if (typeof($) === 'function') { // warning, global var thisPageUsingOtherJSLibrary = true; From 55c1efcf304428bc382dc0495e8af0e160bd6f05 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 29 Jul 2011 09:58:26 +0200 Subject: [PATCH 02/86] Mentioned alchemy installer in README --- README.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8078735bdd..10ddff13a0 100644 --- a/README.md +++ b/README.md @@ -63,18 +63,18 @@ We strongly recommend Rails 2.3.10 and Ruby 1.8.7. We are working hard on a Rails 3 compatible Gem of Alchemy. Feel free to contribute :) Just fork the rails3 branch. -Install via Rails template (recommended) +Install via Installer (recommended) ---------------------------------------- -We have a fancy Rails template that does all the installation stuff for you. You can find it here: +We have a fancy installer script that does all the installation stuff for you. You can find it here: - + -Download the template and put it in a folder of your choice of your local disc. +Download the installer and put it in an executable folder (/usr/local/bin). -Then enter: +Then open a terminal goto your projects folder and enter: - rails _2.3.10_ -d mysql -m path/to/template/install_alchemy.rb YOUR_APP_NAME + alchemy new YOUR_APP_NAME After creation of the new project, follow the instructions displayed in the console. Then just switch to your browser and open http://localhost:3000/admin for creating your first admin user. @@ -87,11 +87,17 @@ Installing into an existing Rails project Tipp ---- -If you use the ferret full text search (enabled by default), then please add a job to your crontab that reindexes the ferret index. +1. This task creates all necessary folders and files needed for creating your own pagelayouts and elements for your website -Example: + rake alchemy:app_structure:create:all - cd /path/to/your/alchemy && RAILS_ENV=production rake ferret:rebuild_index > /dev/null +2. If you use the ferret full text search (enabled by default), then please add a job to your crontab that reindexes the ferret index. + + cd /path/to/your/alchemy && RAILS_ENV=production rake ferret:rebuild_index > /dev/null + +3. You can easily create your element-files (for view and editor) depending on the elements.yml with this generator + + script/generate elements Resources --------- From c3d1d3c871e621d3e200ab8215dfc8f3dea8932e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 9 Aug 2011 09:45:37 +0200 Subject: [PATCH 03/86] ignoring gem files from rails3 branch --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fdf4d4a469..26c31cbc43 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .DS_Store .svn doc/ -rdoc/ \ No newline at end of file +rdoc/ +Gemfile.lock +pkg \ No newline at end of file From 2779d10670ce0f49a15ab75419bb71414e80f75b Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 9 Aug 2011 12:53:10 +0200 Subject: [PATCH 04/86] v1.6.0 Signed-off-by: Thomas von Deyen --- VERSION | 1 - 1 file changed, 1 deletion(-) diff --git a/VERSION b/VERSION index 5e20e8c84c..0402c08f99 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,3 @@ MAJOR: 1 MINOR: 6 PATCH: 0 -BUILD: RC1 From 864680162a58535dc2f6d19b407c0f2fa2190f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20B=C3=B6ning?= Date: Thu, 15 Sep 2011 14:05:10 +0300 Subject: [PATCH 05/86] show_page_with_language_path needs language.code instead of its id --- app/views/elements/_searchresult_view.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/elements/_searchresult_view.html.erb b/app/views/elements/_searchresult_view.html.erb index c265983c46..8678cc9331 100644 --- a/app/views/elements/_searchresult_view.html.erb +++ b/app/views/elements/_searchresult_view.html.erb @@ -1,6 +1,6 @@
> - <% form_tag show_page_with_language_path(:urlname => "suche", :lang => session[:language_id]), :method => :get do %> + <% form_tag show_page_with_language_path(:urlname => "suche", :lang => @page.language_code), :method => :get do %> <%= text_field_tag "query", params[:query], :class => 'field' %> <%= submit_tag _("search"), :name => nil %> <%- end -%> From dfcbe784a598382625a2da337613da04b73785d5 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Sun, 9 Oct 2011 23:09:10 +0300 Subject: [PATCH 06/86] Edited README.md via GitHub --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 10ddff13a0..bf51a9affb 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,9 @@ Features Rails Version ------------- -We strongly recommend Rails 2.3.10 and Ruby 1.8.7. +We recommend Rails 2.3.10 and Ruby 1.8.7 for productive perpuse. -We are working hard on a Rails 3 compatible Gem of Alchemy. Feel free to contribute :) Just fork the rails3 branch. +But the Rails 3 compatible Gem of Alchemy is nearly complete and can be found at rubygems.org. Feel free to contribute :) Just fork the next_stable branch. Install via Installer (recommended) ---------------------------------------- From c4b2aaa4881a305ec2eff98469f6e3a20148a972 Mon Sep 17 00:00:00 2001 From: masche842 Date: Sun, 16 Oct 2011 15:00:56 +0800 Subject: [PATCH 07/86] updated Readme, detailed install instructions. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index dd53a7a241..894abac77c 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Installation Use the installer (recommended): + gem install alchemy_cms alchemy new my_magicpage Start the local server: @@ -76,6 +77,16 @@ Start the local server: Then just switch to your browser and open `http://localhost:3000`. +Add to existing Rails project: + + add gem 'alchemy_cms' to Gemfile + + bundle install + rake alchemy:prepare + rake alchemy:standard_set:install (optional) + rake db:migrate + + Tipps ----- From 1e17be3c79800f27190788f32a473f9398d69e7e Mon Sep 17 00:00:00 2001 From: masche842 Date: Sun, 16 Oct 2011 23:30:01 +0800 Subject: [PATCH 08/86] helper for language-menu improved; bug (.html_safe for array) fixed --- .idea/alchemy_cms.iml | 82 +++++++++++++++++++++++++++++++++++++ .idea/encodings.xml | 5 +++ .idea/misc.xml | 8 ++++ .idea/modules.xml | 9 ++++ .idea/vcs.xml | 7 ++++ app/helpers/pages_helper.rb | 6 +-- 6 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 .idea/alchemy_cms.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/alchemy_cms.iml b/.idea/alchemy_cms.iml new file mode 100644 index 0000000000..4cf4316836 --- /dev/null +++ b/.idea/alchemy_cms.iml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000..e206d70d85 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..92d9b158e5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..efd26a166a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..c80f2198b5 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 9cfcdab33b..712aed3708 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -119,11 +119,7 @@ def language_switches(options={}) :onchange => "window.location=this.value" ) else - if options[:spacer].blank? - return languages.html_safe - else - return languages.join(options[:spacer]).html_safe - end + raw(languages.join) end end end From 14c8922621a63443182228b1c3ea586275c60702 Mon Sep 17 00:00:00 2001 From: masche842 Date: Sun, 16 Oct 2011 23:30:01 +0800 Subject: [PATCH 09/86] helper for language-menu improved; bug (.html_safe for array) fixed --- .idea/misc.xml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 92d9b158e5..0000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - From 1e075c1977cf5340eb9409d51307dd5bd3378879 Mon Sep 17 00:00:00 2001 From: masche842 Date: Mon, 17 Oct 2011 10:26:03 +0800 Subject: [PATCH 10/86] added idea to gitignore in order to exclude rubymines temp files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b23fa9e4a6..0df696ddc6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea .yardoc .DS_Store .svn From a3d24dbff172e7fb184afab125741e9597fba737 Mon Sep 17 00:00:00 2001 From: masche842 Date: Mon, 17 Oct 2011 11:37:27 +0800 Subject: [PATCH 11/86] fixed bug in pages_helper, spec-sceleton --- app/helpers/pages_helper.rb | 14 +++++++------- spec/helpers/pages_helper_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 spec/helpers/pages_helper_spec.rb diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 712aed3708..6c39638c55 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -84,7 +84,7 @@ def language_switches(options={}) } options = default_options.merge(options) if multi_language? - languages = [] + language_links = [] pages = (options[:link_to_public_child] == true) ? Page.language_roots : Page.public_language_roots pages.each_with_index do |page, i| if(options[:link_to_page_with_layout] != nil) @@ -97,29 +97,29 @@ def language_switches(options={}) active = session[:language_id] == page.language.id linkname = page.language.label(options[:linkname]) if options[:as_select_box] - languages << [linkname, show_page_url(:urlname => page.urlname, :lang => page.language.code)] + language_links << [linkname, show_page_url(:urlname => page.urlname, :lang => page.language.code)] else - languages << link_to( + language_links << link_to( "#{content_tag(:span, '', :class => "flag")}#{ content_tag(:span, linkname)}".html_safe, show_page_path(:urlname => page.urlname, :lang => page.language.code), :class => "#{(active ? 'active ' : nil)}#{page.language.code} #{(i == 0) ? 'first' : (i==pages.length-1) ? 'last' : nil}", - :title => options[:show_title] ? I18n.t("alchemy.languages.#{page.language.code}.title", :default => page.language.name) : nil + :title => options[:show_title] ? I18n.t("alchemy.language_links.#{page.language.code}.title", :default => page.language.name) : nil ) end end end - languages.reverse! if options[:reverse] + language_links.reverse! if options[:reverse] if options[:as_select_box] return select_tag( 'language', options_for_select( - languages, + language_links, show_page_url(:urlname => @page.urlname, :lang => @page.language.code) ), :onchange => "window.location=this.value" ) else - raw(languages.join) + raw(language_links.join(options[:spacer])) end end end diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb new file mode 100644 index 0000000000..30843a3d9b --- /dev/null +++ b/spec/helpers/pages_helper_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe PagesHelper do + + describe "language_switches" do + before :each do + helper.stub(:configuration) + end + + it "should return links to all other languages" do + helper.stub(:multi_language?).and_return(true) + Page.create(:language_code => "en", :public => true) + Page.create(:language_code => "de") + ss + helper.language_switches.should == "" + end + + it "should return nil if there is only one language" do + helper.stub(:multi_language?).and_return(nil) + helper.language_switches.should be nil + end + end +end \ No newline at end of file From 1295f8f732a7ac42cc1c4a868a41bc6d3b74dc66 Mon Sep 17 00:00:00 2001 From: masche842 Date: Mon, 17 Oct 2011 11:42:33 +0800 Subject: [PATCH 12/86] some corrections in readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 894abac77c..1b3b730b91 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Installation Use the installer (recommended): - gem install alchemy_cms + gem install alchemy_cms --pre alchemy new my_magicpage Start the local server: @@ -85,6 +85,7 @@ Add to existing Rails project: rake alchemy:prepare rake alchemy:standard_set:install (optional) rake db:migrate + rake db:seed Tipps From e249c4476d0dacd115753dfcbbac26a0fb1de7c8 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 13:32:00 +0200 Subject: [PATCH 13/86] Moved render_element helper into pages_helper. Refs #70 --- app/helpers/alchemy_helper.rb | 51 ------------------------------- app/helpers/pages_helper.rb | 51 +++++++++++++++++++++++++++++++ spec/helpers/pages_helper_spec.rb | 17 +++++++++++ 3 files changed, 68 insertions(+), 51 deletions(-) create mode 100644 spec/helpers/pages_helper_spec.rb diff --git a/app/helpers/alchemy_helper.rb b/app/helpers/alchemy_helper.rb index a69076f14f..3a381a8e78 100644 --- a/app/helpers/alchemy_helper.rb +++ b/app/helpers/alchemy_helper.rb @@ -1,14 +1,3 @@ -# All methods (helpers) in this helper are used by Alchemy to render elements, contents and layouts on the Page. -# -# TODO: list all important infos here. -# -# Most Important Infos: -# --- -# -# 1. The most important helpers for webdevelopers are the render_navigation(), render_elements() and the render_page_layout() helpers. -# 2. The currently displayed page can be accessed via the @page variable. -# 3. All important meta data from @page will be rendered via the render_meta_data() helper. - module AlchemyHelper include FastGettext::Translation @@ -94,46 +83,6 @@ def render_elements(options = {}) end end - # This helper renders the Element partial for either the view or the editor part. - # Generate element partials with ./script/generate elements - def render_element(element, part = :view, options = {}, i = 1) - begin - if element.blank? - warning('Element is nil') - render :partial => "elements/#{part}_not_found", :locals => {:name => 'nil'} - else - default_options = { - :shorten_to => nil, - :render_format => "html" - } - options = default_options.merge(options) - element.store_page(@page) if part == :view - path1 = "#{Rails.root}/app/views/elements/" - path2 = "#{Rails.root}/vendor/plugins/alchemy/app/views/elements/" - partial_name = "_#{element.name.underscore}_#{part}.html.erb" - locals = options.delete(:locals) - render( - :partial => "elements/#{element.name.underscore}_#{part}.#{options[:render_format]}.erb", - :locals => { - :element => element, - :options => options, - :counter => i - }.merge(locals || {}) - ) - end - rescue ActionView::MissingTemplate - warning(%( - Element #{part} partial not found for #{element.name}.\n - Looking for #{partial_name}, but not found - neither in #{path1} - nor in #{path2} - Use rails generate alchemy:elements to generate them. - Maybe you still have old style partial names? (like .rhtml). Then please rename them in .html.erb' - )) - render :partial => "elements/#{part}_not_found", :locals => {:name => element.name, :error => "Element #{part} partial not found. Use rails generate alchemy:elements to generate them."} - end - end - # Renders the Content partial that is given (:editor, or :view). # You can pass several options that are used by the different contents. # diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 9cfcdab33b..31e8c61b01 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -1,5 +1,56 @@ +# All methods (helpers) in this helper are used by Alchemy to render elements, contents and layouts on the Page. +# +# TODO: list all important infos here. +# +# Most Important Infos: +# --- +# +# 1. The most important helpers for webdevelopers are the render_navigation(), render_elements() and the render_page_layout() helpers. +# 2. The currently displayed page can be accessed via the @page variable. +# 3. All important meta data from @page will be rendered via the render_meta_data() helper. + module PagesHelper + # This helper renders the Element partial for either the view or the editor part. + # Generate element partials with ./script/generate elements + def render_element(element, part = :view, options = {}, i = 1) + begin + if element.blank? + warning('Element is nil') + render :partial => "elements/#{part}_not_found", :locals => {:name => 'nil'} + else + default_options = { + :shorten_to => nil, + :render_format => "html" + } + options = default_options.merge(options) + element.store_page(@page) if part == :view + path1 = "#{Rails.root}/app/views/elements/" + path2 = "#{Rails.root}/vendor/plugins/alchemy/app/views/elements/" + partial_name = "_#{element.name.underscore}_#{part}.html.erb" + locals = options.delete(:locals) + render( + :partial => "elements/#{element.name.underscore}_#{part}.#{options[:render_format]}.erb", + :locals => { + :element => element, + :options => options, + :counter => i + }.merge(locals || {}) + ) + end + rescue ActionView::MissingTemplate + warning(%( + Element #{part} partial not found for #{element.name}.\n + Looking for #{partial_name}, but not found + neither in #{path1} + nor in #{path2} + Use rails generate alchemy:elements to generate them. + Maybe you still have old style partial names? (like .rhtml). Then please rename them in .html.erb' + )) + render :partial => "elements/#{part}_not_found", :locals => {:name => element.name, :error => "Element #{part} partial not found. Use rails generate alchemy:elements to generate them."} + end + end + # DEPRICATED! Use Element.preview_text instead. def get_preview_text element element.preview_text diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb new file mode 100644 index 0000000000..f57c5cafbf --- /dev/null +++ b/spec/helpers/pages_helper_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe PagesHelper do + + context "rendering elements" do + + before(:each) do + @element = Factory(:element) + end + + it "should render an element view partial" do + render_element(@element) + end + + end + +end From 016241be31a421e67d22dbcb733f1381a42ebb16 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 13:33:03 +0200 Subject: [PATCH 14/86] Symlink to alchemy config files in dummy app --- spec/dummy/config/alchemy | 1 + spec/dummy/config/alchemy/config.yml | 199 --------------------- spec/dummy/config/alchemy/elements.yml | 91 ---------- spec/dummy/config/alchemy/page_layouts.yml | 29 --- 4 files changed, 1 insertion(+), 319 deletions(-) create mode 120000 spec/dummy/config/alchemy delete mode 100644 spec/dummy/config/alchemy/config.yml delete mode 100644 spec/dummy/config/alchemy/elements.yml delete mode 100644 spec/dummy/config/alchemy/page_layouts.yml diff --git a/spec/dummy/config/alchemy b/spec/dummy/config/alchemy new file mode 120000 index 0000000000..be4ef2f191 --- /dev/null +++ b/spec/dummy/config/alchemy @@ -0,0 +1 @@ +../../../config/alchemy \ No newline at end of file diff --git a/spec/dummy/config/alchemy/config.yml b/spec/dummy/config/alchemy/config.yml deleted file mode 100644 index c74dab14e5..0000000000 --- a/spec/dummy/config/alchemy/config.yml +++ /dev/null @@ -1,199 +0,0 @@ -# = Configuration -# -# == This is the global Alchemy configuration file -# Please override your apps settings in your config/alchemy/config.yml file. -# You can use a handy rake task to generate it. -# -# rake alchemy:app_structure:create:config - -# The amount of time of inactivity in minutes after which the user is kicked out of his current session. -# Only active in production environment!!! -:auto_logout_time: 30 - -# === Redirect options -# redirect_index: You can set to redirect (an 301 permanent, for all you SEO geeks ^_^) to first child page (typically the homepage) the index/intro page if it's not visible. -# So you don't get an 404 error if the language root page is not visible. -# redirect_to_public_child: Alchemy redirects to the first public child page found, if a page is not visible. -:redirect_index: true -:redirect_to_public_child: true - -# Enabling the Ferret fulltext search engine. -# Tip! For best performance and stability install a crontab that reindexes ferrets search index periodly. -# Example: cd ~/html/alchemy/current && RAILS_ENV=production rake ferret:rebuild_index -:ferret: false - -# === Pagecaching -# Enable/Disable pagecaching globally. -# Hint: You can enable/disable page caching for single Alchemy::PageLayouts in the page_layout.yml file. -:cache_pages: true - -# === Sitemap -# Alchemy renders a nice HTML (
  • style) and XML (Google conform!) Sitemap for you. -# Just place a sitemap element for a page layout in your page_layouts.yml file. Alchemy does the rest. -# ==== Options: -# show_root: Show language root page in sitemap? -# show_flag: enables the Checkbox in Page#update overlay. So your customer can set the visibilit of pages in the sitemap. -:sitemap: - :show_root: true - :show_flag: false - -# === Picture rendering settings -# Alchemy uses Fleximage and RMagick to render images. Use {:image_size => "XXXxYYY", :crop => BOOLEAN [true]} to resize images. -# See https://github.com/Squeegy/fleximage for further infos. -# ==== Options: -# output_image_jpg_quality: If rendered as JPG this is the quality setting for it. -# preprocess_image_resize: Large images are downsized after upload to save diskspace. -# image_store_format: Masterimage storage format. Images are rendered from this master image, so a lossless format (png) is strongly recommended. -# image_output_format: Globally image output format setting. -# TIP: You can always override the output format in the options of your Essence. I.e. {:format => :gif} -:output_image_jpg_quality: 85 -:preprocess_image_resize: 1000x1000 -:image_store_format: png -:image_output_format: jpg - -# Set available translations for your customers. -# Currently available translations are German and English. -:translations: - - :language_code: de - :language: Deutsch - - :language_code: en - :language: English - -default_translation: en - -# Default language for your homepgae. -default_language: - code: en - name: English - page_layout: intro - frontpage_name: Intro - -# === Mailer Settings: -# -# To send Mails via contact forms you can create your form fields here and set which fields are to be validated. -# -# ==== Options: -# -# fields: An Array from Hashes with fieldname as keys and type as values. Types are ActiveRecord column types (i.e. string, text, boolean, etc.). -# validate_fields: A Hash with fieldname as key and a Hash (with :message as key and a message_id as value) as value -# -# ==== Translating validation messages: -# -# The message_id is passed through I18n.t so you can translate it in your language yml file. -# -# Example: -# -# de: -# alchemy: -# contactform: -# validations: -# enter_name: 'Bitte geben Sie einen Namen an' -# -:mailer: - :page_layout_name: contact - :forward_to_page: false - :mail_success_page: thanks - :fields: [salutation, firstname, lastname, address, zip, city, phone, email, message] - :validate_fields: - :lastname: - :message: enter_name - :email: - :message: enter_mail - -# === User roles -# You can add own user roles. To set permissions for this roles please add an authorization_rules.rb file in your config folder. -# Further documentation for the auth system used please visit: -# https://github.com/stffn/declarative_authorization/blob/master/README.rdoc -# -# ==== Translating Userroles -# Userroles can be translated inside your the language yml file under: -# alchemy: -# user_roles: -# rolename: Name of the role -:user_roles: [registered, author, editor, admin] - -# === Uploader Settings -# Allow filetypes to upload. -# Pass * to allow all kind of files. -:uploader: - :allowed_filetypes: - :pictures: [jpg, jpeg, gif, png, psd, pdf] - :attachments: [*] - -# === Link Target Options -# Values for the link target selectbox inside the page link overlay. -# The value gets attached as a data-link-target attribute to the link. -# -# == Example: -# Open all links set to overlay inside an jQuery UI Dialog Window. -# -# jQuery(a[data-link-target="overlay"]).dialog(); -:link_target_options: [blank] - -# == Alchemy core plugins configuration - -alchemy_plugins: - - - name: dashboard - navigation: - name: 'home' - controller: 'admin' - action: index - icon: home - sub_navigation: - - name: 'home' - controller: 'admin' - action: index - - - name: pages - navigation: - name: 'module: pages' - controller: 'admin/pages' - action: index - icon: pages - sub_navigation: - - name: 'module: pages' - controller: 'admin/pages' - action: index - - name: 'module: layoutpages' - controller: 'admin/layoutpages' - action: index - nested: - - controller: 'admin/pages' - action: edit - - - name: languages - navigation: - name: 'module: languages' - controller: 'admin/languages' - action: index - icon: languages - sub_navigation: - - name: 'module: languages' - controller: 'admin/languages' - action: index - - - name: users - navigation: - name: 'module: users' - controller: 'admin/users' - action: index - icon: users - sub_navigation: - - name: 'module: users' - controller: 'admin/users' - action: index - - - name: archive - navigation: - controller: 'admin/pictures' - action: index - name: 'module: library' - icon: library - sub_navigation: - - name: 'module: pictures' - controller: 'admin/pictures' - action: index - - name: 'module: attachments' - controller: 'admin/attachments' - action: index diff --git a/spec/dummy/config/alchemy/elements.yml b/spec/dummy/config/alchemy/elements.yml deleted file mode 100644 index d521204de6..0000000000 --- a/spec/dummy/config/alchemy/elements.yml +++ /dev/null @@ -1,91 +0,0 @@ -# == In this configuration you setup Alchemy´s element layouts. -# -# Use rails generate alchemy:scaffold to generate this file for your app. -# -# Elements containing all necessary basic tools for displaying and editing content inside Alchemy. -# They consists of composed contents (different essence-types) as shown in the illustration of an elements-sheme below. -# -# == Schema of an element -# -# ================================= -# # Content 1 (EssenceText) # -# # # -# # Content 2 (EssencePicture) # -# # # -# # Content 3 (EssenceRichtext) # -# ================================= -# -# == Example of a basic element layout -# -# - name: a_unique_name (Used for the partial name in +app/views/elements+ and translated as Element.display_name) -# unique: Bool //pass true if this element only can be displayed once on page -# contents: -# - name: head -# type: EssenceText -# - name: text -# type: EssenceRichtext -# -# As already mentioned above, there are different content-types wich can be defined for each content in an element. -# Defining these types is used to render predefined views in the element. -# -# == Content-Types: -# -# * EssenceText (Used to store a String (max. 255 Chars.) i.e. a headline, or productname. The editor is renderd as a single-lined input field. The view output will be sanitized and escaped. So it's XSS save.) -# * EssenceRichtext (Used to store editable richtext. Editor is rendered as a textarea with TinyMCE Editor.) -# * EssencePicture (Used to store picture ids from pictures assigned through the library. The editor is rendered as a picture-editor collection with a lot of options (i.e. image cropper). The view renders the assigned picture, resizes it, crops it and caches the result.) -# * EssenceFlash (Used to store attachment ids from attachments assigned through the library. The view renders an embeded object.) -# * EssenceDate (Used to store a DateTime object. The view output is passed through Rails I18n Library, so it will be fully localized.) -# * EssenceHtml (Used to store a String (max. 255 Chars.). The view output renders the raw, not sanitized or unescaped String. So be carefull!) -# -# After finishing the setup of your element layouts, you need to generate the files for the elements before using them in Alchemy. -# For creating these files, use the following command in your terminal: -# -# rails generate elements -# -# All new elements will be created as two different partials in Rails.root/app/views/elements. -# For each element there is an editor-view wich will be rendered when editing them in Alchemy and another view for the website´s frontend. -# -# app/views/elements/_elements_name_editor.html.erb -# app/views/elements/_elements_name_view.html.erb -# -# For most contents in an element you can specify additional options, so they get rendered in a specific way. -# These options can be defined as symbols, but its too much to list them up here. -# You can find these options described in the application_helper.rb, most of them at the render_essence method. -# -# == Setting a content as preview-text for the element -# -# You can set a content-essence as preview-text for its element like this -# take_me_for_preview: true -# -# -# == Adding contents dynamically in the frontend -# -# You are able to add content-essences dynamically to the element from the Alchemy frontend. -# You just have to make contents available for adding them. -# This example enables this feature -# -# - name: headline -# unique: false -# contents: -# - name: headline -# type: EssenceText -# - name: big_text -# type: EssenceRichtext -# available_contents: -# - name: big_text -# type: EssenceRichtext -# -# Now an Alchemy user can add the content 'big_text' from the element as much as desired. -# -# === Translate element names -# -# Element names are passed through the I18n library. So you can translate them in your config/locales language yml file. -# -# Example: -# -# de: -# alchemy: -# element_names: -# contact: Kontakt -# search: Suche - diff --git a/spec/dummy/config/alchemy/page_layouts.yml b/spec/dummy/config/alchemy/page_layouts.yml deleted file mode 100644 index 308c1f9af0..0000000000 --- a/spec/dummy/config/alchemy/page_layouts.yml +++ /dev/null @@ -1,29 +0,0 @@ -# == This file defines the page_layouts for new pages. -# -# Please make your own page_layouts for your app in your own Rails.root/config/alchemy/page_layouts.yml file. -# -# === DSL: -# - name: String # The name of the layout used for views and inside the database. You can render a layout with the render_page_layout(name) helper. -# unique: Bool # Pass true and the user can only choose this layout once inside a language tree. -# hide: Bool # Pass true to hide this layout from the user. -# elements: Array # A list of element names that can be placed on this layout i.e. [text, picture]. Elements are defined inside the elements.yml file. -# autogenerate: Array # A list of element names that are autogenerated after creating the Page. -# layoutpage: Bool # Layoutpages are outside the normal pagetree and can be used to place "global" language independent Elements. -# cache: Bool # Pass false to disable the caching for this pages. -# feed: Bool # Pass true to enable a RSS feed of news elements from this page. -# redirects_to_external: Bool # Pass true to disable normal page rendering and redirect to a external page instead. -# controller: controller_name # Controller to use instead of the default PagesController -# action: action_name # Controllers action to use instead of the default PagesController#show -# -# === Translate page layout names -# -# Page layout names are passed through the I18n library. So you can translate them in your config/locales language yml file. -# -# Example: -# -# de: -# alchemy: -# page_layout_names: -# contact: Kontakt -# search: Suche -# From e64f203929c39d02bc7422c6637a937022a4fb3c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 13:50:07 +0200 Subject: [PATCH 15/86] Removing symlink to alchemy config in dummy app and fixes specs --- app/models/element.rb | 27 ++++++++++++++-------- spec/dummy/config/alchemy | 1 - spec/dummy/config/alchemy/page_layouts.yml | 2 ++ spec/element_spec.rb | 9 ++++++-- spec/page_layout_spec.rb | 9 ++++---- 5 files changed, 30 insertions(+), 18 deletions(-) delete mode 120000 spec/dummy/config/alchemy create mode 100644 spec/dummy/config/alchemy/page_layouts.yml diff --git a/app/models/element.rb b/app/models/element.rb index 9719eae1b1..14c844fb8b 100644 --- a/app/models/element.rb +++ b/app/models/element.rb @@ -104,14 +104,23 @@ def self.paste_from_clipboard(page_id, element, method, position) copy end + # Returns the descriptions from elements.yml file. + # Alchemy comes with its own elements.yml file. As so called standard set. + # Place a elements.yml file inside your apps config/alchemy folder to define + # your own set of elements def self.descriptions if File.exists? "#{Rails.root}/config/alchemy/elements.yml" - @elements = YAML.load_file( "#{Rails.root}/config/alchemy/elements.yml" ) - elsif File.exists? "#{Rails.root}/vendor/plugins/alchemy/config/alchemy/elements.yml" - @elements = YAML.load_file( "#{Rails.root}/vendor/plugins/alchemy/config/alchemy/elements.yml" ) - else - raise "Could not read config/alchemy/elements.yml" - end + element_definitions = YAML.load_file( "#{Rails.root}/config/alchemy/elements.yml" ) + end + if !element_definitions + if File.exists?(File.join(File.dirname(__FILE__), "../../config/alchemy/elements.yml")) + element_definitions = YAML.load_file( File.join(File.dirname(__FILE__), "../../config/alchemy/elements.yml") ) + end + end + if !element_definitions + raise LoadError, "Could not find elements.yml file! Please run: rails generate alchemy:scaffold" + end + element_definitions end def self.definitions @@ -148,7 +157,6 @@ def available_content_description_for(content_name) # returns the description of the element with my name in element.yml def description - return nil if Element.descriptions.blank? Element.descriptions.detect{ |d| d['name'] == self.name } end @@ -397,7 +405,7 @@ def self.all_definitions_for(element_names) return definitions.select { |e| element_names.include? e['name'] } end end - + # makes a copy of source and makes copies of the contents from source def self.copy(source, differences = {}) attributes = source.attributes.except("id").merge(differences) @@ -411,9 +419,8 @@ def self.copy(source, differences = {}) # creates the contents for this element as described in the elements.yml def create_contents - element_scratch = description contents = [] - if element_scratch["contents"].blank? + if description["contents"].blank? logger.warn "\n++++++\nWARNING! Could not find any content descriptions for element: #{self.name}\n++++++++\n" else element_scratch["contents"].each do |content_hash| diff --git a/spec/dummy/config/alchemy b/spec/dummy/config/alchemy deleted file mode 120000 index be4ef2f191..0000000000 --- a/spec/dummy/config/alchemy +++ /dev/null @@ -1 +0,0 @@ -../../../config/alchemy \ No newline at end of file diff --git a/spec/dummy/config/alchemy/page_layouts.yml b/spec/dummy/config/alchemy/page_layouts.yml new file mode 100644 index 0000000000..c6b93212e2 --- /dev/null +++ b/spec/dummy/config/alchemy/page_layouts.yml @@ -0,0 +1,2 @@ +- name: testlayout + elements: diff --git a/spec/element_spec.rb b/spec/element_spec.rb index c531511f1f..4cb2241da7 100644 --- a/spec/element_spec.rb +++ b/spec/element_spec.rb @@ -3,10 +3,9 @@ describe Element do it "should return a list of element definitions for a list of element names" do - pending "because YAML is different in test environment. Great Rails!!!!" element_names = ["article"] definitions = Element.all_definitions_for(element_names) - definitions.should == [{:name => 'article'}] + definitions.first.fetch("name").should == 'article' end it "should always return an array calling all_definitions_for()" do @@ -14,4 +13,10 @@ definitions.should == [] end + it "should raise an error if no descriptions are found" do + FileUtils.mv(File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml'), File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml.bak')) + expect { Element.descriptions }.should raise_error + FileUtils.mv(File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml.bak'), File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml')) + end + end diff --git a/spec/page_layout_spec.rb b/spec/page_layout_spec.rb index aa0b56a0d2..364aa4d3c5 100644 --- a/spec/page_layout_spec.rb +++ b/spec/page_layout_spec.rb @@ -8,14 +8,13 @@ end it "should return the users page_layouts if exists in the application" do - layouts_file_path = "#{Rails.root}/config/alchemy/page_layouts.yml" - FileUtils.cp(layouts_file_path, "#{layouts_file_path}.bak") - File.open(layouts_file_path,'w') do |page_layouts| + config_path = FileUtils.mkdir_p("#{Rails.root}/config/alchemy") + layouts_file = File.join(config_path, 'page_layouts.yml') + File.open(layouts_file,'w') do |page_layouts| page_layouts.puts "- name: testlayout\n elements:" end Alchemy::PageLayout.get_layouts.first.values.should include("testlayout") - FileUtils.rm(layouts_file_path) - FileUtils.mv("#{layouts_file_path}.bak", layouts_file_path) + FileUtils.rm_f(config_path) end end From 257cf768c45053e4ddb831d77f052507b1571f11 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 14:59:34 +0200 Subject: [PATCH 16/86] Fixes method call to get element#description --- app/models/element.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/element.rb b/app/models/element.rb index 14c844fb8b..3e149d7b7f 100644 --- a/app/models/element.rb +++ b/app/models/element.rb @@ -423,7 +423,7 @@ def create_contents if description["contents"].blank? logger.warn "\n++++++\nWARNING! Could not find any content descriptions for element: #{self.name}\n++++++++\n" else - element_scratch["contents"].each do |content_hash| + description["contents"].each do |content_hash| contents << Content.create_from_scratch(self, content_hash.symbolize_keys) end end From 3e517ac676f53a0ac61b149628f3b0f9420cc86e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 15:04:41 +0200 Subject: [PATCH 17/86] Removed .idea folder --- .idea/alchemy_cms.iml | 82 ------------------------------------------- .idea/encodings.xml | 5 --- .idea/modules.xml | 9 ----- .idea/vcs.xml | 7 ---- 4 files changed, 103 deletions(-) delete mode 100644 .idea/alchemy_cms.iml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/alchemy_cms.iml b/.idea/alchemy_cms.iml deleted file mode 100644 index 4cf4316836..0000000000 --- a/.idea/alchemy_cms.iml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index e206d70d85..0000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index efd26a166a..0000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index c80f2198b5..0000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - From 28db93f272fdf23f3f27e3c7ab741f0a7eb322c6 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 16:15:25 +0300 Subject: [PATCH 18/86] removed typo in pages_helper_spec coming with last merge --- spec/helpers/pages_helper_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 30843a3d9b..263b6162c9 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -11,7 +11,6 @@ helper.stub(:multi_language?).and_return(true) Page.create(:language_code => "en", :public => true) Page.create(:language_code => "de") - ss helper.language_switches.should == "" end From d9e636c599dfba3027bb7e3364b59599f4e746e0 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 15:24:54 +0200 Subject: [PATCH 19/86] Return true if element#store_page gets nil object --- app/models/element.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/element.rb b/app/models/element.rb index 3e149d7b7f..2263ec5181 100644 --- a/app/models/element.rb +++ b/app/models/element.rb @@ -38,13 +38,15 @@ def prev(name = nil) self.class.where(find_conditions).order("position DESC").limit(1) end - def store_page page + # Stores the page into `to_be_sweeped_pages` (Pages that have to be sweeped after updating element). + def store_page(page) + return true if page.nil? unless self.to_be_sweeped_pages.include? page self.to_be_sweeped_pages << page self.save end end - + # nullifies the page_id aka. trashs it. def trash self.page_id = nil From bb32c0ffe40fe9bf63529485fce5d807dbf54bec Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 15:25:43 +0200 Subject: [PATCH 20/86] Removes deprecated `get_preview_text` helper --- app/helpers/pages_helper.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 73fbd14d7e..9a293b5584 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -51,11 +51,6 @@ def render_element(element, part = :view, options = {}, i = 1) end end - # DEPRICATED! Use Element.preview_text instead. - def get_preview_text element - element.preview_text - end - def render_classes classes=[] s = classes.uniq.delete_if{|x| x == nil || x.blank?}.join(" ") s.blank? ? "" : "class='#{s}'" From b8e5dd74ca81fd692196d919ae1d3d05b526710f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 15:39:37 +0200 Subject: [PATCH 21/86] Moves two more helper methods into pages_helper --- app/helpers/alchemy_helper.rb | 11 ----------- app/helpers/pages_helper.rb | 12 ++++++++++++ spec/helpers/pages_helper_spec.rb | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/helpers/alchemy_helper.rb b/app/helpers/alchemy_helper.rb index 3a381a8e78..bcfd131f6e 100644 --- a/app/helpers/alchemy_helper.rb +++ b/app/helpers/alchemy_helper.rb @@ -951,12 +951,6 @@ def generate_preview_url(target_url) ) end - # Returns a string for the id attribute of a html element for the given element - def element_dom_id(element) - return "" if element.nil? - "#{element.name}_#{element.id}" - end - # Returns a string for the id attribute of a html element for the given content def content_dom_id(content) return "" if content.nil? @@ -1040,11 +1034,6 @@ def render_icon(icon_class) def alchemy_preview_mode_code javascript_include_tag("alchemy/alchemy.preview") if @preview_mode end - - # Renders the data-alchemy-element HTML attribut used for the preview window hover effect. - def element_preview_code(element) - " data-alchemy-element='#{element.id}'" if @preview_mode && element.page == @page - end # Logs a message in the Rails logger (warn level) and optionally displays an error message to the user. def warning(message, text = nil) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 9a293b5584..c4a4531cd8 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -51,6 +51,18 @@ def render_element(element, part = :view, options = {}, i = 1) end end + # Returns a string for the id attribute of a html element for the given element + def element_dom_id(element) + return "" if element.nil? + "#{element.name}_#{element.id}" + end + + # Renders the data-alchemy-element HTML attribut used for the preview window hover effect. + def element_preview_code(element) + return "" if element.nil? + " data-alchemy-element='#{element.id}'" if @preview_mode && element.page == @page + end + def render_classes classes=[] s = classes.uniq.delete_if{|x| x == nil || x.blank?}.join(" ") s.blank? ? "" : "class='#{s}'" diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 2f21e507a5..2dae8f28eb 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -22,17 +22,29 @@ end - context "rendering elements" do + context "rendering elements", :focus => true do before(:each) do @element = Factory(:element) end it "should render an element view partial" do - pending("We have to spec the element model first") render_element(@element) end + it "should render a unique dom id for element" do + element_dom_id(@element).should == "#{@element.name}_#{@element.id}" + end + + it "should return the data-alchemy-element HTML attribute for element" do + @preview_mode = true + element_preview_code(@element).should == " data-alchemy-element='#{@element.id}'" + end + + it "should not return the data-alchemy-element HTML attribute if not in preview_mode" do + element_preview_code(@element).should_not == " data-alchemy-element='#{@element.id}'" + end + end end \ No newline at end of file From 5c9162ca4ca92e43f540e8fdf36b9c1fabed6431 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 22:58:49 +0200 Subject: [PATCH 22/86] Puts helper methods into their helper module and wrote a lot of specs. Refs #70 --- app/helpers/alchemy_helper.rb | 327 ------------------ app/helpers/contents_helper.rb | 69 ++++ app/helpers/elements_helper.rb | 147 ++++++++ app/helpers/essences_helper.rb | 167 +++++++++ app/helpers/pages_helper.rb | 63 ---- .../essences/_essence_picture_editor.html.erb | 4 +- spec/factories.rb | 14 +- spec/helpers/contents_helper_spec.rb | 25 ++ spec/helpers/elements_helper_spec.rb | 42 +++ spec/helpers/essences_helper_spec.rb | 49 +++ spec/helpers/pages_helper_spec.rb | 25 -- spec/integration/standardset_spec.rb | 6 +- 12 files changed, 512 insertions(+), 426 deletions(-) create mode 100644 app/helpers/contents_helper.rb create mode 100644 app/helpers/essences_helper.rb create mode 100644 spec/helpers/contents_helper_spec.rb create mode 100644 spec/helpers/elements_helper_spec.rb create mode 100644 spec/helpers/essences_helper_spec.rb diff --git a/app/helpers/alchemy_helper.rb b/app/helpers/alchemy_helper.rb index bcfd131f6e..730c79bbb0 100644 --- a/app/helpers/alchemy_helper.rb +++ b/app/helpers/alchemy_helper.rb @@ -12,251 +12,6 @@ def shorten(text, length) text.truncate(:length => length) end - def render_editor(element) - render_element(element, :editor) - end - - def get_content(element, position) - return element.contents[position - 1] - end - - # Renders all elements from @page. - # --- - # == Options are: - # :only => [] A list of element names to be rendered only. Very usefull if you want to render a specific element type in a special html part (e.g..
    ) of your page and all other elements in another part. - # :except => [] A list of element names to be rendered. The opposite of the only option. - # :from_page The Page.page_layout string from which the elements are rendered from, or you even pass a Page object. - # :count The amount of elements to be rendered (beginns with first element found) - # :fallback => {:for => 'ELEMENT_NAME', :with => 'ELEMENT_NAME', :from => 'PAGE_LAYOUT'} when no element from this name is found on page, then use this element from that page - # :sort_by => Content#name A Content name to sort the elements by - # :reverse => boolean Reverse the rendering order - # - # This helper also stores all pages where elements gets rendered on, so we can sweep them later if caching expires! - # - def render_elements(options = {}) - default_options = { - :except => [], - :only => [], - :from_page => "", - :count => nil, - :offset => nil, - :locals => {}, - :render_format => "html", - :fallback => nil - } - options = default_options.merge(options) - if options[:from_page].blank? - page = @page - else - if options[:from_page].class == Page - page = options[:from_page] - else - page = Page.find_all_by_page_layout_and_language_id(options[:from_page], session[:language_id]) - end - end - if page.blank? - warning('Page is nil') - return "" - else - show_non_public = configuration(:cache_pages) ? false : defined?(current_user) - if page.class == Array - all_elements = page.collect { |p| p.find_elements(options, show_non_public) }.flatten - else - all_elements = page.find_elements(options, show_non_public) - end - unless options[:sort_by].blank? - all_elements = all_elements.sort_by { |e| e.contents.detect { |c| c.name == options[:sort_by] }.ingredient } - end - all_elements.reverse! if options[:reverse_sort] || options[:reverse] - element_string = "" - if options[:fallback] - unless all_elements.detect { |e| e.name == options[:fallback][:for] } - if from = Page.find_by_page_layout(options[:fallback][:from]) - all_elements += from.elements.find_all_by_name(options[:fallback][:with].blank? ? options[:fallback][:for] : options[:fallback][:with]) - end - end - end - all_elements.each_with_index do |element, i| - element_string += render_element(element, :view, options, i+1) - end - element_string.html_safe - end - end - - # Renders the Content partial that is given (:editor, or :view). - # You can pass several options that are used by the different contents. - # - # For the view partial: - # :image_size => "111x93" Used by EssencePicture to render the image via RMagick to that size. - # :css_class => "" This css class gets attached to the content view. - # :date_format => "Am %d. %m. %Y, um %H:%Mh" Espacially fot the EssenceDate. See Date.strftime for date formatting. - # :caption => true Pass true to enable that the EssencePicture.caption value gets rendered. - # :blank_value => "" Pass a String that gets rendered if the content.essence is blank. - # - # For the editor partial: - # :css_class => "" This css class gets attached to the content editor. - # :last_image_deletable => false Pass true to enable that the last image of an imagecollection (e.g. image gallery) is deletable. - def render_essence(content, part = :view, options = {}, html_options = {}) - if content.nil? - return part == :view ? "" : warning('Content is nil', _("content_not_found")) - elsif content.essence.nil? - return part == :view ? "" : warning('Essence is nil', _("content_essence_not_found")) - end - defaults = { - :for_editor => { - :as => 'text_field', - :css_class => 'long', - :render_format => "html" - }, - :for_view => { - :image_size => "120x90", - :css_class => "", - :date_format => "%d. %m. %Y, %H:%Mh", - :caption => true, - :blank_value => "", - :render_format => "html" - } - } - options_for_partial = defaults[('for_' + part.to_s).to_sym].merge(options[('for_' + part.to_s).to_sym]) - options = options.merge(defaults) - render( - :partial => "essences/#{content.essence.class.name.underscore}_#{part.to_s}.#{options_for_partial[:render_format]}.erb", - :locals => { - :content => content, - :options => options_for_partial, - :html_options => html_options - } - ) - end - - # Renders the Content editor partial from the given Content. - # For options see -> render_essence - def render_essence_editor(content, options = {}) - render_essence(content, :editor, :for_editor => options) - end - - # Renders the Content view partial from the given Content. - # For options see -> render_essence - def render_essence_view(content, options = {}, html_options = {}) - render_essence(content, :view, {:for_view => options}, html_options) - end - - # Renders the Content editor partial from essence_type. - # - # Options are: - # * element (Element) - the Element the contents are in (obligatory) - # * type (String) - the type of Essence (obligatory) - # * options (Hash): - # ** :position (Integer) - The position of the Content inside the Element. I.E. for getting the n-th EssencePicture. Default is 1 (the first) - # ** :all (String) - Pass :all to get all Contents of that name. Default false - # * editor_options (Hash) - Will be passed to the render_essence_editor partial renderer - # - def render_essence_editor_by_type(element, essence_type, options = {}, editor_options = {}) - return warning('Element is nil', _("no_element_given")) if element.blank? - return warning('EssenceType is blank', _("No EssenceType given")) if essence_type.blank? - defaults = { - :position => 1, - :all => false - } - options = defaults.merge(options) - return_string = "" - if options[:all] - contents = element.contents.find_all_by_essence_type_and_name(essence_type, options[:all]) - contents.each do |content| - return_string << render_essence(content, :editor, :for_editor => editor_options) - end - else - content = element.contents.find_by_essence_type_and_position(essence_type, options[:position]) - return_string = render_essence(content, :editor, :for_editor => editor_options) - end - return_string - end - - # Renders the Content view partial from the given Element for the essence_type (e.g. EssenceRichtext). - # For multiple contents of same kind inside one molecue just pass a position so that will be rendered. - # Otherwise the first content found for this type will be rendered. - # For options see -> render_essence - def render_essence_view_by_type(element, type, position, options = {}, html_options = {}) - if element.blank? - warning('Element is nil') - return "" - end - if position.nil? - content = element.content_by_type(type) - else - content = element.contents.find_by_essence_type_and_position(type, position) - end - render_essence(content, :view, :for_view => options) - end - - # Renders the Content view partial from the given Element by position (e.g. 1). - # For options see -> render_essence - def render_essence_view_by_position(element, position, options = {}, html_options = {}) - if element.blank? - warning('Element is nil') - return "" - end - content = element.contents.find_by_position(position) - render_essence(content, :view, {:for_view => options}, html_options) - end - - # Renders the Content editor partial from the given Element by position (e.g. 1). - # For options see -> render_essence - def render_essence_editor_by_position(element, position, options = {}) - if element.blank? - warning('Element is nil') - return "" - end - content = element.contents.find_by_position(position) - render_essence(content, :editor, :for_editor => options) - end - - # Renders the Content editor partial found in views/contents/ for the content with name inside the passed Element. - # For options see -> render_essence - # - # Content creation on the fly: - # - # If you update the elements.yml file after creating an element this helper displays a error message with an option to create the content. - # - def render_essence_editor_by_name(element, name, options = {}) - if element.blank? - return warning('Element is nil', _("no_element_given")) - end - content = element.content_by_name(name) - if content.blank? - render :partial => 'admin/contents/missing', :locals => {:element => element, :name => name} - else - render_essence(content, :editor, :for_editor => options) - end - end - - # Renders the Content view partial from the passed Element for passed content name. - # For options see -> render_essence - def render_essence_view_by_name(element, name, options = {}, html_options = {}) - if element.blank? - warning('Element is nil') - return "" - end - content = element.content_by_name(name) - render_essence(content, :view, {:for_view => options}, html_options) - end - - # Renders the name of elements content or the default name defined in elements.yml - def render_content_name(content) - if content.blank? - warning('Element is nil') - return "" - else - content_name = content.name_for_label - end - if content.description.blank? - warning("Content #{content.name} is missing its description") - title = _("Warning: Content '%{contentname}' is missing its description.") % {:contentname => content.name} - content_name = %( ) + content_name - end - content.has_validations? ? "#{content_name}*" : content_name - end - # Returns @page.title # # The options are: @@ -851,30 +606,6 @@ def element_from_page(options = {}) element = page.elements.find_by_name_and_public(options[:element_name], true) return element end - - # This helper renderes the picture editor for the elements on the Alchemy Desktop. - # It brings full functionality for adding images to the element, deleting images from it and sorting them via drag'n'drop. - # Just place this helper inside your element editor view, pass the element as parameter and that's it. - # - # Options: - # :maximum_amount_of_images (integer), default nil. This option let you handle the amount of images your customer can add to this element. - def render_picture_editor(element, options={}) - default_options = { - :last_image_deletable => true, - :maximum_amount_of_images => nil, - :refresh_sortable => true - } - options = default_options.merge(options) - picture_contents = element.all_contents_by_type("EssencePicture") - render( - :partial => "admin/elements/picture_editor", - :locals => { - :picture_contents => picture_contents, - :element => element, - :options => options - } - ) - end def render_essence_selection_editor(element, content, select_options) if content.class == String @@ -941,28 +672,6 @@ def admin_mainnavi_active?(mainnav) end end - # Generates the url for the preview frame. - # target_url must contain target_controller and target_action. - def generate_preview_url(target_url) - preview_url = url_for( - :controller => ('/' + target_url["target_controller"]), - :action => target_url["target_action"], - :id => params[:id] - ) - end - - # Returns a string for the id attribute of a html element for the given content - def content_dom_id(content) - return "" if content.nil? - if content.class == String - a = Content.find_by_name(content) - return "" if a.nil? - else - a = content - end - "#{a.essence_type.underscore}_#{a.id}" - end - # Helper for including the nescessary javascripts and stylesheets for the different views. # Together with the rails caching we achieve a good load time. def alchemy_assets_set(setname = 'combined') @@ -990,42 +699,6 @@ def parse_sitemap_name(page) pathname end - def render_new_content_link(element) - link_to_overlay_window( - _('add new content'), - new_admin_element_content_path(element), - { - :size => '305x40', - :title => _('Select an content'), - :overflow => true - }, - { - :id => "add_content_for_element_#{element.id}", - :class => 'button new_content_link' - } - ) - end - - def render_create_content_link(element, options = {}) - defaults = { - :label => _('add new content') - } - options = defaults.merge(options) - link_to( - options[:label], - admin_contents_path( - :content => { - :name => options[:content_name], - :element_id => element.id - } - ), - :method => 'post', - :remote => true, - :id => "add_content_for_element_#{element.id}", - :class => 'button new_content_link' - ) - end - # Returns an icon def render_icon(icon_class) content_tag('span', '', :class => "icon #{icon_class}") diff --git a/app/helpers/contents_helper.rb b/app/helpers/contents_helper.rb new file mode 100644 index 0000000000..d96a86e8db --- /dev/null +++ b/app/helpers/contents_helper.rb @@ -0,0 +1,69 @@ +module ContentsHelper + + # Returns a string for the id attribute of a html element for the given content + def content_dom_id(content) + return "" if content.nil? + if content.class == String + c = Content.find_by_name(content) + return "" if c.nil? + else + c = content + end + "#{c.essence_type.underscore}_#{c.id}" + end + + # Renders the name of elements content or the default name defined in elements.yml + def render_content_name(content) + if content.blank? + warning('Element is nil') + return "" + else + content_name = content.name_for_label + end + if content.description.blank? + warning("Content #{content.name} is missing its description") + title = _("Warning: Content '%{contentname}' is missing its description.") % {:contentname => content.name} + content_name = %( ) + content_name + end + content.has_validations? ? "#{content_name}*" : content_name + end + + # Renders a link to show the new content overlay + def render_new_content_link(element) + link_to_overlay_window( + _('add new content'), + new_admin_element_content_path(element), + { + :size => '305x40', + :title => _('Select an content'), + :overflow => true + }, + { + :id => "add_content_for_element_#{element.id}", + :class => 'button new_content_link' + } + ) + end + + # Renders a link to create a new content in element editor + def render_create_content_link(element, options = {}) + defaults = { + :label => _('add new content') + } + options = defaults.merge(options) + link_to( + options[:label], + admin_contents_path( + :content => { + :name => options[:content_name], + :element_id => element.id + } + ), + :method => 'post', + :remote => true, + :id => "add_content_for_element_#{element.id}", + :class => 'button new_content_link' + ) + end + +end diff --git a/app/helpers/elements_helper.rb b/app/helpers/elements_helper.rb index fed28eaf86..8bef0b46d3 100644 --- a/app/helpers/elements_helper.rb +++ b/app/helpers/elements_helper.rb @@ -1,2 +1,149 @@ module ElementsHelper + + include EssencesHelper + + # Renders all elements from @page. + # --- + # == Options are: + # :only => [] A list of element names to be rendered only. Very usefull if you want to render a specific element type in a special html part (e.g..
    ) of your page and all other elements in another part. + # :except => [] A list of element names to be rendered. The opposite of the only option. + # :from_page The Page.page_layout string from which the elements are rendered from, or you even pass a Page object. + # :count The amount of elements to be rendered (beginns with first element found) + # :fallback => {:for => 'ELEMENT_NAME', :with => 'ELEMENT_NAME', :from => 'PAGE_LAYOUT'} when no element from this name is found on page, then use this element from that page + # :sort_by => Content#name A Content name to sort the elements by + # :reverse => boolean Reverse the rendering order + # + # This helper also stores all pages where elements gets rendered on, so we can sweep them later if caching expires! + # + def render_elements(options = {}) + default_options = { + :except => [], + :only => [], + :from_page => "", + :count => nil, + :offset => nil, + :locals => {}, + :render_format => "html", + :fallback => nil + } + options = default_options.merge(options) + if options[:from_page].blank? + page = @page + else + if options[:from_page].class == Page + page = options[:from_page] + else + page = Page.find_all_by_page_layout_and_language_id(options[:from_page], session[:language_id]) + end + end + if page.blank? + warning('Page is nil') + return "" + else + show_non_public = configuration(:cache_pages) ? false : defined?(current_user) + if page.class == Array + all_elements = page.collect { |p| p.find_elements(options, show_non_public) }.flatten + else + all_elements = page.find_elements(options, show_non_public) + end + unless options[:sort_by].blank? + all_elements = all_elements.sort_by { |e| e.contents.detect { |c| c.name == options[:sort_by] }.ingredient } + end + all_elements.reverse! if options[:reverse_sort] || options[:reverse] + element_string = "" + if options[:fallback] + unless all_elements.detect { |e| e.name == options[:fallback][:for] } + if from = Page.find_by_page_layout(options[:fallback][:from]) + all_elements += from.elements.find_all_by_name(options[:fallback][:with].blank? ? options[:fallback][:for] : options[:fallback][:with]) + end + end + end + all_elements.each_with_index do |element, i| + element_string += render_element(element, :view, options, i+1) + end + element_string.html_safe + end + end + + # This helper renders the Element partial for either the view or the editor part. + # Generate element partials with ./script/generate elements + def render_element(element, part = :view, options = {}, i = 1) + begin + if element.blank? + warning('Element is nil') + render :partial => "elements/#{part}_not_found", :locals => {:name => 'nil'} + else + default_options = { + :shorten_to => nil, + :render_format => "html" + } + options = default_options.merge(options) + element.store_page(@page) if part == :view + path1 = "#{Rails.root}/app/views/elements/" + path2 = "#{Rails.root}/vendor/plugins/alchemy/app/views/elements/" + partial_name = "_#{element.name.underscore}_#{part}.html.erb" + locals = options.delete(:locals) + render( + :partial => "elements/#{element.name.underscore}_#{part}.#{options[:render_format]}.erb", + :locals => { + :element => element, + :options => options, + :counter => i + }.merge(locals || {}) + ) + end + rescue ActionView::MissingTemplate + warning(%( + Element #{part} partial not found for #{element.name}.\n + Looking for #{partial_name}, but not found + neither in #{path1} + nor in #{path2} + Use rails generate alchemy:elements to generate them. + Maybe you still have old style partial names? (like .rhtml). Then please rename them in .html.erb' + )) + render :partial => "elements/#{part}_not_found", :locals => {:name => element.name, :error => "Element #{part} partial not found. Use rails generate alchemy:elements to generate them."} + end + end + + # Renders the element editor partial + def render_editor(element) + render_element(element, :editor) + end + + # Returns a string for the id attribute of a html element for the given element + def element_dom_id(element) + return "" if element.nil? + "#{element.name}_#{element.id}" + end + + # Renders the data-alchemy-element HTML attribut used for the preview window hover effect. + def element_preview_code(element) + return "" if element.nil? + " data-alchemy-element='#{element.id}'" if @preview_mode && element.page == @page + end + + # This helper renderes the picture editor for the elements on the Alchemy Desktop. + # It brings full functionality for adding images to the element, deleting images from it and sorting them via drag'n'drop. + # Just place this helper inside your element editor view, pass the element as parameter and that's it. + # + # Options: + # :maximum_amount_of_images (integer), default nil. This option let you handle the amount of images your customer can add to this element. + def render_picture_editor(element, options={}) + default_options = { + :last_image_deletable => true, + :maximum_amount_of_images => nil, + :refresh_sortable => true + } + options = default_options.merge(options) + picture_contents = element.all_contents_by_type("EssencePicture") + render( + :partial => "admin/elements/picture_editor", + :locals => { + :picture_contents => picture_contents, + :element => element, + :options => options + } + ) + end + end diff --git a/app/helpers/essences_helper.rb b/app/helpers/essences_helper.rb new file mode 100644 index 0000000000..d906e150a2 --- /dev/null +++ b/app/helpers/essences_helper.rb @@ -0,0 +1,167 @@ +module EssencesHelper + + include ContentsHelper + + # Renders the Content view partial from the passed Element for passed content name. + # For options see -> render_essence + def render_essence_view_by_name(element, name, options = {}, html_options = {}) + if element.blank? + warning('Element is nil') + return "" + end + content = element.content_by_name(name) + render_essence(content, :view, {:for_view => options}, html_options) + end + + # Renders the Content partial that is given (:editor, or :view). + # You can pass several options that are used by the different contents. + # + # For the view partial: + # :image_size => "111x93" Used by EssencePicture to render the image via RMagick to that size. + # :css_class => "" This css class gets attached to the content view. + # :date_format => "Am %d. %m. %Y, um %H:%Mh" Espacially fot the EssenceDate. See Date.strftime for date formatting. + # :caption => true Pass true to enable that the EssencePicture.caption value gets rendered. + # :blank_value => "" Pass a String that gets rendered if the content.essence is blank. + # + # For the editor partial: + # :css_class => "" This css class gets attached to the content editor. + # :last_image_deletable => false Pass true to enable that the last image of an imagecollection (e.g. image gallery) is deletable. + def render_essence(content, part = :view, options = {}, html_options = {}) + if content.nil? + return part == :view ? "" : warning('Content is nil', _("content_not_found")) + elsif content.essence.nil? + return part == :view ? "" : warning('Essence is nil', _("content_essence_not_found")) + end + defaults = { + :for_editor => { + :as => 'text_field', + :css_class => 'long', + :render_format => "html" + }, + :for_view => { + :image_size => "120x90", + :css_class => "", + :date_format => "%d. %m. %Y, %H:%Mh", + :caption => true, + :blank_value => "", + :render_format => "html" + } + } + if options["for_#{part}".to_sym].nil? + options_for_partial = defaults["for_#{part}".to_sym] + else + options_for_partial = defaults.fetch("for_#{part}".to_sym).merge(options["for_#{part}".to_sym]) + end + options = options.merge(defaults) + render( + :partial => "essences/#{content.essence.class.name.underscore}_#{part.to_s}.#{options_for_partial[:render_format]}.erb", + :locals => { + :content => content, + :options => options_for_partial, + :html_options => html_options + } + ) + end + + # Renders the Content view partial from the given Content. + # For options see -> render_essence + def render_essence_view(content, options = {}, html_options = {}) + render_essence(content, :view, {:for_view => options}, html_options) + end + + # Renders the Content view partial from the given Element for the essence_type (e.g. EssenceRichtext). + # For multiple contents of same kind inside one element just pass a position so that will be rendered. + # Otherwise the first content found for this type will be rendered. + # For options see -> render_essence + def render_essence_view_by_type(element, type, position = 1, options = {}, html_options = {}) + if element.blank? + warning('Element is nil') + return "" + end + if position == 1 + content = element.content_by_type(type) + else + content = element.contents.find_by_essence_type_and_position(type, position) + end + render_essence(content, :view, :for_view => options) + end + + # Renders the Content view partial from the given Element by position (e.g. 1). + # For options see -> render_essence + def render_essence_view_by_position(element, position, options = {}, html_options = {}) + if element.blank? + warning('Element is nil') + return "" + end + content = element.contents.find_by_position(position) + render_essence(content, :view, {:for_view => options}, html_options) + end + + # Renders the Content editor partial from the given Content. + # For options see -> render_essence + def render_essence_editor(content, options = {}) + render_essence(content, :editor, :for_editor => options) + end + + # Renders the Content editor partial from essence_type. + # + # Options are: + # * element (Element) - the Element the contents are in (obligatory) + # * type (String) - the type of Essence (obligatory) + # * options (Hash): + # ** :position (Integer) - The position of the Content inside the Element. I.E. for getting the n-th EssencePicture. Default is 1 (the first) + # ** :all (String) - Pass :all to get all Contents of that name. Default false + # * editor_options (Hash) - Will be passed to the render_essence_editor partial renderer + # + def render_essence_editor_by_type(element, essence_type, options = {}, editor_options = {}) + return warning('Element is nil', _("no_element_given")) if element.blank? + return warning('EssenceType is blank', _("No EssenceType given")) if essence_type.blank? + defaults = { + :position => 1, + :all => false + } + options = defaults.merge(options) + return_string = "" + if options[:all] + contents = element.contents.find_all_by_essence_type_and_name(essence_type, options[:all]) + contents.each do |content| + return_string << render_essence(content, :editor, :for_editor => editor_options) + end + else + content = element.contents.find_by_essence_type_and_position(essence_type, options[:position]) + return_string = render_essence(content, :editor, :for_editor => editor_options) + end + return_string + end + + # Renders the Content editor partial from the given Element by position (e.g. 1). + # For options see -> render_essence + def render_essence_editor_by_position(element, position, options = {}) + if element.blank? + warning('Element is nil') + return "" + end + content = element.contents.find_by_position(position) + render_essence(content, :editor, :for_editor => options) + end + + # Renders the Content editor partial found in views/contents/ for the content with name inside the passed Element. + # For options see -> render_essence + # + # Content creation on the fly: + # + # If you update the elements.yml file after creating an element this helper displays a error message with an option to create the content. + # + def render_essence_editor_by_name(element, name, options = {}) + if element.blank? + return warning('Element is nil', _("no_element_given")) + end + content = element.content_by_name(name) + if content.blank? + render :partial => 'admin/contents/missing', :locals => {:element => element, :name => name} + else + render_essence(content, :editor, :for_editor => options) + end + end + +end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index c4a4531cd8..63112b051f 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -1,68 +1,5 @@ -# All methods (helpers) in this helper are used by Alchemy to render elements, contents and layouts on the Page. -# -# TODO: list all important infos here. -# -# Most Important Infos: -# --- -# -# 1. The most important helpers for webdevelopers are the render_navigation(), render_elements() and the render_page_layout() helpers. -# 2. The currently displayed page can be accessed via the @page variable. -# 3. All important meta data from @page will be rendered via the render_meta_data() helper. - module PagesHelper - # This helper renders the Element partial for either the view or the editor part. - # Generate element partials with ./script/generate elements - def render_element(element, part = :view, options = {}, i = 1) - begin - if element.blank? - warning('Element is nil') - render :partial => "elements/#{part}_not_found", :locals => {:name => 'nil'} - else - default_options = { - :shorten_to => nil, - :render_format => "html" - } - options = default_options.merge(options) - element.store_page(@page) if part == :view - path1 = "#{Rails.root}/app/views/elements/" - path2 = "#{Rails.root}/vendor/plugins/alchemy/app/views/elements/" - partial_name = "_#{element.name.underscore}_#{part}.html.erb" - locals = options.delete(:locals) - render( - :partial => "elements/#{element.name.underscore}_#{part}.#{options[:render_format]}.erb", - :locals => { - :element => element, - :options => options, - :counter => i - }.merge(locals || {}) - ) - end - rescue ActionView::MissingTemplate - warning(%( - Element #{part} partial not found for #{element.name}.\n - Looking for #{partial_name}, but not found - neither in #{path1} - nor in #{path2} - Use rails generate alchemy:elements to generate them. - Maybe you still have old style partial names? (like .rhtml). Then please rename them in .html.erb' - )) - render :partial => "elements/#{part}_not_found", :locals => {:name => element.name, :error => "Element #{part} partial not found. Use rails generate alchemy:elements to generate them."} - end - end - - # Returns a string for the id attribute of a html element for the given element - def element_dom_id(element) - return "" if element.nil? - "#{element.name}_#{element.id}" - end - - # Renders the data-alchemy-element HTML attribut used for the preview window hover effect. - def element_preview_code(element) - return "" if element.nil? - " data-alchemy-element='#{element.id}'" if @preview_mode && element.page == @page - end - def render_classes classes=[] s = classes.uniq.delete_if{|x| x == nil || x.blank?}.join(" ") s.blank? ? "" : "class='#{s}'" diff --git a/app/views/essences/_essence_picture_editor.html.erb b/app/views/essences/_essence_picture_editor.html.erb index 7df6e05308..67b114c974 100644 --- a/app/views/essences/_essence_picture_editor.html.erb +++ b/app/views/essences/_essence_picture_editor.html.erb @@ -4,9 +4,7 @@ <%= link_to_confirmation_window( "", _("confirm_to_delete_image"), - url_for( - :controller => 'essence_pictures', - :action => 'destroy', + admin_essence_picture_path( :id => content, :options => options ), diff --git a/spec/factories.rb b/spec/factories.rb index c5b4cef8a4..ecae564f35 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -28,16 +28,20 @@ code "kl" name 'Klingonian' default false - frontpage_name 'tuq' + frontpage_name 'Tuq' page_layout 'intro' public true end factory :page do - name "tuq" - page_layout "intro" - association :language - public false + name "A Public Page" + page_layout "standard" + language :language + + factory :public_page do + public true + end + end factory :element do diff --git a/spec/helpers/contents_helper_spec.rb b/spec/helpers/contents_helper_spec.rb new file mode 100644 index 0000000000..3ea38e6269 --- /dev/null +++ b/spec/helpers/contents_helper_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe ContentsHelper do + + before(:each) do + @element = Factory(:element) + end + + it "should render a dom id" do + content_dom_id(@element.contents.first).should == "essence_text_1" + end + + it "should render the content name" do + render_content_name(@element.contents.first).should == "Einleitung" + end + + it "should render a link to add new content to element" do + pending "Don't know how to include the alchemy_helper in specs" + end + + it "should render a link to create a content in element" do + render_create_content_link(@element).should match(/a.+href.*admin\/contents.+class.+button new_content_link.*data-method.+post/) + end + +end diff --git a/spec/helpers/elements_helper_spec.rb b/spec/helpers/elements_helper_spec.rb new file mode 100644 index 0000000000..abad5b4cc3 --- /dev/null +++ b/spec/helpers/elements_helper_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +include AlchemyHelper + +describe ElementsHelper do + + before(:each) do + @element = Factory(:element) + end + + it "should render an element view partial" do + render_element(@element).should match(/class="article".+id="article_1"/) + end + + it "should render an element editor partial" do + render_editor(@element).should match(/class="content_editor".+id="essence_text_1"/) + end + + it "should render all elements" + + it "should render a unique dom id for element" do + element_dom_id(@element).should == "#{@element.name}_#{@element.id}" + end + + it "should render a picture editor partial" do + render_picture_editor(@element).should match(/class="essence_picture_editor"/) + end + + context "in preview mode" do + + it "should return the data-alchemy-element HTML attribute for element" do + @preview_mode = true + element_preview_code(@element).should == " data-alchemy-element='#{@element.id}'" + end + + it "should not return the data-alchemy-element HTML attribute if not in preview_mode" do + element_preview_code(@element).should_not == " data-alchemy-element='#{@element.id}'" + end + + end + +end diff --git a/spec/helpers/essences_helper_spec.rb b/spec/helpers/essences_helper_spec.rb new file mode 100644 index 0000000000..7f750914b2 --- /dev/null +++ b/spec/helpers/essences_helper_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe EssencesHelper do + + before(:each) do + @element = Factory(:element) + @element.content_by_name('intro').essence.update_attributes(:body => 'hello!') + end + + it "should render an essence" do + content = @element.content_by_name('intro') + render_essence(content).should match(/hello!/) + end + + it "should render an essence view" do + content = @element.content_by_name('intro') + render_essence_view(content).should match(/hello!/) + end + + it "should render an essence view by name" do + render_essence_view_by_name(@element, 'intro').should match(/hello!/) + end + + it "should render an essence view by type" do + render_essence_view_by_type(@element, 'EssenceText').should match(/hello!/) + end + + it "should render an essence view by position" do + render_essence_view_by_position(@element, 1).should match(/hello!/) + end + + it "should render an essence editor" do + content = @element.content_by_name('intro') + render_essence_editor(content).should match(/input.+type="text".+value="hello!/) + end + + it "should render an essence editor by name" do + render_essence_editor_by_name(@element, 'intro').should match(/input.+type="text".+value="hello!/) + end + + it "should render an essence editor by type" do + render_essence_editor_by_type(@element, 'EssenceText').should match(/input.+type="text".+value="hello!/) + end + + it "should render an essence editor by position" do + render_essence_editor_by_position(@element, 1).should match(/input.+type="text".+value="hello!/) + end + +end diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 2dae8f28eb..fab111ca11 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -21,30 +21,5 @@ end end - - context "rendering elements", :focus => true do - - before(:each) do - @element = Factory(:element) - end - - it "should render an element view partial" do - render_element(@element) - end - - it "should render a unique dom id for element" do - element_dom_id(@element).should == "#{@element.name}_#{@element.id}" - end - - it "should return the data-alchemy-element HTML attribute for element" do - @preview_mode = true - element_preview_code(@element).should == " data-alchemy-element='#{@element.id}'" - end - - it "should not return the data-alchemy-element HTML attribute if not in preview_mode" do - element_preview_code(@element).should_not == " data-alchemy-element='#{@element.id}'" - end - - end end \ No newline at end of file diff --git a/spec/integration/standardset_spec.rb b/spec/integration/standardset_spec.rb index f483aea0bd..09d8fe35fd 100644 --- a/spec/integration/standardset_spec.rb +++ b/spec/integration/standardset_spec.rb @@ -3,9 +3,9 @@ describe 'Alchemy Standard Set' do it "should show the sitename ingredient as page title prefix" do - pending "because rails 3 has other yaml library in test environment" - header_page = Page.create(:page_layout => 'layout_header', :parent_id => Page.root.id, :layoutpage => true, :language => Language.get_default) - sitename = Element.create_from_scratch({:name => 'sitename', :page_id => header_page.id}) + pending "because we should spec creation of Page and Language first" + header_page = Factory(:public_page) + sitename = Factory(:element, :name => 'sitename', :page => header_page) sitename.content_by_name('name').essence.update_attributes(:body => 'Peters Petshop') visit '/' within('head title') { page.should have_content('Peters Petshop') } From f5e6802b5448fb90a37c6f62d7eefcba0350ce77 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 17 Oct 2011 23:09:28 +0200 Subject: [PATCH 23/86] Changes RSpec output options and implemented one more helper spec --- .rspec | 3 +-- spec/helpers/contents_helper_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.rspec b/.rspec index ed4af24de9..5f1647637a 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --color ---format documentation ---debug +--format progress diff --git a/spec/helpers/contents_helper_spec.rb b/spec/helpers/contents_helper_spec.rb index 3ea38e6269..5fc83f01df 100644 --- a/spec/helpers/contents_helper_spec.rb +++ b/spec/helpers/contents_helper_spec.rb @@ -1,5 +1,7 @@ require 'spec_helper' +include AlchemyHelper + describe ContentsHelper do before(:each) do @@ -15,7 +17,7 @@ end it "should render a link to add new content to element" do - pending "Don't know how to include the alchemy_helper in specs" + render_new_content_link(@element).should match(/Alchemy.openWindow.+\/admin\/elements\/1\/contents\/new/m) end it "should render a link to create a content in element" do From ebded3641d8c5ff53219494d2a35c540b51624eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Tue, 18 Oct 2011 02:46:23 +0200 Subject: [PATCH 24/86] - fixes not working method public_language_roots (returned an empty hash, always) - refactored pages_helper_spec --- app/models/page.rb | 2 +- spec/helpers/pages_helper_spec.rb | 50 ++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index cfc7a44888..4528fc7ad1 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -40,7 +40,7 @@ class Page < ActiveRecord::Base scope :accessable, where(:restricted => false) scope :restricted, where(:restricted => true) scope :public_language_roots, lambda { - where("language_root = 1 AND language_code IN ('#{Language.all_codes_for_published.join('\',\'')}') AND public = 1") + where(:language_root => true).where("language_code IN ('#{Language.all_codes_for_published.join('\',\'')}')").where(:public => true) } scope :all_last_edited_from, lambda { |user| where(:updater_id => user.id).order('updated_at DESC').limit(5) } diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 263b6162c9..b1a56d61ba 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -2,21 +2,37 @@ describe PagesHelper do - describe "language_switches" do - before :each do - helper.stub(:configuration) - end + describe "using the language_switches method" do + + before :each do + @default_language = Language.get_default + @german = Factory(:language, :code => "de", :name => "Deutsch", :public => true) + # simulates link_to_public_child = true + helper.stub(:configuration).and_return(true) + helper.stub(:multi_language?).and_return(true) + end + + it "should return nil when having only one public language" do + helper.stub(:multi_language?).and_return(false) + helper.language_switches.should be nil + end + + it "should render an empty string when having more than one public language but only one language_root is public" do + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) + helper.stub(:multi_language?).and_return(true) + helper.language_switches.should == '' + pending "It means if we have just one possible language, so we dont need to render it!?' + end + + it "should render two links when having two public language_root pages and a public children per page" do + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + end - it "should return links to all other languages" do - helper.stub(:multi_language?).and_return(true) - Page.create(:language_code => "en", :public => true) - Page.create(:language_code => "de") - helper.language_switches.should == "" - end - - it "should return nil if there is only one language" do - helper.stub(:multi_language?).and_return(nil) - helper.language_switches.should be nil - end - end -end \ No newline at end of file +end From ded9ac4c3147d04e6f473d056266205cc1e88882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Tue, 18 Oct 2011 02:49:53 +0200 Subject: [PATCH 25/86] changed description of pending spec --- spec/helpers/pages_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index b1a56d61ba..cdb27f0e07 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -22,7 +22,7 @@ @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) helper.stub(:multi_language?).and_return(true) helper.language_switches.should == '' - pending "It means if we have just one possible language, so we dont need to render it!?' + pending "Do we need to render language_switcher with two languages if we have only one accessible language tree? I think we dont...' end it "should render two links when having two public language_root pages and a public children per page" do From 2eafe81d78ebe8dec749131cedb1eb24ce4ead86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Tue, 18 Oct 2011 02:58:30 +0200 Subject: [PATCH 26/86] typo... --- spec/helpers/pages_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index cdb27f0e07..5118c9a13e 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -18,11 +18,11 @@ end it "should render an empty string when having more than one public language but only one language_root is public" do + pending "It renders a link to the language. But do we need to render a language_switcher with one link? (we have only one accessible language tree) I think we dont..." @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) helper.stub(:multi_language?).and_return(true) helper.language_switches.should == '' - pending "Do we need to render language_switcher with two languages if we have only one accessible language tree? I think we dont...' end it "should render two links when having two public language_root pages and a public children per page" do From ed56e73e473f5e60b015ebca491709b29e0679b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Tue, 18 Oct 2011 09:23:01 +0200 Subject: [PATCH 27/86] - fixes not working method public_language_roots (returned an empty hash, always) - refactored pages_helper_spec --- app/models/page.rb | 2 +- spec/helpers/pages_helper_spec.rb | 49 +++++++++++++++++++------------ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index cfc7a44888..4528fc7ad1 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -40,7 +40,7 @@ class Page < ActiveRecord::Base scope :accessable, where(:restricted => false) scope :restricted, where(:restricted => true) scope :public_language_roots, lambda { - where("language_root = 1 AND language_code IN ('#{Language.all_codes_for_published.join('\',\'')}') AND public = 1") + where(:language_root => true).where("language_code IN ('#{Language.all_codes_for_published.join('\',\'')}')").where(:public => true) } scope :all_last_edited_from, lambda { |user| where(:updater_id => user.id).order('updated_at DESC').limit(5) } diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index fab111ca11..5118c9a13e 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -2,24 +2,37 @@ describe PagesHelper do - context "language_switches" do + describe "using the language_switches method" do - before :each do - helper.stub(:configuration) - end - - it "should return links to all other languages" do - helper.stub(:multi_language?).and_return(true) - Page.create(:language_code => "en", :public => true) - Page.create(:language_code => "de") - helper.language_switches.should == "" - end - - it "should return nil if there is only one language" do - helper.stub(:multi_language?).and_return(nil) - helper.language_switches.should be nil - end - + before :each do + @default_language = Language.get_default + @german = Factory(:language, :code => "de", :name => "Deutsch", :public => true) + # simulates link_to_public_child = true + helper.stub(:configuration).and_return(true) + helper.stub(:multi_language?).and_return(true) + end + + it "should return nil when having only one public language" do + helper.stub(:multi_language?).and_return(false) + helper.language_switches.should be nil + end + + it "should render an empty string when having more than one public language but only one language_root is public" do + pending "It renders a link to the language. But do we need to render a language_switcher with one link? (we have only one accessible language tree) I think we dont..." + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) + helper.stub(:multi_language?).and_return(true) + helper.language_switches.should == '' + end + + it "should render two links when having two public language_root pages and a public children per page" do + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + end -end \ No newline at end of file +end From f2e8da0f72f0dc4d5f2e8491e0060c22de657f82 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 18 Oct 2011 17:40:47 +0200 Subject: [PATCH 28/86] Adds a pending spec --- spec/integration/standardset_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/integration/standardset_spec.rb b/spec/integration/standardset_spec.rb index 09d8fe35fd..fab6fceda8 100644 --- a/spec/integration/standardset_spec.rb +++ b/spec/integration/standardset_spec.rb @@ -11,4 +11,6 @@ within('head title') { page.should have_content('Peters Petshop') } end -end \ No newline at end of file + it "should render a whole page including all its elements and contents" + +end From 63902e83403aac6188b29d99ff576344bd57775f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 18 Oct 2011 18:02:38 +0200 Subject: [PATCH 29/86] Using Rails 3.0.10 for install script. Closes #73 --- bin/alchemy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/alchemy b/bin/alchemy index 65fe1a5bc1..822f03e1ac 100755 --- a/bin/alchemy +++ b/bin/alchemy @@ -18,7 +18,7 @@ class Alchemy < Thor say "Installing...", :yellow - if system "rails new #{project} -m #{File.join(File.dirname(__FILE__), '..', 'lib', 'rails', 'templates', 'alchemy.rb')} -d mysql -JT" + if system "rails _3.0.10_ new #{project} -m #{File.join(File.dirname(__FILE__), '..', 'lib', 'rails', 'templates', 'alchemy.rb')} -d mysql -JT" @application = project From 150dc7e4fbf7eeeba1e406de1776b66ae3622de4 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 18 Oct 2011 22:24:06 +0200 Subject: [PATCH 30/86] Fixes pages helper spec. --- config/locales/de.yml | 2 +- spec/helpers/pages_helper_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 580127086f..61fce973bf 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -325,7 +325,7 @@ de: inclusion: "%{attribute} ist kein gültiger Wert" exclusion: "%{attribute} ist nicht verfügbar" invalid: "%{attribute} ist nicht gültig" - record_invalid: 'Validierung ist fehlgeschlagen' + record_invalid: 'Validierung von %{errors} ist fehlgeschlagen' confirmation: "%{attribute} stimmt nicht mit der Bestätigung überein" accepted: "%{attribute} muss akzeptiert werden" empty: "%{attribute} muss ausgefüllt werden" diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 27b24e860e..184392e731 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -6,7 +6,7 @@ before :each do @default_language = Language.get_default - @german = Factory(:language, :code => "de", :name => "Deutsch", :public => true) + @german = Language.find_by_code('de') # simulates link_to_public_child = true helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(true) From a5dde4c21ddd7edc9c56fe8b403484e995c56008 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 18 Oct 2011 23:13:07 +0200 Subject: [PATCH 31/86] Fixes Factories to get all examples passing --- app/controllers/elements_controller.rb | 2 +- app/helpers/pages_helper.rb | 2 ++ spec/element_spec.rb | 2 ++ spec/factories.rb | 19 ++++++++++++++----- spec/integration/standardset_spec.rb | 22 +++++++++++++--------- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/controllers/elements_controller.rb b/app/controllers/elements_controller.rb index 444654ee8b..65b88db990 100644 --- a/app/controllers/elements_controller.rb +++ b/app/controllers/elements_controller.rb @@ -2,7 +2,7 @@ class ElementsController < AlchemyController filter_access_to [:show], :attribute_check => true layout false - + # Returns the element partial as HTML or as JavaScript that tries to replace a given +container_id+ with the partial content via jQuery. def show @element = Element.find(params[:id]) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 63112b051f..d17e052fab 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -1,5 +1,7 @@ module PagesHelper + include ElementsHelper + def render_classes classes=[] s = classes.uniq.delete_if{|x| x == nil || x.blank?}.join(" ") s.blank? ? "" : "class='#{s}'" diff --git a/spec/element_spec.rb b/spec/element_spec.rb index 4cb2241da7..760c786699 100644 --- a/spec/element_spec.rb +++ b/spec/element_spec.rb @@ -19,4 +19,6 @@ FileUtils.mv(File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml.bak'), File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml')) end + it "should return an ingredient by name" + end diff --git a/spec/factories.rb b/spec/factories.rb index ecae564f35..a7eedb6d08 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -32,16 +32,25 @@ page_layout 'intro' public true end - + factory :page do - name "A Public Page" + language { Language.find_by_code('kl') || Factory(:language) } + name "A Page" + parent_id { Factory(:language_root_page).id } page_layout "standard" - language :language - + + factory :language_root_page do + name 'Klingonian' + page_layout 'intro' + language_root true + parent_id { Page.root.id } + end + factory :public_page do + name "A Public Page" public true end - + end factory :element do diff --git a/spec/integration/standardset_spec.rb b/spec/integration/standardset_spec.rb index fab6fceda8..6e96430b50 100644 --- a/spec/integration/standardset_spec.rb +++ b/spec/integration/standardset_spec.rb @@ -2,15 +2,19 @@ describe 'Alchemy Standard Set' do - it "should show the sitename ingredient as page title prefix" do - pending "because we should spec creation of Page and Language first" - header_page = Factory(:public_page) - sitename = Factory(:element, :name => 'sitename', :page => header_page) - sitename.content_by_name('name').essence.update_attributes(:body => 'Peters Petshop') - visit '/' - within('head title') { page.should have_content('Peters Petshop') } - end + before(:each) do + # We need an user or the signup view will show up + Factory(:registered_user) + end - it "should render a whole page including all its elements and contents" + it "should show the sitename ingredient as page title prefix" + + it "should render a whole page including all its elements and contents" do + page = Factory(:public_page) + article = Factory(:element, :name => 'article', :page => page) + article.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop') + visit '/a-public-page' + within('#content') { page.should have_content('Welcome to Peters Petshop') } + end end From 9b7b174fc91c6ddca49df82653f51a910e74f90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Wed, 19 Oct 2011 00:27:19 +0200 Subject: [PATCH 32/86] Fixes Issue #74 Added more specs for the language_switches method --- app/helpers/pages_helper.rb | 10 +++- spec/helpers/pages_helper_spec.rb | 98 ++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 16 deletions(-) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 6c39638c55..056ae7f550 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -72,6 +72,7 @@ def alchemy_form_reset_button(name, options={}) end # helper for language switching + # returns a string with links or nil def language_switches(options={}) default_options = { :linkname => :name, @@ -86,13 +87,13 @@ def language_switches(options={}) if multi_language? language_links = [] pages = (options[:link_to_public_child] == true) ? Page.language_roots : Page.public_language_roots + return nil if pages.blank? pages.each_with_index do |page, i| if(options[:link_to_page_with_layout] != nil) - page_found_by_layout = Page.find_by_page_layout_and_language_id(options[:link_to_page_with_layout].to_s, page.language) + page_found_by_layout = Page.where(:page_layout => options[:link_to_page_with_layout].to_s, :language_id => page.language_id) end page = page_found_by_layout || page page = (options[:link_to_public_child] ? (page.first_public_child.blank? ? nil : page.first_public_child) : nil) if !page.public? - if !page.blank? active = session[:language_id] == page.language.id linkname = page.language.label(options[:linkname]) @@ -107,6 +108,11 @@ def language_switches(options={}) ) end end + # when last iteration and we have just one language_link, + # we dont need to render it. + if (i==pages.length-1) && language_links.length == 1 + return nil + end end language_links.reverse! if options[:reverse] if options[:as_select_box] diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 5118c9a13e..1c7946120a 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -2,7 +2,7 @@ describe PagesHelper do - describe "using the language_switches method" do + context "method language_switches" do before :each do @default_language = Language.get_default @@ -13,24 +13,94 @@ end it "should return nil when having only one public language" do + helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(false) helper.language_switches.should be nil end - it "should render an empty string when having more than one public language but only one language_root is public" do - pending "It renders a link to the language. But do we need to render a language_switcher with one link? (we have only one accessible language tree) I think we dont..." - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) - helper.stub(:multi_language?).and_return(true) - helper.language_switches.should == '' - end + context "with two public languages and two language_roots" do + + before :each do + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + end + + context "and config redirect_to_public_child is set to TRUE" do + + before :each do + # simulates link_to_public_child = true + helper.stub(:configuration).and_return(true) + end + + it "should return nil if only one language_root is public and both do not have children" do + @german_language_root.update_attributes(:public => false) + helper.language_switches.should == nil + end + + it "should return nil if only one language_root is public and both have none public children" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => false, :name => "child1") + helper.language_switches.should == nil + end + + it "should render two links when having two public language_root pages" do + helper.language_switches.should have_selector('a', :count => 2) + end - it "should render two links when having two public language_root pages and a public children per page" do - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") - helper.language_switches.should have_selector('a', :count => 2) + it "should render two links when having just one public language_root but a public children in both language_roots" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should render two links when having two not public language_roots but a public children in both" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should return nil when having two not public language_roots and a public children in only one of them" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + end + + context "and config redirect_to_public_child is set to FALSE" do + + before :each do + # simulates link_to_public_child = false + helper.stub(:configuration).and_return(false) + end + + it "should render two links when having two public language_root pages" do + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should render nil when having just one public language_root but a public children in both language_roots" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + it "should render nil when having two not public language_roots but a public children in both" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + end + end end From ff1dcf5354fea19c538eea50d2f119deecf0c247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Wed, 19 Oct 2011 00:33:24 +0200 Subject: [PATCH 33/86] Fixes Issue #74 Added more specs for the language_switches method --- app/helpers/pages_helper.rb | 10 +++- spec/helpers/pages_helper_spec.rb | 98 ++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 16 deletions(-) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 63112b051f..e4ae4cc1e6 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -67,6 +67,7 @@ def alchemy_form_reset_button(name, options={}) end # helper for language switching + # returns a string with links or nil def language_switches(options={}) default_options = { :linkname => :name, @@ -81,13 +82,13 @@ def language_switches(options={}) if multi_language? language_links = [] pages = (options[:link_to_public_child] == true) ? Page.language_roots : Page.public_language_roots + return nil if pages.blank? pages.each_with_index do |page, i| if(options[:link_to_page_with_layout] != nil) - page_found_by_layout = Page.find_by_page_layout_and_language_id(options[:link_to_page_with_layout].to_s, page.language) + page_found_by_layout = Page.where(:page_layout => options[:link_to_page_with_layout].to_s, :language_id => page.language_id) end page = page_found_by_layout || page page = (options[:link_to_public_child] ? (page.first_public_child.blank? ? nil : page.first_public_child) : nil) if !page.public? - if !page.blank? active = session[:language_id] == page.language.id linkname = page.language.label(options[:linkname]) @@ -102,6 +103,11 @@ def language_switches(options={}) ) end end + # when last iteration and we have just one language_link, + # we dont need to render it. + if (i==pages.length-1) && language_links.length == 1 + return nil + end end language_links.reverse! if options[:reverse] if options[:as_select_box] diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 5118c9a13e..1c7946120a 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -2,7 +2,7 @@ describe PagesHelper do - describe "using the language_switches method" do + context "method language_switches" do before :each do @default_language = Language.get_default @@ -13,24 +13,94 @@ end it "should return nil when having only one public language" do + helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(false) helper.language_switches.should be nil end - it "should render an empty string when having more than one public language but only one language_root is public" do - pending "It renders a link to the language. But do we need to render a language_switcher with one link? (we have only one accessible language tree) I think we dont..." - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) - helper.stub(:multi_language?).and_return(true) - helper.language_switches.should == '' - end + context "with two public languages and two language_roots" do + + before :each do + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + end + + context "and config redirect_to_public_child is set to TRUE" do + + before :each do + # simulates link_to_public_child = true + helper.stub(:configuration).and_return(true) + end + + it "should return nil if only one language_root is public and both do not have children" do + @german_language_root.update_attributes(:public => false) + helper.language_switches.should == nil + end + + it "should return nil if only one language_root is public and both have none public children" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => false, :name => "child1") + helper.language_switches.should == nil + end + + it "should render two links when having two public language_root pages" do + helper.language_switches.should have_selector('a', :count => 2) + end - it "should render two links when having two public language_root pages and a public children per page" do - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") - helper.language_switches.should have_selector('a', :count => 2) + it "should render two links when having just one public language_root but a public children in both language_roots" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should render two links when having two not public language_roots but a public children in both" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should return nil when having two not public language_roots and a public children in only one of them" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + end + + context "and config redirect_to_public_child is set to FALSE" do + + before :each do + # simulates link_to_public_child = false + helper.stub(:configuration).and_return(false) + end + + it "should render two links when having two public language_root pages" do + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should render nil when having just one public language_root but a public children in both language_roots" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + it "should render nil when having two not public language_roots but a public children in both" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + end + end end From e1e95162951c6327563ca43a7221916a20b1649b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Wed, 19 Oct 2011 00:50:14 +0200 Subject: [PATCH 34/86] Fixes Issue #74 Added more specs for the language_switches method --- spec/helpers/pages_helper_spec.rb | 100 +++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 15 deletions(-) diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 184392e731..1c7946120a 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -2,35 +2,105 @@ describe PagesHelper do - context "using the language_switches method" do + context "method language_switches" do before :each do @default_language = Language.get_default - @german = Language.find_by_code('de') + @german = Factory(:language, :code => "de", :name => "Deutsch", :public => true) # simulates link_to_public_child = true helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(true) end it "should return nil when having only one public language" do + helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(false) helper.language_switches.should be nil end - it "should render an empty string when having more than one public language but only one language_root is public" do - pending "It renders a link to the language. But do we need to render a language_switcher with one link? (we have only one accessible language tree) I think we dont..." - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => false, :language_root => true) - helper.stub(:multi_language?).and_return(true) - helper.language_switches.should == '' - end + context "with two public languages and two language_roots" do + + before :each do + @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + end + + context "and config redirect_to_public_child is set to TRUE" do + + before :each do + # simulates link_to_public_child = true + helper.stub(:configuration).and_return(true) + end + + it "should return nil if only one language_root is public and both do not have children" do + @german_language_root.update_attributes(:public => false) + helper.language_switches.should == nil + end + + it "should return nil if only one language_root is public and both have none public children" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => false, :name => "child1") + helper.language_switches.should == nil + end + + it "should render two links when having two public language_root pages" do + helper.language_switches.should have_selector('a', :count => 2) + end - it "should render two links when having two public language_root pages and a public children per page" do - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") - helper.language_switches.should have_selector('a', :count => 2) + it "should render two links when having just one public language_root but a public children in both language_roots" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should render two links when having two not public language_roots but a public children in both" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should return nil when having two not public language_roots and a public children in only one of them" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + end + + context "and config redirect_to_public_child is set to FALSE" do + + before :each do + # simulates link_to_public_child = false + helper.stub(:configuration).and_return(false) + end + + it "should render two links when having two public language_root pages" do + helper.language_switches.should have_selector('a', :count => 2) + end + + it "should render nil when having just one public language_root but a public children in both language_roots" do + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + it "should render nil when having two not public language_roots but a public children in both" do + @default_language_root.update_attributes(:public => false) + @german_language_root.update_attributes(:public => false) + @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") + @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + helper.language_switches.should == nil + end + + end + end end From c814fdf338390090baa55b02f4b36490b75d281a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 12:24:22 +0200 Subject: [PATCH 35/86] Fixes page_layout_spec. Removing spec/dummy/config/alchemy folder after test run --- spec/dummy/config/alchemy/page_layouts.yml | 2 -- spec/page_layout_spec.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 spec/dummy/config/alchemy/page_layouts.yml diff --git a/spec/dummy/config/alchemy/page_layouts.yml b/spec/dummy/config/alchemy/page_layouts.yml deleted file mode 100644 index c6b93212e2..0000000000 --- a/spec/dummy/config/alchemy/page_layouts.yml +++ /dev/null @@ -1,2 +0,0 @@ -- name: testlayout - elements: diff --git a/spec/page_layout_spec.rb b/spec/page_layout_spec.rb index 364aa4d3c5..3009f63fbb 100644 --- a/spec/page_layout_spec.rb +++ b/spec/page_layout_spec.rb @@ -14,7 +14,7 @@ page_layouts.puts "- name: testlayout\n elements:" end Alchemy::PageLayout.get_layouts.first.values.should include("testlayout") - FileUtils.rm_f(config_path) + FileUtils.rm_rf(config_path) end end From 478e2f06af512e2ef1a3d54e88a4be45e3e3b409 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 13:09:20 +0200 Subject: [PATCH 36/86] Fixes to pages_helper language_links and specs --- app/helpers/pages_helper.rb | 10 ++++------ spec/factories.rb | 1 + spec/helpers/pages_helper_spec.rb | 33 +++++++++++++++---------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index ad9f211207..5adaad13d0 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -84,7 +84,7 @@ def language_switches(options={}) if multi_language? language_links = [] pages = (options[:link_to_public_child] == true) ? Page.language_roots : Page.public_language_roots - return nil if pages.blank? + return nil if (pages.blank? || pages.length == 1) pages.each_with_index do |page, i| if(options[:link_to_page_with_layout] != nil) page_found_by_layout = Page.where(:page_layout => options[:link_to_page_with_layout].to_s, :language_id => page.language_id) @@ -105,12 +105,8 @@ def language_switches(options={}) ) end end - # when last iteration and we have just one language_link, - # we dont need to render it. - if (i==pages.length-1) && language_links.length == 1 - return nil - end end + return nil if language_links.empty? || language_links.length == 1 language_links.reverse! if options[:reverse] if options[:as_select_box] return select_tag( @@ -124,6 +120,8 @@ def language_switches(options={}) else raw(language_links.join(options[:spacer])) end + else + nil end end diff --git a/spec/factories.rb b/spec/factories.rb index a7eedb6d08..ad78d58f97 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -43,6 +43,7 @@ name 'Klingonian' page_layout 'intro' language_root true + public true parent_id { Page.root.id } end diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 1c7946120a..a69d7bbefa 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -6,7 +6,7 @@ before :each do @default_language = Language.get_default - @german = Factory(:language, :code => "de", :name => "Deutsch", :public => true) + @klingonian = Factory(:language) # simulates link_to_public_child = true helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(true) @@ -14,15 +14,14 @@ it "should return nil when having only one public language" do helper.stub(:configuration).and_return(true) - helper.stub(:multi_language?).and_return(false) helper.language_switches.should be nil end context "with two public languages and two language_roots" do before :each do - @default_language_root = Factory(:page, :language => @default_language, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) - @german_language_root = Factory(:page, :language => @german, :parent_id => Page.root.id, :name => "home", :public => true, :language_root => true) + @default_language_root = Factory(:language_root_page, :language => @default_language, :name => 'Default Language Root') + @klingonian_language_root = Factory(:language_root_page) end context "and config redirect_to_public_child is set to TRUE" do @@ -33,14 +32,14 @@ end it "should return nil if only one language_root is public and both do not have children" do - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) helper.language_switches.should == nil end it "should return nil if only one language_root is public and both have none public children" do - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => false, :name => "child1") + @klingonian_first_public_child = Factory(:page, :language => @klingonian, :parent_id => @klingonian_language_root.id, :public => false, :name => "child1") helper.language_switches.should == nil end @@ -49,25 +48,25 @@ end it "should render two links when having just one public language_root but a public children in both language_roots" do - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + @klingonian_first_public_child = Factory(:page, :language => @klingonian, :parent_id => @klingonian_language_root.id, :public => true, :name => "child1") helper.language_switches.should have_selector('a', :count => 2) end it "should render two links when having two not public language_roots but a public children in both" do @default_language_root.update_attributes(:public => false) - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + @klingonian_first_public_child = Factory(:page, :language => @klingonian, :parent_id => @klingonian_language_root.id, :public => true, :name => "child1") helper.language_switches.should have_selector('a', :count => 2) end it "should return nil when having two not public language_roots and a public children in only one of them" do @default_language_root.update_attributes(:public => false) - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => false, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + @klingonian_first_public_child = Factory(:page, :language => @klingonian, :parent_id => @klingonian_language_root.id, :public => true, :name => "child1") helper.language_switches.should == nil end @@ -85,17 +84,17 @@ end it "should render nil when having just one public language_root but a public children in both language_roots" do - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + @klingonian_first_public_child = Factory(:page, :language => @klingonian, :parent_id => @klingonian_language_root.id, :public => true, :name => "child1") helper.language_switches.should == nil end it "should render nil when having two not public language_roots but a public children in both" do @default_language_root.update_attributes(:public => false) - @german_language_root.update_attributes(:public => false) + @klingonian_language_root.update_attributes(:public => false) @default_first_public_child = Factory(:page, :language => @default_language, :parent_id => @default_language_root.id, :public => true, :name => "child1") - @german_first_public_child = Factory(:page, :language => @german, :parent_id => @german_language_root.id, :public => true, :name => "child1") + @klingonian_first_public_child = Factory(:page, :language => @klingonian, :parent_id => @klingonian_language_root.id, :public => true, :name => "child1") helper.language_switches.should == nil end From 3a4734766663365447c529ea12880c649e8d96ad Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 13:30:13 +0200 Subject: [PATCH 37/86] Removes duplicated div#content from standard set --- app/views/layouts/pages.html.erb | 4 +--- app/views/page_layouts/_contact.html.erb | 2 +- app/views/page_layouts/_external.html.erb | 1 - app/views/page_layouts/_intro.html.erb | 2 +- app/views/page_layouts/_news.html.erb | 2 +- app/views/page_layouts/_search.html.erb | 2 +- app/views/page_layouts/_standard.html.erb | 2 +- spec/integration/standardset_spec.rb | 7 ++++--- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/views/layouts/pages.html.erb b/app/views/layouts/pages.html.erb index 8e29c61f4c..e000abf6af 100644 --- a/app/views/layouts/pages.html.erb +++ b/app/views/layouts/pages.html.erb @@ -16,9 +16,7 @@ -
    - <%= yield %> -
    + <%= yield %>
    - <%= render_elements %> + <%= render_elements %>
    diff --git a/app/views/page_layouts/_external.html.erb b/app/views/page_layouts/_external.html.erb index 446c428ed6..e69de29bb2 100644 --- a/app/views/page_layouts/_external.html.erb +++ b/app/views/page_layouts/_external.html.erb @@ -1 +0,0 @@ -<%= render_elements %> \ No newline at end of file diff --git a/app/views/page_layouts/_intro.html.erb b/app/views/page_layouts/_intro.html.erb index 5c0452ce57..b0e44484a0 100644 --- a/app/views/page_layouts/_intro.html.erb +++ b/app/views/page_layouts/_intro.html.erb @@ -10,5 +10,5 @@ <%- end -%>
    - <%= render_elements(:except => ['header', 'claim']) %> + <%= render_elements(:except => ['header', 'claim']) %>
    diff --git a/app/views/page_layouts/_news.html.erb b/app/views/page_layouts/_news.html.erb index a7e38e282d..786911f05c 100644 --- a/app/views/page_layouts/_news.html.erb +++ b/app/views/page_layouts/_news.html.erb @@ -10,5 +10,5 @@ <%- end -%>
    - <%= render_elements %> + <%= render_elements %>
    diff --git a/app/views/page_layouts/_search.html.erb b/app/views/page_layouts/_search.html.erb index a7e38e282d..786911f05c 100644 --- a/app/views/page_layouts/_search.html.erb +++ b/app/views/page_layouts/_search.html.erb @@ -10,5 +10,5 @@ <%- end -%>
- <%= render_elements %> + <%= render_elements %>
diff --git a/app/views/page_layouts/_standard.html.erb b/app/views/page_layouts/_standard.html.erb index 568088f7fc..0592223caf 100644 --- a/app/views/page_layouts/_standard.html.erb +++ b/app/views/page_layouts/_standard.html.erb @@ -10,5 +10,5 @@ <%- end -%>
- <%= render_elements :except => ["claim", "header"] %> + <%= render_elements :except => ["claim", "header"] %>
diff --git a/spec/integration/standardset_spec.rb b/spec/integration/standardset_spec.rb index 6e96430b50..95cf9f1f65 100644 --- a/spec/integration/standardset_spec.rb +++ b/spec/integration/standardset_spec.rb @@ -10,10 +10,11 @@ it "should show the sitename ingredient as page title prefix" it "should render a whole page including all its elements and contents" do - page = Factory(:public_page) - article = Factory(:element, :name => 'article', :page => page) - article.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop') + page = Factory(:public_page, :language => Language.get_default) + article = page.elements.find_by_name('article') + article.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true) visit '/a-public-page' + save_and_open_page within('#content') { page.should have_content('Welcome to Peters Petshop') } end From cf14261ec4b2b6fbb6ec84f4abb35a0835374026 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 13:40:41 +0200 Subject: [PATCH 38/86] Moves render_page_layout helper into pages_helper --- app/helpers/alchemy_helper.rb | 12 ------------ app/helpers/pages_helper.rb | 12 ++++++++++++ spec/helpers/pages_helper_spec.rb | 6 ++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/helpers/alchemy_helper.rb b/app/helpers/alchemy_helper.rb index 730c79bbb0..ab11652415 100644 --- a/app/helpers/alchemy_helper.rb +++ b/app/helpers/alchemy_helper.rb @@ -363,18 +363,6 @@ def static_image_tag image, options={} image_tag url_for(:controller => :images, :action => :show_static, :image => image) end - # Renders the layout from @page.page_layout. File resists in /app/views/page_layouts/_LAYOUT-NAME.html.erb - def render_page_layout(options={}) - default_options = { - :render_format => "html" - } - options = default_options.merge(options) - render :partial => "page_layouts/#{@page.page_layout.downcase}.#{options[:render_format]}.erb" - rescue ActionView::MissingTemplate - warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.") - render :partial => "page_layouts/standard" - end - # Returns @current_language set in the action (e.g. Page.show) def current_language if @current_language.nil? diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb index 5adaad13d0..2f9e21b602 100644 --- a/app/helpers/pages_helper.rb +++ b/app/helpers/pages_helper.rb @@ -125,6 +125,18 @@ def language_switches(options={}) end end + # Renders the layout from @page.page_layout. File resists in /app/views/page_layouts/_LAYOUT-NAME.html.erb + def render_page_layout(options={}) + default_options = { + :render_format => "html" + } + options = default_options.merge(options) + render :partial => "page_layouts/#{@page.page_layout.downcase}.#{options[:render_format]}.erb" + rescue ActionView::MissingTemplate + warning("PageLayout: '#{@page.page_layout}' not found. Rendering standard page_layout.") + render :partial => "page_layouts/standard" + end + def sitename_from_header_page header_page = Page.find_by_page_layout_and_layoutpage('layout_header', true) return "" if header_page.nil? diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index a69d7bbefa..5b676b2045 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -2,6 +2,12 @@ describe PagesHelper do + it "should render the current page layout" do + @page = Factory(:public_page) + helper.stub(:configuration).and_return(true) + render_page_layout.should have_selector('div#content') + end + context "method language_switches" do before :each do From db63f598b692865b7ab058b9e4303269f9e62fca Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 13:48:26 +0200 Subject: [PATCH 39/86] Moves model specs into spec/models folder --- spec/{ => models}/element_spec.rb | 0 spec/{ => models}/language_spec.rb | 0 spec/{ => models}/page_spec.rb | 0 spec/{ => models}/user_spec.rb | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename spec/{ => models}/element_spec.rb (100%) rename spec/{ => models}/language_spec.rb (100%) rename spec/{ => models}/page_spec.rb (100%) rename spec/{ => models}/user_spec.rb (100%) diff --git a/spec/element_spec.rb b/spec/models/element_spec.rb similarity index 100% rename from spec/element_spec.rb rename to spec/models/element_spec.rb diff --git a/spec/language_spec.rb b/spec/models/language_spec.rb similarity index 100% rename from spec/language_spec.rb rename to spec/models/language_spec.rb diff --git a/spec/page_spec.rb b/spec/models/page_spec.rb similarity index 100% rename from spec/page_spec.rb rename to spec/models/page_spec.rb diff --git a/spec/user_spec.rb b/spec/models/user_spec.rb similarity index 100% rename from spec/user_spec.rb rename to spec/models/user_spec.rb From 406e873406375dbf5e53af0c89d5085e66470ab7 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 14:00:41 +0200 Subject: [PATCH 40/86] Ads a published scope for Element --- app/models/element.rb | 1 + spec/models/element_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/models/element.rb b/app/models/element.rb index 2263ec5181..bb7db92c62 100644 --- a/app/models/element.rb +++ b/app/models/element.rb @@ -17,6 +17,7 @@ class Element < ActiveRecord::Base # TODO: add a trashed column to elements table scope :trashed, where(:page_id => nil).order('updated_at DESC') + scope :published, where(:public => true) # Returns next Element on self.page or nil. Pass a Element.name to get next of this kind. def next(name = nil) diff --git a/spec/models/element_spec.rb b/spec/models/element_spec.rb index 760c786699..b07a6abf65 100644 --- a/spec/models/element_spec.rb +++ b/spec/models/element_spec.rb @@ -2,6 +2,12 @@ describe Element do + it "should return all public elements" do + @public_elements = [Factory(:element), Factory(:element)] + @all_elements = @public_elements + [Factory(:element, :public => false)] + Element.published.should == @public_elements + end + it "should return a list of element definitions for a list of element names" do element_names = ["article"] definitions = Element.all_definitions_for(element_names) From ca3629e81c2e9fdeeeb1f6554098d7a64c1742d7 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 19 Oct 2011 22:00:35 +0200 Subject: [PATCH 41/86] Refactor Page.find_selected_elements --- app/models/element.rb | 4 +- app/models/page.rb | 43 +++++++++++------- spec/helpers/pages_helper_spec.rb | 8 ++-- spec/integration/standardset_spec.rb | 9 ++-- spec/models/element_spec.rb | 31 ++++++++++--- spec/models/page_spec.rb | 65 ++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 31 deletions(-) diff --git a/app/models/element.rb b/app/models/element.rb index bb7db92c62..09e704fe55 100644 --- a/app/models/element.rb +++ b/app/models/element.rb @@ -18,7 +18,9 @@ class Element < ActiveRecord::Base # TODO: add a trashed column to elements table scope :trashed, where(:page_id => nil).order('updated_at DESC') scope :published, where(:public => true) - + scope :named, lambda { |names| where(arel_table[:name].in(names)) } + scope :excluded, lambda { |names| where(arel_table[:name].not_in(names)) } + # Returns next Element on self.page or nil. Pass a Element.name to get next of this kind. def next(name = nil) if name.nil? diff --git a/app/models/page.rb b/app/models/page.rb index 4528fc7ad1..7e711410d7 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -50,24 +50,37 @@ class Page < ActiveRecord::Base scope :contentpages, where("pages.layoutpage = 0 AND pages.parent_id IS NOT NULL") - # Finds selected elements from page either except a passed collection or only the passed collection - # Collection is an array of strings from element names. E.g.: ['text', 'headline'] - # Returns only public ones - def find_selected_elements(options, show_non_public = false) - public_condition = show_non_public ? nil : ' AND elements.public = 1' - if !options[:except].blank? - condition = ["elements.name NOT IN (?)#{public_condition}", options[:except]] - elsif !options[:only].blank? - condition = ["elements.name IN (?)#{public_condition}", options[:only]] + # Finds selected elements from page. + # + # Options are: + # + # :only => Array of element names # Returns only elements with given names + # :except => Array of element names # Returns all elements except the ones with given names + # :count => Integer # Limit the count of returned elements + # :offset => Integer # Starts with an offset while returning elements + # :random => Boolean # Returning elements randomly shuffled + # + # Returns only public elements by default. + # Pass true as second argument to get all elements. + # + def find_selected_elements(options = {}, show_non_public = false) + elements = self.elements + if !options[:only].blank? + elements = self.elements.named(options[:only]) + elsif !options[:except].blank? + elements = self.elements.excluded(options[:except]) + end + elements = elements.offset(options[:offset]).limit(options[:count]) + elements = elements.order("RAND()") if options[:random] + if show_non_public + elements else - condition = show_non_public.nil? ? nil : {:public => true} + elements.published end - elements = self.elements.where(condition).limit(options[:count]).offset(options[:offset]) - elements.order("RAND()") unless options[:random].blank? - elements end - def find_elements(options, show_non_public = false) + def find_elements(options = {}, show_non_public = false) #:nodoc: + # TODO: What is this? A Kind of proxy method? Why not rendering the elements directly if you already have them???? if !options[:collection].blank? && options[:collection].is_a?(Array) all_elements = options[:collection] else @@ -75,7 +88,7 @@ def find_elements(options, show_non_public = false) end all_elements end - + def elements_grouped_by_cells group = ActiveSupport::OrderedHash.new cells.each { |cell| group[cell] = cell.elements } diff --git a/spec/helpers/pages_helper_spec.rb b/spec/helpers/pages_helper_spec.rb index 5b676b2045..37982df7c8 100644 --- a/spec/helpers/pages_helper_spec.rb +++ b/spec/helpers/pages_helper_spec.rb @@ -9,7 +9,7 @@ end context "method language_switches" do - + before :each do @default_language = Language.get_default @klingonian = Factory(:language) @@ -17,14 +17,14 @@ helper.stub(:configuration).and_return(true) helper.stub(:multi_language?).and_return(true) end - + it "should return nil when having only one public language" do helper.stub(:configuration).and_return(true) helper.language_switches.should be nil end - + context "with two public languages and two language_roots" do - + before :each do @default_language_root = Factory(:language_root_page, :language => @default_language, :name => 'Default Language Root') @klingonian_language_root = Factory(:language_root_page) diff --git a/spec/integration/standardset_spec.rb b/spec/integration/standardset_spec.rb index 95cf9f1f65..25d6660f99 100644 --- a/spec/integration/standardset_spec.rb +++ b/spec/integration/standardset_spec.rb @@ -10,12 +10,11 @@ it "should show the sitename ingredient as page title prefix" it "should render a whole page including all its elements and contents" do - page = Factory(:public_page, :language => Language.get_default) - article = page.elements.find_by_name('article') + p = Factory(:public_page, :language => Language.get_default) + article = p.elements.find_by_name('article') article.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true) - visit '/a-public-page' - save_and_open_page - within('#content') { page.should have_content('Welcome to Peters Petshop') } + visit '/de/a-public-page' + within('div#content div.article div.intro') { page.should have_content('Welcome to Peters Petshop') } end end diff --git a/spec/models/element_spec.rb b/spec/models/element_spec.rb index b07a6abf65..3c7cba60bd 100644 --- a/spec/models/element_spec.rb +++ b/spec/models/element_spec.rb @@ -2,10 +2,29 @@ describe Element do - it "should return all public elements" do - @public_elements = [Factory(:element), Factory(:element)] - @all_elements = @public_elements + [Factory(:element, :public => false)] - Element.published.should == @public_elements + context "scoped" do + + before(:each) do + Element.delete_all + end + + it "should return all public elements" do + elements = [Factory(:element, :public => true), Factory(:element, :public => true)] + Element.published.all.should == elements + end + + it "should return all elements by name" do + elements = [Factory(:element, :name => 'article'), Factory(:element, :name => 'article')] + Element.named(['article']).all.should == elements + end + + it "should return all elements but excluded ones" do + Factory(:element, :name => 'article') + Factory(:element, :name => 'article') + excluded = [Factory(:element, :name => 'claim')] + Element.excluded(['article']).all.should == excluded + end + end it "should return a list of element definitions for a list of element names" do @@ -20,9 +39,9 @@ end it "should raise an error if no descriptions are found" do - FileUtils.mv(File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml'), File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml.bak')) + FileUtils.mv(File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml'), File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml.bak')) expect { Element.descriptions }.should raise_error - FileUtils.mv(File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml.bak'), File.join(File.dirname(__FILE__), '..', 'config', 'alchemy', 'elements.yml')) + FileUtils.mv(File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml.bak'), File.join(File.dirname(__FILE__), '..', '..', 'config', 'alchemy', 'elements.yml')) end it "should return an ingredient by name" diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb index 75106bdc76..f02b90ec4d 100644 --- a/spec/models/page_spec.rb +++ b/spec/models/page_spec.rb @@ -15,6 +15,71 @@ Page.rootpage.should be_instance_of(Page) end + context "finding elements" do + + before(:each) do + @page = Factory(:public_page) + @non_public_elements = [ + Factory(:element, :public => false, :page => @page), + Factory(:element, :public => false, :page => @page) + ] + end + + it "should return the collection of elements if passed an array into options[:collection]" do + options = {:collection => @page.elements} + @page.find_elements(options).all.should == @page.elements.all + end + + context "with show_non_public argument TRUE" do + + it "should return all elements from empty options" do + @page.find_elements({}, true).all.should == @page.elements.all + end + + it "should only return the elements passed as options[:only]" do + @page.find_elements({:only => ['article']}, true).all.should == @page.elements.named('article').all + end + + it "should not return the elements passed as options[:except]" do + @page.find_elements({:except => ['article']}, true).all.should == @page.elements - @page.elements.named('article').all + end + + it "should return elements offsetted" do + @page.find_elements({:offset => 2}, true).all.should == @page.elements.offset(2) + end + + it "should return elements limitted in count" do + @page.find_elements({:count => 1}, true).all.should == @page.elements.limit(1) + end + + end + + context "with show_non_public argument FALSE" do + + it "should return all elements from empty arguments" do + @page.find_elements().all.should == @page.elements.published.all + end + + it "should only return the public elements passed as options[:only]" do + @page.find_elements(:only => ['article']).all.should == @page.elements.published.named('article').all + end + + it "should return all public elements except the ones passed as options[:except]" do + @page.find_elements(:except => ['article']).all.should == @page.elements.published.all - @page.elements.published.named('article').all + end + + it "should return elements offsetted" do + @page.find_elements({:offset => 2}).all.should == @page.elements.published.offset(2) + end + + it "should return elements limitted in count" do + @page.find_elements({:count => 1}).all.should == @page.elements.published.limit(1) + end + + end + + end + context "create" do it "the rootpage with page_layout rootpage does not need a parent_id" do @rootpage.rootpage?.should be_true From 958bb61500ab428b21dac361b21bc4b93f99dffa Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 20 Oct 2011 22:22:59 +0200 Subject: [PATCH 42/86] Fixes show_page_paths having lang param for languages not being public while server starts. --- config/routes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 3d67ac7788..10173f234c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,10 +29,10 @@ match '/pictures/thumbnails/:id/:size(/:crop_from)(/:crop_size)/thumbnail.png' => 'pictures#thumbnail', :as => :thumbnail, :defaults => { :format => 'png' } match '/:lang' => 'pages#show', - :constraints => {:lang => Regexp.new(Language.all_codes_for_published.join('|'))}, + :constraints => {:lang => /[a-z]{2}/}, :as => :show_language_root match '(/:lang)/:urlname(.:format)' => 'pages#show', - :constraints => {:lang => Regexp.new(Language.all_codes_for_published.join('|'))}, + :constraints => {:lang => /[a-z]{2}/}, :as => :show_page resources :user_sessions From d922c9ab6908ad7978dc3f63a16d8e37d9b6eb7f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 20 Oct 2011 23:50:56 +0200 Subject: [PATCH 43/86] Ads an is_admin? method and helper --- app/controllers/alchemy_controller.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/alchemy_controller.rb b/app/controllers/alchemy_controller.rb index 6bf2633fb7..ccca1d1225 100644 --- a/app/controllers/alchemy_controller.rb +++ b/app/controllers/alchemy_controller.rb @@ -12,9 +12,15 @@ class AlchemyController < ApplicationController before_filter :set_language before_filter :mailer_set_url_options - helper_method :current_server, :configuration, :multi_language?, :current_user, :clipboard_empty?, :trash_empty?, :get_clipboard + helper_method :current_server, :configuration, :multi_language?, :current_user, :clipboard_empty?, :trash_empty?, :get_clipboard, :is_admin? helper :layout - + + # Returns true if the current_user (The logged-in Alchemy User) has the admin role. + def is_admin? + return false if !current_user + current_user.admin? + end + def render_errors_or_redirect(object, redicrect_url, flash_notice, button = nil) if object.errors.empty? flash[:notice] = _(flash_notice) @@ -23,7 +29,7 @@ def render_errors_or_redirect(object, redicrect_url, flash_notice, button = nil) render_remote_errors(object, button) end end - + def render_remote_errors(object, button = nil) render :update do |page| page << "jQuery('#errors').html('
    " + object.errors.sum { |a, b| "
  • " + _(b) + "
  • " } + "
')" @@ -31,7 +37,7 @@ def render_remote_errors(object, button = nil) page << "Alchemy.enableButton('#{button}')" unless button.blank? end end - + # Returns a host string with the domain the app is running on. def current_server # For local development server From b54e830aff885966d1ffcdc0c22d19ce16f85c04 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 21 Oct 2011 00:34:17 +0200 Subject: [PATCH 44/86] Split AlchemyHelper methods into Controller contexts. Closes #70 --- app/helpers/alchemy_helper.rb | 418 +----------------- app/helpers/elements_helper.rb | 43 ++ app/helpers/pages_helper.rb | 364 ++++++++++++++- .../_image_link.html.erb} | 0 .../_link.html.erb} | 0 .../_renderer.html.erb} | 0 spec/helpers/elements_helper_spec.rb | 21 +- spec/helpers/pages_helper_spec.rb | 27 ++ spec/integration/standardset_spec.rb | 15 +- 9 files changed, 460 insertions(+), 428 deletions(-) rename app/views/{partials/_navigation_image_link.html.erb => navigation/_image_link.html.erb} (100%) rename app/views/{partials/_navigation_link.html.erb => navigation/_link.html.erb} (100%) rename app/views/{partials/_navigation_renderer.html.erb => navigation/_renderer.html.erb} (100%) diff --git a/app/helpers/alchemy_helper.rb b/app/helpers/alchemy_helper.rb index ab11652415..5abb69ec0d 100644 --- a/app/helpers/alchemy_helper.rb +++ b/app/helpers/alchemy_helper.rb @@ -2,317 +2,14 @@ module AlchemyHelper include FastGettext::Translation - def configuration(name) - return Alchemy::Config.get(name) - end - # An alias for truncate. # Left here for downwards compatibilty. def shorten(text, length) text.truncate(:length => length) end - # Returns @page.title - # - # The options are: - # :prefix => "" - # :seperator => "|" - # - # == Webdevelopers: - # Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. - # So you dont have to worry about anything. - def render_page_title options={} - default_options = { - :prefix => "", - :seperator => "|" - } - default_options.update(options) - unless @page.title.blank? - h("#{default_options[:prefix]} #{default_options[:seperator]} #{@page.title}") - else - h("") - end - end - - # Returns a complete html tag for the <head> part of the html document. - # - # == Webdevelopers: - # Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. - # So you dont have to worry about anything. - def render_title_tag options={} - default_options = { - :prefix => "", - :seperator => "|" - } - options = default_options.merge(options) - title = render_page_title(options) - %(<title>#{title}).html_safe - end - - # Renders a html tag for :name => "" and :content => "" - # - # == Webdevelopers: - # Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. - # So you dont have to worry about anything. - def render_meta_tag(options={}) - default_options = { - :name => "", - :default_language => "de", - :content => "" - } - options = default_options.merge(options) - lang = (@page.language.blank? ? options[:default_language] : @page.language.code) - %().html_safe - end - - # Renders a html for @page.language. - # - # == Webdevelopers: - # Please use the render_meta_data() helper. There all important meta information gets rendered in one helper. - # So you dont have to worry about anything. - def render_meta_content_language_tag(options={}) - default_options = { - :default_language => "de" - } - options = default_options.merge(options) - lang = (@page.language_code.blank? ? options[:default_language] : @page.language_code) - %().html_safe - end - - # = This helper takes care of all important meta tags for your @page. - # --- - # The meta data is been taken from the @page.title, @page.meta_description, @page.meta_keywords, @page.updated_at and @page.language database entries managed by the Alchemy user via the Alchemy cockpit. - # - # Assume that the user has entered following data into the Alchemy cockpit of the Page "home" and that the user wants that the searchengine (aka. google) robot should index the page and should follow all links on this page: - # - # Title = Homepage - # Description = Your page description - # Keywords: cms, ruby, rubyonrails, rails, software, development, html, javascript, ajax - # - # Then placing render_meta_data(:title_prefix => "company", :title_seperator => "::") into the part of the pages.html.erb layout produces: - # - # - # - # Company :: #{@page.title} - # - # - # - # - # - # - def render_meta_data options={} - if @page.blank? - warning("No Page found!") - return nil - end - default_options = { - :title_prefix => "", - :title_seperator => "|", - :default_lang => "de" - } - options = default_options.merge(options) - #render meta description of the root page from language if the current meta description is empty - if @page.meta_description.blank? - description = Page.find_by_language_root_and_language_id(true, session[:language_id]).meta_description rescue "" - else - description = @page.meta_description - end - #render meta keywords of the root page from language if the current meta keywords is empty - if @page.meta_keywords.blank? - keywords = Page.find_by_language_root_and_language_id(true, session[:language_id]).meta_keywords rescue "" - else - keywords = @page.meta_keywords - end - robot = "#{@page.robot_index? ? "" : "no"}index, #{@page.robot_follow? ? "" : "no"}follow" - meta_string = %( - - #{render_meta_content_language_tag} - #{render_title_tag( :prefix => options[:title_prefix], :seperator => options[:title_seperator])} - #{render_meta_tag( :name => "description", :content => description)} - #{render_meta_tag( :name => "keywords", :content => keywords)} - - - - ) - if @page.contains_feed? - meta_string += %( - - ) - end - return meta_string.html_safe - end - - # Returns an array of all pages in the same branch from current. Used internally to find the active page in navigations. - def breadcrumb(current) - return [] if current.nil? - result = Array.new - result << current - while current = current.parent - result << current - end - return result.reverse - end - - # Returns a html string for a linked breadcrumb from root to current page. - # == Options: - # :seperator => %(>) Maybe you don't want this seperator. Pass another one. - # :page => @page Pass a different Page instead of the default (@page). - # :without => nil Pass Pageobject or array of Pages that must not be displayed. - # :public_only => false Pass boolean for displaying hidden pages only. - # :visible_only => true Pass boolean for displaying (in navigation) visible pages only. - # :restricted_only => false Pass boolean for displaying restricted pages only. - # :reverse => false Pass boolean for displaying reversed breadcrumb. - def render_breadcrumb(options={}) - default_options = { - :seperator => %(>), - :page => @page, - :without => nil, - :public_only => false, - :visible_only => true, - :restricted_only => false, - :reverse => false - } - options = default_options.merge(options) - pages = breadcrumb(options[:page]) - pages.delete(Page.root) - unless options[:without].nil? - unless options[:without].class == Array - pages.delete(options[:without]) - else - pages = pages - options[:without] - end - end - if(options[:visible_only]) - pages.reject!{|p| !p.visible? } - end - if(options[:public_only]) - pages.reject!{|p| !p.public? } - end - if(options[:restricted_only]) - pages.reject!{|p| !p.restricted? } - end - if(options[:reverse]) - pages.reverse! - end - bc = [] - pages.each do |page| - urlname = page.urlname - (page.name == @page.name) ? css_class = "active" : nil - if page == pages.last - css_class.blank? ? css_class = "last" : css_class = [css_class, "last"].join(" ") - elsif page == pages.first - css_class.blank? ? css_class = "first" : css_class = [css_class, "last"].join(" ") - end - if multi_language? - url = show_page_url(:urlname => urlname, :lang => page.language_code) - else - url = show_page_url(:urlname => urlname) - end - bc << link_to( h(page.name), url, :class => css_class, :title => page.title ) - end - bc.join(options[:seperator]).html_safe - end - - # returns true if page is in the active branch - def page_active? page - @breadcrumb ||= breadcrumb(@page) - @breadcrumb.include? page - end - - # = This helper renders the navigation. - # - # It produces a html
structure with all necessary classes and ids so you can produce nearly every navigation the web uses today. - # E.G. dropdown-navigations, simple mainnavigations or even complex nested ones. - # --- - # == En detail: - # - # - # - # As you can see: Everything you need. - # - # Not pleased with the way Alchemy produces the navigation structure? - # Then feel free to overwrite the partials (_navigation_renderer.html.erb and _navigation_link.html.erb) found in views/pages/partials/ or pass different partials via the options :navigation_partial and :navigation_link_partial. - # - # == The options are: - # - # :submenu => false Do you want a nested