Skip to content

Commit

Permalink
Replaced special modes starting with "*" by "+" to avoid filename pro…
Browse files Browse the repository at this point in the history
…blems. [#223 state:resolved]

You should rebuild test fixtures after this commit.
  • Loading branch information
gaspard committed Oct 7, 2008
1 parent 6fa15f1 commit 25bb91e
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 35 deletions.
16 changes: 8 additions & 8 deletions app/controllers/application.rb
Expand Up @@ -45,7 +45,7 @@ def render_404(exception)
if File.exists?("#{SITES_ROOT}/#{current_site.host}/public/#{prefix}/404.html")
render :file => "#{SITES_ROOT}/#{current_site.host}/public/#{prefix}/404.html", :status => '404 Not Found'
else
render_and_cache :mode => '*notFound', :format => 'html', :cache_url => "/#{prefix}/404.html", :status => '404 Not Found'
render_and_cache :mode => '+notFound', :format => 'html', :cache_url => "/#{prefix}/404.html", :status => '404 Not Found'
end
end
format.all { render :nothing => true, :status => "404 Not Found" }
Expand Down Expand Up @@ -264,8 +264,8 @@ def template_url(opts={})
klasses = []
klass.kpath.split(//).each_index { |i| klasses << klass.kpath[0..i] }

# FIXME: is searching in all skins a good idea ? I think not. Only searching for special modes '*popupLayout', '*login', etc.
if mode && mode[0..0] == '*'
# FIXME: is searching in all skins a good idea ? I think not. Only searching for special modes '+popupLayout', '+login', etc.
if mode && mode[0..0] == '+'
template = secure(Template) { Template.find(:first,
:conditions => ["tkpath IN (?) AND format = ? AND mode #{mode ? '=' : 'IS'} ? AND template_contents.node_id = nodes.id", klasses, format, mode],
:from => "nodes, template_contents",
Expand Down Expand Up @@ -314,7 +314,7 @@ def template_url(opts={})
skin_helper = response.template
res = ZafuParser.new_with_url(skin_path, :helper => skin_helper).render

if session[:dev] && mode != '*popupLayout'
if session[:dev] && mode != '+popupLayout'
# add template edit buttons
used_nodes = []
zafu_nodes = []
Expand Down Expand Up @@ -428,7 +428,7 @@ def template_url_for_asset(opts)
data_path(asset, :mode => mode)
end

# opts should contain :current_template and :src. The source is a path like 'default/Node-*index'
# opts should contain :current_template and :src. The source is a path like 'default/Node-+index'
# ('skin/template/path'). If the path starts with a slash, the skin_name in the path is searched first. Otherwise,
# the current skin is searched first.
# <r:include template='Node'/>
Expand Down Expand Up @@ -490,7 +490,7 @@ def save_erb_to_url(template, template_url)

# TODO: test
def fullpath_from_template_url(template_url=params[:t_url])
if template_url =~ /\A\.|[^\w\*\._\-\/]/
if template_url =~ /\A\.|[^\w\+\._\-\/]/
raise Zena::AccessViolation.new("'template_url' contains illegal characters : #{template_url.inspect}")
end

Expand Down Expand Up @@ -793,12 +793,12 @@ def render_errors(errs=@errors)
# and then into default. This action is also responsible for setting a default @title_for_layout.
def admin_layout
@title_for_layout ||= "#{params[:controller]}/#{params[:action]}"
template_url(:mode=>'*adminLayout')
template_url(:mode=>'+adminLayout')
end

# TODO: test
def popup_layout
template_url(:mode=>'*popupLayout')
template_url(:mode=>'+popupLayout')
end

def format_date(thedate, theformat = nil, tz_name=nil, lang=visitor.lang)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/nodes_controller.rb
Expand Up @@ -27,7 +27,7 @@ class NodesController < ApplicationController
def index
@node = current_site.root_node
respond_to do |format|
format.html { render_and_cache :mode => '*index' }
format.html { render_and_cache :mode => '+index' }
format.xml { render :xml => @node.to_xml }
end
end
Expand All @@ -49,7 +49,7 @@ def not_found
def search
do_search
respond_to do |format|
format.html { render_and_cache :mode => '*search', :cache => false }
format.html { render_and_cache :mode => '+search', :cache => false }
format.js
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/session_controller.rb
Expand Up @@ -7,7 +7,7 @@ def new
respond_to do |format|
format.html do
@node = visitor.site.root_node
render_and_cache :mode => '*login'
render_and_cache :mode => '+login'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/versions_controller.rb
Expand Up @@ -73,7 +73,7 @@ def edit
end

def custom_tab
render :file => template_url(:mode=>'*edit', :format=>'html'), :layout=>false
render :file => template_url(:mode=>'+edit', :format=>'html'), :layout=>false
rescue ActiveRecord::RecordNotFound
render :inline => "no custom form for this class (#{@node.klass})"
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/template.rb
Expand Up @@ -30,7 +30,7 @@ def version_class
def filter_attributes(attributes)
content = version.content
new_name = attributes['name'] || (new_record? ? attributes['v_title'] : nil) # only set name from version title on creation
if new_name =~ /^([A-Z][a-zA-Z\*]+?)(-(([a-zA-Z_\*]*)(-([a-zA-Z_]+)|))|)(\.|\Z)/
if new_name =~ /^([A-Z][a-zA-Z]+?)(-(([a-zA-Z_\+]*)(-([a-zA-Z_]+)|))|)(\.|\Z)/
attributes['c_klass' ] ||= $1
attributes['c_mode' ] ||= $4
attributes['c_format'] ||= ($6 || 'html')
Expand All @@ -57,7 +57,7 @@ def document_before_validation
content.format = 'html' if content.format.blank?
self[:name] = name_from_content(:format => content.format, :mode => content.mode, :klass => content.klass)

if version.text.blank? && content.format == 'html' && content.mode != '*edit'
if version.text.blank? && content.format == 'html' && content.mode != '+edit'
# set a default text

if content.klass == 'Node'
Expand All @@ -75,6 +75,7 @@ def document_before_validation
</r:void>
<r:javascripts list='prototype,effects,zena'/>
<r:uses_calendar/>
</head>
<body>
</body>
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions db/migrate/000_zena/045_avoid_star_in_templates.rb
@@ -0,0 +1,13 @@
class AvoidStarInTemplates < ActiveRecord::Migration
def self.up
execute "UPDATE #{TemplateContent.table_name} SET mode = REPLACE(mode, '*', '+')"
execute "UPDATE #{Node.table_name} SET name = REPLACE(name, '*', '+')"
execute "UPDATE #{Version.table_name} SET title = REPLACE(title, '*', '+')"
end

def self.down
execute "UPDATE #{TemplateContent.table_name} SET mode = REPLACE(mode, '+', '*')"
execute "UPDATE #{Node.table_name} SET name = REPLACE(name, '+', '*')"
execute "UPDATE #{Version.table_name} SET title = REPLACE(title, '+', '*')"
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -160,7 +160,6 @@
end

create_table "nodes", :force => true do |t|
t.column "zip", :integer
t.column "type", :string, :limit => 32
t.column "event_at", :datetime
t.column "kpath", :string, :limit => 16
Expand All @@ -184,6 +183,7 @@
t.column "custom_base", :boolean, :default => false
t.column "basepath", :text
t.column "site_id", :integer
t.column "zip", :integer
t.column "project_id", :integer
t.column "position", :float, :default => 0.0
t.column "vclass_id", :integer
Expand Down
2 changes: 1 addition & 1 deletion lib/core_ext/string.rb
Expand Up @@ -56,7 +56,7 @@ def url_name!
gsub!(s, rep)
end
end
gsub!(/[^a-zA-Z0-9\.\-\* ]/," ")
gsub!(/[^a-zA-Z0-9\.\-\+ ]/," ")
replace(split.join(" "))
gsub!(/ (.)/) { $1.upcase }
self
Expand Down
10 changes: 5 additions & 5 deletions test/sites/zena/nodes.yml
Expand Up @@ -305,22 +305,22 @@ Node_zafu:

Node_admin_layout_zafu:
class: Template
name: Node-*adminLayout
name: Node-+adminLayout
parent: default

Node_index_zafu:
class: Template
name: Node-*index
name: Node-+index
parent: default

Node_not_found_zafu:
class: Template
name: Node-*notFound
name: Node-+notFound
parent: default

Node_popup_layout_zafu:
class: Template
name: Node-*popupLayout
name: Node-+popupLayout
parent: default

notes_zafu:
Expand All @@ -340,7 +340,7 @@ Project_zafu:

Node_login_zafu:
class: Template
name: Node-*login
name: Node-+login
parent: default

translations:
Expand Down
12 changes: 6 additions & 6 deletions test/sites/zena/template_contents.yml
Expand Up @@ -3,7 +3,7 @@ Node_search_zafu:
skin_name: default
format: html
tkpath: N
mode: "*search"
mode: "+search"
klass: Node

Node_zafu:
Expand All @@ -19,31 +19,31 @@ Node_admin_layout_zafu:
skin_name: default
format: html
tkpath: N
mode: "*adminLayout"
mode: "+adminLayout"
klass: Node

Node_index_zafu:
node: Node_index_zafu
skin_name: default
format: html
tkpath: N
mode: "*index"
mode: "+index"
klass: Node

Node_not_found_zafu:
node: Node_not_found_zafu
skin_name: default
format: html
tkpath: N
mode: "*notFound"
mode: "+notFound"
klass: Node

Node_popup_layout_zafu:
node: Node_popup_layout_zafu
skin_name: default
format: html
tkpath: N
mode: "*popupLayout"
mode: "+popupLayout"
klass: Node

notes_zafu:
Expand Down Expand Up @@ -91,7 +91,7 @@ Node_login_zafu:
skin_name: default
format: html
tkpath: N
mode: "*login"
mode: "+login"
klass: Node

Node_test_zafu:
Expand Down
12 changes: 6 additions & 6 deletions test/sites/zena/versions.yml
Expand Up @@ -460,7 +460,7 @@ Node_search_zafu_en:
node: Node_search_zafu
user: tiger
text: |
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-*search.zafu") do |l| %> <%= l %><% end %>
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-+search.zafu") do |l| %> <%= l %><% end %>

style_css_en:
type: TextDocumentVersion
Expand All @@ -481,28 +481,28 @@ Node_admin_layout_zafu_en:
node: Node_admin_layout_zafu
user: tiger
text: |
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-*adminLayout.zafu") do |l| %> <%= l %><% end %>
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-+adminLayout.zafu") do |l| %> <%= l %><% end %>

Node_index_zafu_en:
type: TemplateVersion
node: Node_index_zafu
user: tiger
text: |
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-*index.zafu") do |l| %> <%= l %><% end %>
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-+index.zafu") do |l| %> <%= l %><% end %>

Node_not_found_zafu_en:
type: TemplateVersion
node: Node_not_found_zafu
user: tiger
text: |
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-*notFound.zafu") do |l| %> <%= l %><% end %>
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-+notFound.zafu") do |l| %> <%= l %><% end %>

Node_popup_layout_zafu_en:
type: TemplateVersion
node: Node_popup_layout_zafu
user: tiger
text: |
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-*popupLayout.zafu") do |l| %> <%= l %><% end %>
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-+popupLayout.zafu") do |l| %> <%= l %><% end %>

Node_test_en:
type: TemplateVersion
Expand Down Expand Up @@ -530,7 +530,7 @@ Node_login_zafu_en:
node: Node_login_zafu
user: tiger
text: |
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-*login.zafu") do |l| %> <%= l %><% end %>
<% File.foreach("#{RAILS_ROOT}/db/init/base/skins/default/Node-+login.zafu") do |l| %> <%= l %><% end %>

translations_de:
type: TextDocumentVersion
Expand Down
4 changes: 2 additions & 2 deletions test/unit/node_test.rb
Expand Up @@ -582,9 +582,9 @@ def test_all_children

def test_url_name
assert_equal "salutJEcrisAujourdHui", "salut j'écris: Aujourd'hui ".url_name!
assert_equal "a--Bab*Mol", " à,--/ bab* mol".url_name!
assert_equal "a--BabMol", " à,--/ bab* mol".url_name!
assert_equal "07.11.2006-mardiProchain", "07.11.2006-mardi_prochain".url_name!
assert_equal "Node-*login", "Node-*login".url_name!
assert_equal "Node-+login", "Node-+login".url_name!
end

def test_tags
Expand Down

0 comments on commit 25bb91e

Please sign in to comment.