diff options
| author | erdgeist <erdgeist@bauklotz.local> | 2009-03-10 19:59:02 +0100 |
|---|---|---|
| committer | erdgeist <erdgeist@bauklotz.local> | 2009-03-10 19:59:02 +0100 |
| commit | d6049aeffc7de43393a9a7a1d2f95f26422a046f (patch) | |
| tree | 7036f509aa4f4a518a00ddb0e12fe8a6eb4d563a /app | |
| parent | 3b3158199f147646348fae0008d3f63062967a87 (diff) | |
| parent | 14ada6b405dac2bea27a2959f6f73a7398776b0b (diff) | |
Merge branch 'master' of ssh://git@svn.medienhaus.udk-berlin.de/usr/local/git/cccms
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/content_controller.rb | 3 | ||||
| -rw-r--r-- | app/controllers/nodes_controller.rb | 12 | ||||
| -rw-r--r-- | app/helpers/link_helper.rb | 13 | ||||
| -rw-r--r-- | app/models/node.rb | 5 | ||||
| -rw-r--r-- | app/models/page.rb | 67 | ||||
| -rw-r--r-- | app/views/layouts/admin.html.erb | 3 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 9 | ||||
| -rw-r--r-- | app/views/nodes/_preview.html.erb | 5 | ||||
| -rw-r--r-- | app/views/nodes/edit.html.erb | 7 | ||||
| -rw-r--r-- | app/views/nodes/index.html.erb | 4 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 6 |
11 files changed, 78 insertions, 56 deletions
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 706cfcd..d548a34 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb | |||
| @@ -10,7 +10,7 @@ class ContentController < ApplicationController | |||
| 10 | 10 | ||
| 11 | @page = Node.find_page(path) | 11 | @page = Node.find_page(path) |
| 12 | 12 | ||
| 13 | if @page | 13 | if @page and @page.public? |
| 14 | template = @page.valid_template | 14 | template = @page.valid_template |
| 15 | 15 | ||
| 16 | render( | 16 | render( |
| @@ -25,4 +25,5 @@ class ContentController < ApplicationController | |||
| 25 | end | 25 | end |
| 26 | 26 | ||
| 27 | end | 27 | end |
| 28 | |||
| 28 | end | 29 | end |
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 81ead62..0c961b7 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -32,7 +32,7 @@ class NodesController < ApplicationController | |||
| 32 | 32 | ||
| 33 | if parent and @node.save | 33 | if parent and @node.save |
| 34 | @node.move_to_child_of parent | 34 | @node.move_to_child_of parent |
| 35 | redirect_to(@node) | 35 | redirect_to(edit_node_path(@node)) |
| 36 | else | 36 | else |
| 37 | @node.errors.add("Parent node") | 37 | @node.errors.add("Parent node") |
| 38 | render :action => :new | 38 | render :action => :new |
| @@ -40,7 +40,15 @@ class NodesController < ApplicationController | |||
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | def show | 42 | def show |
| 43 | @nodes = Node.find(params[:id]).children | 43 | @page = Node.find(params[:id]).draft |
| 44 | |||
| 45 | if @page | ||
| 46 | template = @page.valid_template | ||
| 47 | render( | ||
| 48 | :file => template, | ||
| 49 | :layout => "application" | ||
| 50 | ) | ||
| 51 | end | ||
| 44 | end | 52 | end |
| 45 | 53 | ||
| 46 | def edit | 54 | def edit |
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 68586c1..33d8a06 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb | |||
| @@ -1,11 +1,14 @@ | |||
| 1 | module LinkHelper | 1 | module LinkHelper |
| 2 | 2 | ||
| 3 | def link_to_path path | 3 | def link_to_path title, path |
| 4 | url_for( | 4 | params[:locale] ||= I18n.locale |
| 5 | |||
| 6 | link_to( | ||
| 7 | title, | ||
| 5 | :controller => :content, | 8 | :controller => :content, |
| 6 | :action => :render_page, | 9 | :action => :render_page, |
| 7 | :language => I18n.locale, | 10 | :locale => params[:locale], |
| 8 | :page_path => path | 11 | :page_path => path |
| 9 | ) | 12 | ) |
| 10 | end | 13 | end |
| 11 | 14 | ||
diff --git a/app/models/node.rb b/app/models/node.rb index 7f2bca6..d2db4ba 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -59,7 +59,6 @@ class Node < ActiveRecord::Base | |||
| 59 | def create_new_draft user | 59 | def create_new_draft user |
| 60 | empty_page = self.pages.new | 60 | empty_page = self.pages.new |
| 61 | empty_page.user = user | 61 | empty_page.user = user |
| 62 | |||
| 63 | empty_page.clone_attributes_from self.head | 62 | empty_page.clone_attributes_from self.head |
| 64 | 63 | ||
| 65 | self.draft = empty_page | 64 | self.draft = empty_page |
| @@ -70,11 +69,9 @@ class Node < ActiveRecord::Base | |||
| 70 | def publish_draft! | 69 | def publish_draft! |
| 71 | if self.draft | 70 | if self.draft |
| 72 | self.head = self.draft | 71 | self.head = self.draft |
| 72 | self.head.save! | ||
| 73 | self.draft = nil | 73 | self.draft = nil |
| 74 | self.save! | 74 | self.save! |
| 75 | |||
| 76 | self.head.published_at = Time.now | ||
| 77 | self.head.save! | ||
| 78 | else | 75 | else |
| 79 | nil | 76 | nil |
| 80 | end | 77 | end |
diff --git a/app/models/page.rb b/app/models/page.rb index a4817a3..af820e3 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | require 'xml' | ||
| 2 | |||
| 1 | class Page < ActiveRecord::Base | 3 | class Page < ActiveRecord::Base |
| 2 | 4 | ||
| 3 | PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) | 5 | PUBLIC_TEMPLATE_PATH = File.join(%w(custom page_templates public)) |
| @@ -17,7 +19,7 @@ class Page < ActiveRecord::Base | |||
| 17 | before_save :rewrite_links_in_body | 19 | before_save :rewrite_links_in_body |
| 18 | 20 | ||
| 19 | # Security | 21 | # Security |
| 20 | attr_accessible :title, :abstract, :body, :template_name | 22 | attr_accessible :title, :abstract, :body, :template_name, :published_at |
| 21 | 23 | ||
| 22 | # Class Methods | 24 | # Class Methods |
| 23 | 25 | ||
| @@ -57,24 +59,6 @@ class Page < ActiveRecord::Base | |||
| 57 | end | 59 | end |
| 58 | 60 | ||
| 59 | # Instance Methods | 61 | # Instance Methods |
| 60 | |||
| 61 | def clone_attributes_from page | ||
| 62 | return nil unless page | ||
| 63 | |||
| 64 | self.tag_list = page.tag_list.join(", ") | ||
| 65 | |||
| 66 | locale_before = I18n.locale | ||
| 67 | |||
| 68 | I18n.available_locales.each do |l| | ||
| 69 | next if l == :root | ||
| 70 | I18n.locale = l | ||
| 71 | self.title = page.title | ||
| 72 | self.abstract = page.abstract | ||
| 73 | self.body = page.body | ||
| 74 | end | ||
| 75 | |||
| 76 | I18n.locale = locale_before | ||
| 77 | end | ||
| 78 | 62 | ||
| 79 | def public_template_path | 63 | def public_template_path |
| 80 | File.join(PUBLIC_TEMPLATE_PATH, template_name) | 64 | File.join(PUBLIC_TEMPLATE_PATH, template_name) |
| @@ -104,8 +88,13 @@ class Page < ActiveRecord::Base | |||
| 104 | def clone_attributes_from page | 88 | def clone_attributes_from page |
| 105 | return nil unless page | 89 | return nil unless page |
| 106 | 90 | ||
| 91 | # Clone untranslated attributes | ||
| 92 | |||
| 107 | self.tag_list = page.tag_list.join(", ") | 93 | self.tag_list = page.tag_list.join(", ") |
| 108 | self.template_name = page.template_name | 94 | self.template_name = page.template_name |
| 95 | self.published_at = page.published_at | ||
| 96 | |||
| 97 | # Clone translated attributes | ||
| 109 | 98 | ||
| 110 | locale_before = I18n.locale | 99 | locale_before = I18n.locale |
| 111 | 100 | ||
| @@ -120,27 +109,35 @@ class Page < ActiveRecord::Base | |||
| 120 | I18n.locale = locale_before | 109 | I18n.locale = locale_before |
| 121 | end | 110 | end |
| 122 | 111 | ||
| 112 | def public? | ||
| 113 | published_at.nil? ? true : published_at < Time.now | ||
| 114 | end | ||
| 115 | |||
| 123 | private | 116 | private |
| 124 | 117 | ||
| 125 | def rewrite_links_in_body | 118 | def rewrite_links_in_body |
| 126 | if self.body | 119 | begin |
| 127 | tmp_body = "<div>#{self.body}</div>" | 120 | if self.body |
| 128 | xml_string = XML::Parser.string( tmp_body ) | 121 | tmp_body = "<div>#{self.body}</div>" |
| 129 | xml_doc = xml_string.parse | 122 | xml_string = XML::Parser.string( tmp_body ) |
| 130 | links = xml_doc.find("a[not(starts-with(@href, 'http://'))]") | 123 | xml_doc = xml_string.parse |
| 131 | 124 | links = xml_doc.find("//a[not(starts-with(@href, 'http://'))]") | |
| 132 | locales = I18n.available_locales.reject {|l| l == :root} | 125 | |
| 133 | 126 | locales = I18n.available_locales.reject {|l| l == :root} | |
| 134 | links.each do |link| | 127 | |
| 135 | unless locales.include? link[:href].slice(1,2).to_sym | 128 | links.each do |link| |
| 136 | link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") | 129 | unless locales.include? link[:href].slice(1,2).to_sym |
| 130 | link[:href] = link[:href].sub(/^\//, "/#{I18n.locale}/") | ||
| 131 | end | ||
| 137 | end | 132 | end |
| 133 | |||
| 134 | tmp_body = xml_doc.to_s.gsub(/(\n\<div\>|\<\/div\>\n)/, "") | ||
| 135 | tmp_body.gsub!("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "") | ||
| 136 | |||
| 137 | self.body = tmp_body | ||
| 138 | end | 138 | end |
| 139 | 139 | rescue | |
| 140 | tmp_body = xml_doc.to_s.gsub(/(\n\<div\>|\<\/div\>\n)/, "") | 140 | nil |
| 141 | tmp_body.gsub!("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "") | ||
| 142 | |||
| 143 | self.body = tmp_body | ||
| 144 | end | 141 | end |
| 145 | end | 142 | end |
| 146 | 143 | ||
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 840c37c..bede781 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb | |||
| @@ -20,7 +20,8 @@ | |||
| 20 | theme_advanced_buttons2 : "", | 20 | theme_advanced_buttons2 : "", |
| 21 | theme_advanced_buttons3 : "", | 21 | theme_advanced_buttons3 : "", |
| 22 | extended_valid_elements : "aggregate[tags|limit|order_by|order_direction|partial]", | 22 | extended_valid_elements : "aggregate[tags|limit|order_by|order_direction|partial]", |
| 23 | relative_urls : false | 23 | relative_urls : false, |
| 24 | entity_encoding : "raw" | ||
| 24 | }); | 25 | }); |
| 25 | </script> | 26 | </script> |
| 26 | </head> | 27 | </head> |
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index be7e044..e6317fd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb | |||
| @@ -12,10 +12,11 @@ | |||
| 12 | <![endif]--> | 12 | <![endif]--> |
| 13 | </head> | 13 | </head> |
| 14 | <body> | 14 | <body> |
| 15 | <%= render :partial => 'nodes/preview' if params[:action] == "show" %> | ||
| 15 | <div id="logo"> | 16 | <div id="logo"> |
| 16 | <a href="index.html" title="Startseite"><img src="/images/chaosknot.gif" alt="Chaosknoten" /></a> | 17 | <a href="index.html" title="Startseite"><img src="/images/chaosknot.gif" alt="Chaosknoten" /></a> |
| 17 | </div> | 18 | </div> |
| 18 | <!-- HEAD --> | 19 | <!-- HEAD --> |
| 19 | <div id="header"> | 20 | <div id="header"> |
| 20 | <div id="yellow"> | 21 | <div id="yellow"> |
| 21 | </div> | 22 | </div> |
| @@ -25,19 +26,19 @@ | |||
| 25 | <div id="topnav"> | 26 | <div id="topnav"> |
| 26 | <ul id="navlist"> | 27 | <ul id="navlist"> |
| 27 | <li> | 28 | <li> |
| 28 | <a href="<%= params[:locale] %>/club">Kennenlernen</a> | 29 | <%= link_to_path "Kennenlernen", "club" %> |
| 29 | </li> | 30 | </li> |
| 30 | <li> | 31 | <li> |
| 31 | • | 32 | • |
| 32 | </li> | 33 | </li> |
| 33 | <li> | 34 | <li> |
| 34 | <a href="<%= params[:locale] %>/support">Unterstützen</a> | 35 | <%= link_to_path "Unterstützen", "support" %> |
| 35 | </li> | 36 | </li> |
| 36 | <li> | 37 | <li> |
| 37 | • | 38 | • |
| 38 | </li> | 39 | </li> |
| 39 | <li> | 40 | <li> |
| 40 | <a href="<%= params[:locale] %>/contact">Erreichen</a> | 41 | <%= link_to_path "Erreichen", "contact" %> |
| 41 | </li> | 42 | </li> |
| 42 | <% if current_user %> | 43 | <% if current_user %> |
| 43 | <li> | 44 | <li> |
diff --git a/app/views/nodes/_preview.html.erb b/app/views/nodes/_preview.html.erb new file mode 100644 index 0000000..e8d7b9f --- /dev/null +++ b/app/views/nodes/_preview.html.erb | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | <div id="preview_disclaimer"> | ||
| 2 | <strong>Preview draft.</strong> | ||
| 3 | Clicking on links will redirected you to the public site. | ||
| 4 | <%= link_to 'Back to admin interface', nodes_path %> | ||
| 5 | </div \ No newline at end of file | ||
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index 929bbf6..2dade0f 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb | |||
| @@ -13,9 +13,14 @@ | |||
| 13 | <%= f.error_messages %> | 13 | <%= f.error_messages %> |
| 14 | 14 | ||
| 15 | <% fields_for @draft do |d| %> | 15 | <% fields_for @draft do |d| %> |
| 16 | |||
| 17 | <p> | ||
| 18 | <%= d.label :published_at %><br /> | ||
| 19 | <%= d.datetime_select :published_at %> | ||
| 20 | </p> | ||
| 16 | <p> | 21 | <p> |
| 17 | <%= d.label :template_name %> | 22 | <%= d.label :template_name %> |
| 18 | <%= d.select :template_name, custom_page_templates %> | 23 | <%= d.select :template_name, custom_page_templates, {:prompt => 'Select Template'} %> |
| 19 | </p> | 24 | </p> |
| 20 | <p> | 25 | <p> |
| 21 | <%= d.label :title %><br /> | 26 | <%= d.label :title %><br /> |
diff --git a/app/views/nodes/index.html.erb b/app/views/nodes/index.html.erb index 833ffed..a2a42b1 100644 --- a/app/views/nodes/index.html.erb +++ b/app/views/nodes/index.html.erb | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | <th class="path">Path</th> | 11 | <th class="path">Path</th> |
| 12 | <th class="actions">Actions</th> | 12 | <th class="actions">Actions</th> |
| 13 | <th class="editor">Locked by</th> | 13 | <th class="editor">Locked by</th> |
| 14 | <th class="revision">Rev.</th> | ||
| 14 | </tr> | 15 | </tr> |
| 15 | <% @nodes.each do |node| %> | 16 | <% @nodes.each do |node| %> |
| 16 | <tr class="<%= cycle("even", "odd") %>"> | 17 | <tr class="<%= cycle("even", "odd") %>"> |
| @@ -29,6 +30,9 @@ | |||
| 29 | <td> | 30 | <td> |
| 30 | <%= "#{node.draft.user.login}" if node.draft && node.draft.user %> | 31 | <%= "#{node.draft.user.login}" if node.draft && node.draft.user %> |
| 31 | </td> | 32 | </td> |
| 33 | <td> | ||
| 34 | <%= node.head.revision if node.head %> | ||
| 35 | </td> | ||
| 32 | </tr> | 36 | </tr> |
| 33 | <% end %> | 37 | <% end %> |
| 34 | </table> | 38 | </table> |
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb index dd37c28..67dd7fc 100644 --- a/app/views/nodes/show.html.erb +++ b/app/views/nodes/show.html.erb | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | <h1>Node</h1> | 1 | <h1>Node</h1> |
| 2 | 2 | ||
| 3 | <%= @node.unique_name %> | 3 | There is no draft to preview. Click <%= link_to 'edit', edit_node_path %> to |
| 4 | 4 | create one or view the currently | |
| 5 | <%= link_to 'Edit', edit_node_path %> \ No newline at end of file | 5 | <%= link_to_path 'published version', @node.unique_path %>. \ No newline at end of file |
