Skip to content

Commit

Permalink
Renamed 'ancestor?' method to 'is_ancestor?'.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 8, 2011
1 parent a489c9a commit 40d46b5
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 51 deletions.
4 changes: 4 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* Fixed block edit with ajax ([edit] method).
* Removed fulltext search (no more MyISAM tables).
* Fixed SQLiss scoping in queries like "Job:project" (added kpath filter).
* Fixed Zafu calendar and timezones in dates.
* Added 'foreach' method (paginated looping in SQLiss query) for console.
* Added 'count' method (count objects with SQLiss query) for console.
* Added support for scripts with Zena::Console.

== 1.0.0.rc2 2011-02-14

Expand Down
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def self.author_proc
:m_text => String, :m_title => String, :m_author => String,
:id => {:class => Number, :method => 'zip'},
:skin => 'Skin', :ref_lang => String,
:visitor => 'User', [:ancestor?, Node] => Boolean,
:visitor => 'User', [:is_ancestor?, Node] => Boolean,
:comments_count => Number,
:v => {:class => 'Version', :method => 'version'},
:version => 'Version', :v_status => Number, :v_lang => String,
Expand Down
2 changes: 1 addition & 1 deletion app/views/zafu/default/Node.zafu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div id='visitor' do='visitor_link'/>
<div id='search' do='search_box' type='search'/>
<ol id='menu' do='root' do='pages'>
<li do='each' on_if='ancestor?(main)' do='link'/>
<li do='each' on_if='is_ancestor?(main)' do='link'/>
</ol>
</div>
<div id='container'>
Expand Down
2 changes: 1 addition & 1 deletion db/init/base/skins/default/Node.zafu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div id='visitor' do='visitor_link'/>
<div id='search' do='search_box' type='search'/>
<ol id='menu' do='root' do='pages'>
<li do='each' on_if='ancestor?(main)' do='link'/>
<li do='each' on_if='is_ancestor?(main)' do='link'/>
</ol>
</div>
<div id='container'>
Expand Down
2 changes: 1 addition & 1 deletion doc/zafu_changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ start_node: "start"
v_title: "title"
"<r:if kind_of='Section'": "<r:Section?>"
"<r:text/>": "mat"
"on_if_node='ancestor'": "on_if='ancestor?(main)'"
"on_if_node='ancestor'": "on_if='is_ancestor?(main)'"
"<div do='admin_links'/>": "<ol class='admin_links' do='admin_links'>
<li do='each' do='show'><a href='#'>do this</a></li>
</ol>"
Expand Down
5 changes: 5 additions & 0 deletions lib/zena.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ def init

require_ordered_dependencies

# This is needed for idx fields taming (lock table content in OR clause).
# Must come after 'require_ordered_dependencies' so that AfterCommit is loaded
# before first DB usage.
Zena::Db.insert_dummy_ids

load_plugins if RAILS_ROOT != Zena::ROOT
include_modules
Bricks.load_bricks
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/ancestry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def z_ancestors
end

# Return true if the current node is an ancestor for the given child
def ancestor?(child)
def is_ancestor?(child)
child.fullpath =~ %r{\A#{fullpath}}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def display_calendar
if opts[:size] == :tiny
add_block %Q{<r:cell><em do='link' date='#{format_date(date, "%Y-%m-%d")}' do='date' format='%e'/></r:cell>}
else
add_block "<r:cell><span do='date' format='%e'/><ol><li do='each' do='link' eval='title.limit(10)'/></ol></r:cell>"
add_block "<r:cell><p do='date' format='%e'/><ol><li do='each' do='link' eval='title.limit(10)'/></ol></r:cell>"
end
cell_block = descendant('cell')
end
Expand Down
26 changes: 25 additions & 1 deletion public/javascripts/zena.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,6 @@ Zena.m_toggle = function(id) {
s.src = s.src;
});
}
fleXenv.updateScrollBars();
}

var pm_counter = 1;
Expand All @@ -889,4 +888,29 @@ Zena.plus_minus = function(elem, start, plus, minus) {
Element.insert(elem.previous(), {bottom:trigger_tag});
Element.replace(elem, new_tag);
}
}

Zena.read_cookie = function(name, def) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return def;
}

