diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-27 22:52:50 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-27 22:52:50 +0200 |
| commit | 9a19a0494ef51cdac9a78e24d517ca48ba44c453 (patch) | |
| tree | 8eaae12d8047a40e29d3ea7ff3116b5c869e04bd /app/helpers | |
| parent | 85a01e35274b8d4d4165a7b26bd7986e211246bb (diff) | |
| parent | 1853082fcd8c067390c246f9daa01a9b47387497 (diff) | |
Migration from Rails 2.3.5 to Rails 8.1 successful.
Merging dev branch.
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/admin_helper.rb | 8 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 11 | ||||
| -rw-r--r-- | app/helpers/content_helper.rb | 44 | ||||
| -rw-r--r-- | app/helpers/link_helper.rb | 62 | ||||
| -rw-r--r-- | app/helpers/nodes_helper.rb | 20 |
5 files changed, 87 insertions, 58 deletions
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index da8945e..e5c3d5c 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | module AdminHelper | 1 | module AdminHelper |
| 2 | 2 | ||
| 3 | def language_selector | 3 | def language_selector |
| 4 | case I18n.locale | 4 | case I18n.locale |
| 5 | when :de | 5 | when :de |
| 6 | link_to 'English', url_for(:overwrite_params => {:locale => :en}) | 6 | link_to raw('<span class="inactive">English</span>'), url_for(params.permit!.to_h.merge('locale' => 'en')) |
| 7 | when :en | 7 | when :en |
| 8 | link_to 'Deutsch', url_for(:overwrite_params => {:locale => :de}) | 8 | link_to raw('<span class="inactive">Deutsch</span>'), url_for(params.permit!.to_h.merge('locale' => 'de')) |
| 9 | end | 9 | end |
| 10 | end | 10 | end |
| 11 | end \ No newline at end of file | 11 | end |
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22a7940..0be66e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | # Methods added to this helper will be available to all templates in the application. | 1 | # Methods added to this helper will be available to all templates in the application. |
| 2 | module ApplicationHelper | 2 | module ApplicationHelper |
| 3 | def form_error_messages(form_object) | ||
| 4 | object = form_object.is_a?(ActionView::Helpers::FormBuilder) ? form_object.object : form_object | ||
| 5 | return "" unless object && object.errors.any? | ||
| 6 | content_tag(:div, :class => "error_messages") do | ||
| 7 | content_tag(:ul) do | ||
| 8 | object.errors.full_messages.map do |msg| | ||
| 9 | content_tag(:li, msg) | ||
| 10 | end.join.html_safe | ||
| 11 | end | ||
| 12 | end | ||
| 13 | end | ||
| 3 | end | 14 | end |
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index d6c96f1..21cc579 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | module ContentHelper | 1 | module ContentHelper |
| 2 | 2 | ||
| 3 | def main_menu | 3 | def main_menu |
| 4 | menu_items = MenuItem.all(:order => "position ASC") | 4 | menu_items = MenuItem.order("position ASC").all |
| 5 | render( | 5 | render( |
| 6 | :partial => 'content/main_navigation', | 6 | :partial => 'content/main_navigation', |
| 7 | :locals => {:menu_items => menu_items} | 7 | :locals => {:menu_items => menu_items} |
| @@ -9,13 +9,13 @@ module ContentHelper | |||
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def calendar | 11 | def calendar |
| 12 | occurrences = Occurrence.find_in_range(Time.now, (Time.now+14.days)) | 12 | occurrences = Occurrence.find_in_range(Time.now, (Time.now+6.weeks)) |
| 13 | 13 | ||
| 14 | if occurrences.empty? | 14 | if occurrences.empty? |
| 15 | occurrences = Occurrence.find_next | 15 | occurrences = Occurrence.find_next |
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | occurrences = occurrences.reject { |o| o.node.head.nil? } | 18 | occurrences = occurrences.reject { |o| o.node.nil? || o.node.head.nil? } |
| 19 | 19 | ||
| 20 | render( | 20 | render( |
| 21 | :partial => 'content/front_page_calendar', | 21 | :partial => 'content/front_page_calendar', |
| @@ -43,7 +43,7 @@ module ContentHelper | |||
| 43 | # Returns the published_at attribute of a page if it is not nil, otherwise | 43 | # Returns the published_at attribute of a page if it is not nil, otherwise |
| 44 | # it returns the auto-filled value of the created_at attribute | 44 | # it returns the auto-filled value of the created_at attribute |
| 45 | def date_for_page page | 45 | def date_for_page page |
| 46 | page.published_at.to_s(:db) rescue page.created_at.to_s(:db) | 46 | I18n.l(page.published_at, :format => :ccc) rescue I18n.l(page.created_at, :format => :ccc) |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | def author_for_page page | 49 | def author_for_page page |
| @@ -51,7 +51,7 @@ module ContentHelper | |||
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | def page_title | 53 | def page_title |
| 54 | if @page.title && @page.title != "" | 54 | if @page && @page.title && @page.title != "" |
| 55 | "CCC | #{@page.title}" | 55 | "CCC | #{@page.title}" |
| 56 | else | 56 | else |
| 57 | "CCC | Chaos Computer Club" | 57 | "CCC | Chaos Computer Club" |
| @@ -59,41 +59,43 @@ module ContentHelper | |||
| 59 | end | 59 | end |
| 60 | 60 | ||
| 61 | # This method is an output filter for templates. It accepts any kind of text | 61 | # This method is an output filter for templates. It accepts any kind of text |
| 62 | # and checks for an <aggregate /> tag within it. If such a tag is found, its | 62 | # and checks for an [aggregate short code within it. If such a code is found, |
| 63 | # attributes are parsed and converted into parameters for the | 63 | # its # attributes are parsed and converted into parameters for the |
| 64 | # render_collection method. The <aggregate /> tag will then be replaced | 64 | # render_collection method. The [aggregate ] short code will then be replaced |
| 65 | # entirely with the output of the render_collection method. | 65 | # entirely with the output of the render_collection method. |
| 66 | # | 66 | # |
| 67 | # Syntax of the <aggregate /> tag: | 67 | # Syntax of the [aggregate ] short code: |
| 68 | # | 68 | # |
| 69 | # <aggregate | 69 | # [aggregate |
| 70 | # flags="update, pressemitteilung" | 70 | # flags="update, pressemitteilung" |
| 71 | # limit="20" | 71 | # limit="20" |
| 72 | # order_by="published_at" | 72 | # order_by="published_at" |
| 73 | # order_direction="DESC" | 73 | # order_direction="DESC" |
| 74 | # /> | 74 | # ] |
| 75 | def aggregate? content | 75 | def aggregate? content |
| 76 | options = {} | 76 | options = {} |
| 77 | 77 | ||
| 78 | cccms_attributes = ActionView::Base.sanitized_allowed_attributes + ['lang'] | ||
| 79 | |||
| 78 | begin | 80 | begin |
| 79 | if content =~ /<aggregate([^<>]*)>/ | 81 | if content =~ /\[aggregate([^\]]*)\]/ |
| 80 | tag = $~.to_s | 82 | tag = $~.to_s |
| 81 | matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/) | 83 | matched_data = $1.scan(/\w+\="[a-zA-Z\s\/_\d,.=]*"/) |
| 82 | 84 | ||
| 83 | matched_data.each do |data| | 85 | matched_data.each do |data| |
| 84 | splitted_data = data.split("=") | 86 | splitted_data = data.split("=", 2) |
| 85 | options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") | 87 | options[splitted_data[0].to_sym] = splitted_data[1].gsub(/"/, "") |
| 86 | end | 88 | end |
| 87 | 89 | ||
| 88 | options[:partial] = select_partial( options[:partial] ) | 90 | options[:partial] = select_partial(options[:partial]) |
| 89 | 91 | ||
| 90 | sanitize( content.sub(tag, render_collection(options)) ) | 92 | sanitize(content.sub(tag, render_collection(options)), :attributes => cccms_attributes) |
| 91 | else | 93 | else |
| 92 | sanitize( content ) | 94 | sanitize(content, :attributes => cccms_attributes) |
| 93 | end | 95 | end |
| 94 | 96 | ||
| 95 | rescue | 97 | rescue |
| 96 | sanitize( content ) | 98 | sanitize(content, :attributes => cccms_attributes) |
| 97 | end | 99 | end |
| 98 | end | 100 | end |
| 99 | 101 | ||
| @@ -124,9 +126,7 @@ module ContentHelper | |||
| 124 | # Check if a custom partial exists in the proper location | 126 | # Check if a custom partial exists in the proper location |
| 125 | def partial_exists? partial | 127 | def partial_exists? partial |
| 126 | File.exist?( | 128 | File.exist?( |
| 127 | File.join( | 129 | Rails.root.join('app', 'views', 'custom', 'partials', "_#{partial}.html.erb") |
| 128 | RAILS_ROOT, 'app', 'views', 'custom', 'partials', "_#{partial}.html.erb" | ||
| 129 | ) | ||
| 130 | ) | 130 | ) |
| 131 | end | 131 | end |
| 132 | 132 | ||
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 1b20e6d..878e8e4 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb | |||
| @@ -1,54 +1,62 @@ | |||
| 1 | module LinkHelper | 1 | module LinkHelper |
| 2 | 2 | ||
| 3 | def content_path_helper path_array | 3 | def content_path_helper path_array |
| 4 | url_for( | 4 | url_for( |
| 5 | :controller => :content, | 5 | :controller => :content, |
| 6 | :action => :render_page, | 6 | :action => :render_page, |
| 7 | :locale => params[:locale] || I18n.locale, | 7 | :locale => (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale), |
| 8 | :page_path => path_array | 8 | :page_path => path_array |
| 9 | ) | 9 | ) |
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | def content_url_helper path_array | 12 | def content_url_helper path_array |
| 13 | request.protocol + request.host_with_port + content_path_helper(path_array) | 13 | request.protocol + request.host_with_port + content_path_helper(path_array) |
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | def link_to_path title, path, html_options = {} | 16 | def link_to_path title, path, html_options = {} |
| 17 | return "" if path.nil? | ||
| 18 | |||
| 17 | if params[:page_path] | 19 | if params[:page_path] |
| 18 | active = (params[:page_path].join("/") == path.sub(/^\//, "")) | 20 | page_path = params[:page_path].is_a?(Array) ? params[:page_path].join("/") : params[:page_path] |
| 21 | active = (page_path == path.sub(/^\//, "")) | ||
| 19 | end | 22 | end |
| 20 | 23 | ||
| 21 | active_class = active ? {:class => 'active'} : {:class => 'inactive'} | 24 | active_class = active ? {:class => 'active'} : {:class => 'inactive'} |
| 22 | |||
| 23 | html_options = html_options.merge(active_class) | 25 | html_options = html_options.merge(active_class) |
| 24 | 26 | locale = (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale) | |
| 25 | params[:locale] ||= I18n.locale | 27 | |
| 26 | 28 | link_to( | |
| 27 | link_to( | 29 | title, |
| 28 | title, { | 30 | content_path(path.sub(/^\//, ""), :locale => locale), |
| 29 | :controller => :content, | ||
| 30 | :action => :render_page, | ||
| 31 | :locale => params[:locale], | ||
| 32 | :page_path => (path.sub(/^\//, "").split("/") rescue "") | ||
| 33 | }, | ||
| 34 | html_options | 31 | html_options |
| 35 | ) | 32 | ) |
| 36 | end | 33 | end |
| 37 | 34 | ||
| 38 | def selected? controller_name | 35 | def selected? controller_name |
| 39 | if params[:controller] == controller_name | 36 | if params[:controller] == controller_name |
| 40 | return :class => "selected" | 37 | return :class => "selected" |
| 41 | end | 38 | end |
| 42 | end | 39 | end |
| 43 | 40 | ||
| 44 | def unlock_link | 41 | def unlock_link |
| 45 | message = "Are you sure you want to unlock?\n" + | 42 | message = "Are you sure you want to unlock?\n" \ |
| 46 | "Locked by #{@node.lock_owner.login}\n" + | 43 | "Locked by #{@node.lock_owner.login}\n" \ |
| 47 | "Last modified #{@page.updated_at.to_s(:db)}" | 44 | "Last modified #{@page.updated_at.to_fs(:db)}" |
| 48 | 45 | button_to 'Unlock', unlock_node_path(@node), | |
| 49 | link_to( | 46 | method: :put, |
| 50 | 'Unlock', unlock_node_path(@node), :method => :put, :confirm => message | 47 | form: { data: { confirm: message } } |
| 48 | end | ||
| 49 | |||
| 50 | def content_path(page_path = nil, options = {}) | ||
| 51 | if page_path.is_a?(Hash) | ||
| 52 | options = page_path | ||
| 53 | page_path = options.delete(:page_path) | ||
| 54 | end | ||
| 55 | locale = options[:locale] || params[:locale] || I18n.locale | ||
| 56 | options[:locale] = (locale.to_sym == I18n.default_locale) ? nil : locale | ||
| 57 | Rails.application.routes.url_helpers.content_path( | ||
| 58 | Array(page_path).join("/").sub(/^\//, ""), | ||
| 59 | options | ||
| 51 | ) | 60 | ) |
| 52 | end | 61 | end |
| 53 | 62 | end | |
| 54 | end \ No newline at end of file | ||
diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb index d889719..a054a2e 100644 --- a/app/helpers/nodes_helper.rb +++ b/app/helpers/nodes_helper.rb | |||
| @@ -4,6 +4,10 @@ module NodesHelper | |||
| 4 | if node.head | 4 | if node.head |
| 5 | node.head.title | 5 | node.head.title |
| 6 | else | 6 | else |
| 7 | if not node.draft or not node.draft.title | ||
| 8 | logger.error "Missing title in node #{node.id}" | ||
| 9 | return "NO TITLE" | ||
| 10 | end | ||
| 7 | node.draft.title | 11 | node.draft.title |
| 8 | end | 12 | end |
| 9 | end | 13 | end |
| @@ -24,14 +28,20 @@ module NodesHelper | |||
| 24 | def user_list | 28 | def user_list |
| 25 | User.all.map {|u| [u.login, u.id]} | 29 | User.all.map {|u| [u.login, u.id]} |
| 26 | end | 30 | end |
| 27 | 31 | ||
| 28 | def event_information | 32 | def event_information |
| 29 | if @node.event | 33 | if @node.event |
| 30 | "#{@node.event.start_time.to_s(:db)} - #{@node.event.end_time.to_s(:db)} > " \ | 34 | safe_join([ |
| 31 | "#{link_to 'show', event_path(@node.event)} " \ | 35 | "#{@node.event.start_time.to_fs(:db)} - #{@node.event.end_time.to_fs(:db)} > ", |
| 32 | "#{link_to 'edit', edit_event_path(@node.event)}" | 36 | link_to('show', event_path(@node.event)), |
| 37 | ' ', | ||
| 38 | link_to('edit', edit_event_path(@node.event)) | ||
| 39 | ]) | ||
| 33 | else | 40 | else |
| 34 | "no event attached > #{link_to 'add', new_event_path(:node_id => @node.id)}" | 41 | safe_join([ |
| 42 | 'no event attached > ', | ||
| 43 | link_to('add', new_event_path(:node_id => @node.id)) | ||
| 44 | ]) | ||
| 35 | end | 45 | end |
| 36 | end | 46 | end |
| 37 | end | 47 | end |
