Changeset 503

Show
Ignore:
Timestamp:
2007-05-10 13:35:42 (2 years ago)
Author:
gaspard
Message:

[feature] Added dynamic attributes support (versioned dynamic attributes)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/TODO

    r472 r503  
    11== MOST IMPORTANT: 
    2 prepare a boot script for zena so it is restarted on hardware reboot : 
    3 'send a mail' 
    4 rm -rf log/mongrel.*.pid 
    5 mongrel_rails cluster::start 
    6  
     2* use connection.quote !!! 
    73 
    84== Todo 
  • trunk/app/models/version.rb

    r502 r503  
    3737  validate_on_update    :can_update_content 
    3838  after_save            :save_content 
    39    
     39  uses_dynamic_attributes 
    4040  # not tested belongs_to :comment_group, :class_name=>'Group', :foreign_key=>'cgroup_id' 
    4141  # not tested has_many :comments, :order=>'created_at' 
     
    119119  def content_class 
    120120    nil 
     121  end 
     122   
     123  def clone 
     124    obj = super 
     125    # clone dynamic attributes 
     126    obj.dyn = self.dyn 
     127    obj 
    121128  end 
    122129   
  • trunk/config/version.rb

    r479 r503  
    33    MAJOR = 0 
    44    MINOR = 8 
    5     TINY  = 1 
     5    TINY  = 2 
    66     
    77    STRING = [MAJOR, MINOR, TINY].join('.') 
  • trunk/db/migrate/000_zena/015_add_dyn_attributes.rb

    r502 r503  
    77      t.column 'value', :text 
    88    end 
     9    add_index 'dyn_attributes', 'owner_id' 
     10    add_index 'dyn_attributes', 'owner_table' 
    911  end 
    1012 
    1113  def self.down 
     14    remove_index 'dyn_attributes', 'owner_id' 
     15    remove_index 'dyn_attributes', 'owner_table' 
    1216    drop_table 'dyn_attributes' 
    1317  end 
  • trunk/db/schema.rb

    r486 r503  
    8383    t.column "site_id",      :integer 
    8484  end 
     85 
     86  create_table "dyn_attributes", :force => true do |t| 
     87    t.column "owner_id",    :integer 
     88    t.column "owner_table", :string 
     89    t.column "key",         :string 
     90    t.column "value",       :text 
     91  end 
     92 
     93  execute "ALTER TABLE dyn_attributes ENGINE = MyISAM" 
     94  execute "CREATE  INDEX index_dyn_attributes_on_owner_id ON dyn_attributes (owner_id)" 
     95  execute "ALTER TABLE dyn_attributes ENGINE = MyISAM" 
     96  execute "CREATE  INDEX index_dyn_attributes_on_owner_table ON dyn_attributes (owner_table)" 
    8597 
    8698  create_table "groups", :force => true do |t| 
     
    164176  end 
    165177 
     178  create_table "tmp", :id => false, :force => true do |t| 
     179    t.column "a", :string, :limit => 50 
     180    t.column "b", :string, :limit => 50 
     181  end 
     182 
    166183  create_table "trans_phrases", :force => true do |t| 
    167184    t.column "phrase",  :string,  :limit => 100, :default => "", :null => false 
  • trunk/lib/multiversion.rb

    r502 r503  
    381381        # Any attribute starting with 'c_' belongs to the 'version' or 'redaction' content 
    382382        def method_missing(meth, *args) 
    383           if meth.to_s =~ /^(v_|c_)(([\w_\?]+)(=?))$/ 
     383          if meth.to_s =~ /^(v_|c_|d_)(([\w_\?]+)(=?))$/ 
    384384            target = $1 
    385             method = $2.to_sym 
    386             value  = $3.to_sym 
     385            method = $2 
     386            value  = $3 
    387387            mode   = $4 
    388388            if mode == '=' 
     
    408408                end 
    409409              elsif target == 'd_' 
    410                 recipient.dyn[method] = args[0] 
     410                recipient.dyn[method[0..-2]] = args[0] 
    411411              else 
    412412                begin 
  • trunk/lib/parser/lib/rules/zena.rb

    r501 r503  
    497497            render_html_tag(expand_with) 
    498498          else 
    499             add_params(res, id_hash) 
    500           end 
     499            add_params(expand_with, id_hash) 
     500          end 
     501        else 
     502          # error, no list 
     503          "<span class='parser_error'>each not in list context</span>" 
    501504        end 
    502505      end 
  • trunk/lib/parser/test/zafu.yml

    r497 r503  
    241241names: 
    242242  src: "<p do='void' name='root'><p do='inspect' name='first'/><p do='inspect' name='second'/></p>" 
    243   res: "<p>[inspect {> :name=>'root/first'}]<p/>[/inspect][inspect {> :name=>'root/second'}]<p/>[/inspect]</p>" 
     243  res: "<p>[inspect {= :name=>'first'} {> :name=>'root/first'}]<p/>[/inspect][inspect {= :name=>'second'} {> :name=>'root/second'}]<p/>[/inspect]</p>" 
    244244 
    245245default_tag: 
  • trunk/test/helpers/basic.yml

    r498 r503  
    287287  src: "<z:children><z:each join=', '><z:show attr='name'/></z:each></z:children>" 
    288288  res: "bird, flower" 
    289  
    290 edit_not_each: 
    291   src: "<li class='blah'>this is a post <z:edit>edit post</z:edit></li>" 
    292   tem: "/<li class='blah'>this is a post </li>/" 
    293  
    294 edit_each_no_form: 
    295   src: "<z:each><li>blah <z:edit>do this and that</z:edit></li>" 
    296   tem: "/<li>blah </li>" 
    297  
    298 each_add_with_form: 
    299   context: 
    300     node: 'wiki' 
    301   src: "<z:children><z:each><li do='show' attr='name'>blah</li>\n</z:each><z:add><li>add new</li></z:add><z:form><li><form>this is the form</form></li></z:form></z:children>" 
    302   res: "/<li>bird.*<li>flower.*<li.*list_add.*list_form.*toggle.*<li .*list_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value='/each/add/with/form/list'/" 
    303    
    304 each_edit_with_form: 
    305   context: 
    306     node: 'wiki' 
    307   src: "<z:children><z:each><li><z:show attr='name'>blah</z:show> <z:edit>edit</z:edit></li>\n</z:each><z:form><li><form>this is the form</form></li></z:form></z:children>" 
    308   res: "/<li id='/each/edit/with/form/list30'>bird <a href=\"#\" onclick=\"new Ajax.Request\('/nodes/30/edit\?template_url=%2Feach%2Fedit%2Fwith%2Fform%2Flist/" 
    309289 
    310290set_attribute: 
  • trunk/test/helpers/zafu_ajax.yml

    r501 r503  
    99  tem: "<span id='/show/edit/list_name<%= @node[:zip] %>'><%= link_to_remote(@node.name, :url => edit_node_path(@node[:zip]) + \"?attribute=name&identifier=%2Fshow%2Fedit%2Flist_name#{@node[:zip]}\", :method => :get) %></span>" 
    1010  res: "/span id='/show/edit/list_name22'>.*Ajax\.Request\('/nodes/22/edit\?attribute=name/" 
     11 
     12edit_not_each: 
     13  src: "<li class='blah'>this is a post <z:edit>edit post</z:edit></li>" 
     14  tem: "/<li class='blah'>this is a post </li>/" 
     15 
     16edit_each_no_form: 
     17  src: "<z:children><li do='each'>blah <z:edit>do this and that</z:edit></li></z:children>" 
     18  tem: "/<li>blah </li>/" 
     19 
     20each_add_with_form: 
     21  context: 
     22    node: 'wiki' 
     23  src: "<z:children><z:each><li do='show' attr='name'>blah</li>\n</z:each><z:add><li>add new</li></z:add><z:form><li><form>this is the form</form></li></z:form></z:children>" 
     24  res: "/<li.*list30.*>bird.*<li.*list31.*>flower.*<li.*list_add.*list_form.*toggle.*<li .*list_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value='/each/add/with/form/list'/" 
     25 
     26each_edit_with_form: 
     27  context: 
     28    node: 'wiki' 
     29  src: "<z:children><z:each><li><z:show attr='name'>blah</z:show> <z:edit>edit</z:edit></li>\n</z:each><z:form><li><form>this is the form</form></li></z:form></z:children>" 
     30  res: "/<li id='/each/edit/with/form/list30'>bird <a href=\"#\" onclick=\"new Ajax.Request\('/nodes/30/edit\?template_url=%2Feach%2Fedit%2Fwith%2Fform%2Flist/" 
  • trunk/test/helpers/zena_parser_test.rb

    r500 r503  
    99   
    1010  def test_single 
    11     do_test('zafu_ajax', 'show_edit') 
     11    do_test('zafu_ajax', 'edit_each_no_form') 
    1212  end 
    1313   
  • trunk/test/unit/multiversion_test.rb

    r495 r503  
    575575    assert_equal 1, trad.size 
    576576  end 
     577   
     578  def test_dynamic_attributes 
     579    login(:lion) 
     580    node = secure(Node) { nodes(:status) } 
     581    node.d_bolo = 'spaghetti bolognese' 
     582    assert node.save, "Can save node" 
     583     
     584    # reload 
     585    node = secure(Node) { nodes(:status) } 
     586    assert_equal 'spaghetti bolognese', node.d_bolo 
     587  end 
    577588end 
  • trunk/test/unit/version_test.rb

    r484 r503  
    146146  end 
    147147   
     148  def test_dynamic_attributes 
     149    login(:tiger) 
     150    node = secure(Node) { nodes(:status) } 
     151    version = node.send(:redaction) 
     152    assert_nothing_raised { version.dyn['zucchini'] = 'courgettes' } 
     153    assert_nothing_raised { version.d_zucchini = 'courgettes' } 
     154    assert_equal 'courgettes', version.d_zucchini 
     155    assert node.save 
     156     
     157    node = secure(Node) { nodes(:status) } 
     158    version = node.version 
     159    assert_equal 'courgettes', version.d_zucchini 
     160  end 
     161   
     162  def test_clone 
     163    login(:tiger) 
     164    node = secure(Node) { nodes(:status) } 
     165    assert node.update_attributes(:d_whatever => 'no idea') 
     166    assert_equal 'no idea', node.d_whatever 
     167    version1_id = node.version[:id] 
     168    assert node.publish 
     169     
     170    node = secure(Node) { nodes(:status) } 
     171    assert node.update_attributes(:d_other => 'funny') 
     172    version2_id = node.version[:id] 
     173    assert_not_equal version1_id, version2_id 
     174    assert_equal 'no idea', node.d_whatever 
     175    assert_equal 'funny', node.d_other 
     176  end 
    148177end 
  • trunk/vendor/plugins/ar_mysql_full_text/lib/ar_mysql_full_text.rb

    r455 r503  
    5151            next if row[2] == "PRIMARY" # skip the primary key 
    5252            current_index = row[2] 
    53             indexes << MySQLIndexDefinition.new(row[0], row[2], row[1] == "0", [], row[10]) 
     53            index_type = row[10] 
     54            index_type = '' if index_type == 'BTREE' 
     55            indexes << MySQLIndexDefinition.new(row[0], row[2], row[1] == "0", [], index_type) 
    5456          end 
    5557