Zena.write_cookie = function(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

Zena.delete_cookie = function(name) {
Zena.write_cookie(name,"",-1);
}
47 changes: 23 additions & 24 deletions public/stylesheets/calendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,32 @@
.tinycal .body td.sun, .tinycal .body td.sun a { color:#35950B; }
.tinycal .body td.sunother, .tinycal .body td.sunother a { color:#C8DEC1; }


/* LARGE CALENDAR */
.largecal .title { display:table; margin:auto; background:white; margin-bottom:0.5em; font-size:1.3em; }
.largecal .title a { color:#655; font-size: 1em; font-family: Georgia, Times, serif;}
.largecal .title span { padding:0 6px; display:block; float:left; text-align:center;}
.largecal .title .date { width:150px; }
.largecal table { border:1px solid #655; margin:auto; border-collapse:separate; line-height:1em; clear:left;}
.largecal .head td { border-left:1px solid #836C6C; background: #655; color: #fff; width:14%; height:0.8em; text-align:center; padding:0.4em 3px; }
.largecal .head td:first-child {border-left-width:0;}
.largecal .body td { background: #ffd; width:14%; height:3.4em; padding:3px; vertical-align:top; font-style:italic; text-align:left; color:#999;
border:1px solid #DDDBC1; border-width:1px 0 0 1px; font-size:0.8em;}
.largecal .body a { font-weight:normal; font-style:normal;}
.largecal .body td:first-child {border-left-width:0;}
#cal h3 { display:table; margin:auto; font-size:1.3em; }
#cal h3 p { color:#655; font-family: Georgia, Times, serif; margin-bottom:0.5em; display:table; float:left; width:20em; text-align:center;}
#cal h3 a { padding:0 6px; display:block; float:left;}
.largecal { border:1px solid #655; margin:auto; border-collapse:separate; line-height:1em; clear:left;}
.largecal th { border-left:1px solid #836C6C; background: #655; color: #fff; width:14%; height:0.8em; text-align:center; padding:0.4em 3px; }
.largecal th:first-child {border-left-width:0;}
.largecal td { background: #ffd; width:14%; min-height:3.4em; padding:3px; vertical-align:top; font-style:italic; text-align:left; color:#999;
border:1px solid #DDDBC1; border-width:1px 0 0 1px; font-size:10px;}
.largecal a { font-weight:normal; font-style:normal;}
.largecal td:first-child {border-left-width:0;}

.largecal .body .other { background:#DDDBC1;}
.largecal .body .today { font-weight:bold; color:black; background:#DCF6FF; margin:0;}
.largecal .body .sun, .largecal .body .sat { background:#E6FFDC;}
.largecal .head .sun, .largecal .head .sat { background:#636D5E;}
.largecal .body .ref { background:white;}
.largecal .body .sunother, .largecal .body .satother { background:#C8DEC1;}
.largecal .body .suntoday, .largecal .body .sattoday { font-weight:bold; color:black; background:#C7FFC3;}
.largecal .other { background:#DDDBC1;}
.largecal .today { font-weight:bold; color:black; background:#DCF6FF; margin:0;}
.largecal .sun, .largecal .sat { background:#E6FFDC;}
.largecal th.sun, .largecal th.sat { background:#636D5E;}
.largecal .ref { background:white;}
.largecal .sunother, .largecal .satother { background:#C8DEC1;}
.largecal .suntoday, .largecal .sattoday { font-weight:bold; color:black; background:#C7FFC3;}

.largecal .body div { margin:2px; margin-left:1.2em; font-style:normal; font-weight:normal; font-size:1.1em; }
.largecal .body div a { padding:1px;}
.largecal .body div a:hover { text-decoration:underline; }
.largecal .body span { float:left; }
.largecal .body ol { margin-left:0px; display:block; list-style:none;}
.largecal .body li { margin:0;}
.largecal p { margin:0;}
.largecal ol { margin:0; list-style:none;}
.largecal li { margin:0; line-height:12px}
.largecal li:first-child { border-top:0;}
.largecal li { border-top:1px solid #aaa;}

.assign .body td { padding:0;}
.assign .body ol { border-left:1px solid #ddd;}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def test_search_klass

def test_search_q
login(:anon)
get 'search', 'q' => 'zen'
get 'search', 'q' => 'wild'
assert nodes = assigns(:nodes)
assert_equal [nodes_id(:zena)], nodes.map {|r| r.id}
end
Expand Down
10 changes: 5 additions & 5 deletions test/integration/zafu_compiler/calendar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ calendar:
context:
date: "2006-03-18"
src: "<div do='calendar' attr='date' select='posts where #{cal_start} <= date and date < #{cal_end} in project'/>"
res: "/<td><span>15</span><ol><li><a href='/oo/projects-list/Clean-Water-project/post27.html'>parc openi…</a></li></ol><\/td>.*<td class='sat ref'>18</td>/"
res: "/<td><p>15</p><ol><li><a href='/oo/projects-list/Clean-Water-project/post27.html'>parc openi…</a></li></ol><\/td>.*<td class='sat ref'>18</td>/"

calendar_tz:
context:
date: "2006-03-18"
src: "<div do='calendar' attr='date' tz='America/New_York' select='posts where #{cal_start} <= date and date < #{cal_end} in project'/>"
res: "/<td><span>14</span><ol><li><a href='/oo/projects-list/Clean-Water-project/post27.html'>parc openi…</a></li></ol><\/td>.*<td class='sat ref'>18</td>/"
res: "/<td><p>14</p><ol><li><a href='/oo/projects-list/Clean-Water-project/post27.html'>parc openi…</a></li></ol><\/td>.*<td class='sat ref'>18</td>/"

calendar_with_blocks:
context:
Expand All @@ -25,14 +25,14 @@ calendar_with_blocks:
<r:link date='#{date.advance(:months =&gt; -1).strftime(\"%Y-%m-%d\", tz)}' text='PREV'/>
<r:date format='%B'/>
<r:link date='#{date.advance(:months =&gt; 1).strftime(\"%Y-%m-%d\", tz)}' text='NEXT'/>
</h3></div>"
res: "/date=2006-02-18'>PREV.*date=2006-04-18'>NEXT/"
</h3><r:cell><b do='date' format='%e.%m'/></r:cell></div>"
res: "/date=2006-02-18'>PREV.*date=2006-04-18'>NEXT.*<b>15.03</b>/"

calendar_node_attr:
context:
date: '2006-03-10'
src: "<div do='calendar' attr='created_at' select='nodes where #{cal_start} <= created_at and created_at < #{cal_end} in project'/>"
res: "/<span>10</span>.*Keeping th…/"
res: "/p>10</p>.*Keeping th…/"

calendar_bad_query:
src: "<div do='calendar' attr='date' select='posts where #{cal_start} <= starsky and hutch < #{cal_end} in project'/>"
Expand Down
10 changes: 5 additions & 5 deletions test/integration/zafu_compiler/conditional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ if_has_discussion:
res: "status title:yes zena enhancements:no"

case_ancestor:
src: "<r:root><r:pages><r:each join=', '><r:case><r:when eval='ancestor?(main)'><b><r:show attr='title'/></b></r:when><r:else><r:show attr='title'/></r:else></r:case></r:each></r:pages></r:root>"
src: "<r:root><r:pages><r:each join=', '><r:case><r:when eval='is_ancestor?(main)'><b><r:show attr='title'/></b></r:when><r:else><r:show attr='title'/></r:else></r:case></r:each></r:pages></r:root>"
res: "Collections, Nature, people, <b>projects list</b>, Skins (layout themes)"

on_if_ancestor_no_class:
old_src: "<r:root><r:pages><li do='each' on_if_node='ancestor' join=', '><r:show attr='title'/></li></r:pages></r:root>"
src: "<r:root><r:pages><li do='each' on_if='ancestor?(main)' join=', '><r:show attr='title'/></li></r:pages></r:root>"
tem: '/var3.ancestor\?\(@node\)/'
src: "<r:root><r:pages><li do='each' on_if='is_ancestor?(main)' join=', '><r:show attr='title'/></li></r:pages></r:root>"
tem: '/var3.is_ancestor\?\(@node\)/'
res: "<li class=''>Collections</li>, <li class=''>Nature</li>, <li class=''>people</li>, <li class=' on'>projects list</li>, <li class=''>Skins (layout themes)</li>"

multiple_class_conditions:
Expand All @@ -117,8 +117,8 @@ multiple_class_conditions_true_in_middle:

# var1 = stored 'papa'
test_ancestor_with_stored:
src: "<r:parent do='parent' set_papa='this' do='pages'><div do='each' super_if='papa.ancestor?(this)' do='title'/></r:parent>"
tem: "/_zpapa = var1.*\(_zpapa\.ancestor\?\(var4\)\)/"
src: "<r:parent do='parent' set_papa='this' do='pages'><div do='each' super_if='papa.is_ancestor?(this)' do='title'/></r:parent>"
tem: "/_zpapa = var1.*\(_zpapa\.is_ancestor\?\(var4\)\)/"
res: "<div class=''>a wiki with Zena</div><div class=' super'>Clean Water project</div>"

on_if_kind_of:
Expand Down
5 changes: 5 additions & 0 deletions test/integration/zafu_compiler/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ label_on_select:
src: "<r:select label='t' name='title' values='1,2'/>"
res: "/<label>titre</label> <span><select name='node\[title\]'/"

passiv_form:
# Should not transform 'form' or 'input' into 'r:form' or 'r:input'
src: "<form>xxx<input name='x' id='y' type='text'/></form>"
tem: "<form>xxx<input name='x' id='y' type='text'/></form>"

param_on_select:
src: "<r:select param='q[contact.status]' values='0,-5,-10' tshow='active, being registered, inactive'/>"
res: "<select name='q[contact.status]'><option value=\"0\">active</option>\n<option value=\"-5\">being registered</option>\n<option value=\"-10\">inactive</option></select>"
8 changes: 8 additions & 0 deletions test/integration/zafu_compiler/urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ url_with_param:
src: "<p do='eval'>url(parent)</p>"
res: "<p>http://test.host/oo/projects-list/Clean-Water-project</p>"

url_with_hash:
src: "<p do='url(this, :mode => \"foo\")'/>"
res: "/page22_foo.html/"

r_url_with_hash:
src: "<r:url mode='back' f='x'/>"
res: "/page22_back.html\?f=x/"

path:
src: "<a href='#{path}'>blah</a>"
res: "<a href='/oo/projects-list/Clean-Water-project/page22.html'>blah</a>"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/zafu_compiler/zafu_attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ on_if_on_each:
res: "<p class=''>crocodiles</p><p class=''>Keeping things clean !</p><p class=' on'>status title</p>"

on_if_ancestor:
src: "<r:root><r:pages><li do='each' on_if='ancestor?(main)' class='hello' join=', ' do='title'/></r:pages></r:root>"
src: "<r:root><r:pages><li do='each' on_if='is_ancestor?(main)' class='hello' join=', ' do='title'/></r:pages></r:root>"
res: "<li class='hello'>Collections</li>, <li class='hello'>Nature</li>, <li class='hello'>people</li>, <li class='hello on'>projects list</li>, <li class='hello'>Skins (layout themes)</li>"

on_if_empty:
Expand Down
12 changes: 6 additions & 6 deletions test/unit/node_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class NodeTest < Zena::Unit::TestCase
end

context 'with a sub-node' do
should 'return true on ancestor?' do
assert subject.ancestor?(secure!(Node) { nodes(:status) })
should 'return true on is_ancestor?' do
assert subject.is_ancestor?(secure!(Node) { nodes(:status) })
end
end # with a sub-node

context 'with a node that is not a sub-node' do
should 'return false on ancestor?' do
assert !subject.ancestor?(secure!(Node) { nodes(:people) })
should 'return false on is_ancestor?' do
assert !subject.is_ancestor?(secure!(Node) { nodes(:people) })
end
end # with a node that is not a sub-node

should 'return true on ancestor? on self' do
assert subject.ancestor?(subject)
should 'return true on is_ancestor? on self' do
assert subject.is_ancestor?(subject)
end
end # On a node

Expand Down
7 changes: 5 additions & 2 deletions zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2011-04-20}
s.date = %q{2011-05-08}
s.default_executable = %q{zena}
s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
s.email = %q{gaspard@teti.ch}
Expand Down Expand Up @@ -164,7 +164,6 @@ Gem::Specification.new do |s|
"app/views/links/destroy.rjs",
"app/views/links/show.rjs",
"app/views/nodes/500.html",
"app/views/nodes/_dates.rhtml",
"app/views/nodes/_edit_attribute.rhtml",
"app/views/nodes/_gallery.rhtml",
"app/views/nodes/_groups.rhtml",
Expand Down Expand Up @@ -501,6 +500,7 @@ Gem::Specification.new do |s|
"lib/zena/app.rb",
"lib/zena/base_additions.rb",
"lib/zena/code_syntax.rb",
"lib/zena/console.rb",
"lib/zena/controller/test_case.rb",
"lib/zena/core_ext/date_time.rb",
"lib/zena/core_ext/dir.rb",
Expand Down Expand Up @@ -2229,6 +2229,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<property>, ["= 2.1.2"])
s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_runtime_dependency(%q<zafu>, ["= 0.7.7"])
s.add_runtime_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_runtime_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_runtime_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2251,6 +2252,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<property>, ["= 2.1.2"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<zafu>, ["= 0.7.7"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
Expand All @@ -2274,6 +2276,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<property>, ["= 2.1.2"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<zafu>, ["= 0.7.7"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
Expand Down

0 comments on commit 40d46b5

Please sign in to comment.