Changeset 548

Show
Ignore:
Timestamp:
2007-05-21 11:04:10 (2 years ago)
Author:
gaspard
Message:

[new] zafu include now takes a 'part' argument to load only parts of a template (can load self).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/application.rb

    r547 r548  
    283283      # 1. site forces authentication  
    284284      if (current_site.authentication? && visitor.is_anon?) 
    285         do_login 
     285        do_login and return false 
    286286      end 
    287287       
     
    297297     
    298298    def do_login 
     299      session[:after_login_url]   ||= request.parameters 
    299300      if current_site[:http_auth] || true 
    300301        basic_auth_required do |username, password|  
     
    303304          end 
    304305        end 
    305         # reset render 
    306         return !visitor.is_anon? 
    307306      else 
    308307        flash[:notice] = _("Please log in") 
    309         session[:after_login_url] = request.parameters 
    310         redirect_to login_path and return false 
     308        redirect_to login_path 
    311309      end 
    312310    end 
     
    318316      # reset session lang, will be set from user on next request/filter 
    319317      session[:lang] = nil 
    320       return true 
     318      redirect_to session.delete(:after_login_url) || user_path(visitor) 
    321319    end 
    322320     
     
    330328        headers["Status"] = "Unauthorized"  
    331329        headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\"" 
    332         # FIXME: JS redirect instead of text if not site.authentication 
     330         
     331        # require login 
    333332        if current_site.authentication? 
    334333          render :nothing => true, :status => 401 
  • trunk/app/controllers/nodes_controller.rb

    r545 r548  
    318318    def clean_url 
    319319      if params[:prefix] == AUTHENTICATED_PREFIX && visitor.is_anon? 
    320         return false unless do_login 
     320        do_login and return false 
    321321      end 
    322322      case params[:action] 
     
    334334 
    335335      if redirect_url 
    336         redirect_to redirect_url 
    337         return false 
     336        redirect_to redirect_url and return false 
    338337      end 
    339338    end 
  • trunk/db/init/base/skins/default/Project.html

    r541 r548  
    1313     
    1414    <r:home> 
    15       <r:include template='title.html'/> 
     15      <r:include template='layout.html' part='body/container/main/title'/> 
    1616      <r:summary text=''/> 
    1717      <r:text/> 
    1818      <r:else> 
    19         <r:include template='title.html'/> 
     19        <r:include template='layout.html' part='body/container/main/title'/> 
    2020      </r:else> 
    2121    </r:home> 
  • trunk/db/init/base/skins/default/layout.html

    r541 r548  
    4949 
    5050    <div id='content' do='content_for_layout' name='content'> 
    51       <div id='main' do='void' name='main'></div> 
     51      <div id='main' do='void' name='main'> 
     52        <div class='header' name='title'> 
     53          <r:if kind_of='Document'><p class="document"><r:link format="data"><r:img mode='pv'/></r:link></p></r:if> 
     54          <h1 do='title' class='s30' status='true' actions='all'>this is the title</h1> 
     55          <div class='subtitle'> 
     56            <r:case> 
     57              <r:when test='[user_id] == [v_user_id]'> 
     58                <r:trans>posted by</r:trans> <b do='author' do='show' attr='fullname'>Super Man</b> 
     59              </r:when> 
     60              <r:else> 
     61                <r:trans>original by</r:trans> <b do='author' do='show' attr='fullname'>Platon</b> 
     62                <r:trans>modified by</r:trans> <b do='version' do='author' do='show' attr='fullname'>Socrate</b> 
     63              </r:else> 
     64            </r:case> 
     65          </div> 
     66        </div> 
     67      </div> 
    5268 
    5369      <div id='related' do='void' name='related'> 
  • trunk/db/schema.rb

    r545 r548  
    151151    t.column "admin_group_id",  :integer 
    152152    t.column "site_group_id",   :integer 
    153     t.column "trans_group_id",  :integer 
    154153    t.column "name",            :string 
    155154    t.column "authentication",  :boolean 
     
    175174    t.column "klass",     :string 
    176175    t.column "mode",      :string 
     176  end 
     177 
     178  create_table "tmp", :id => false, :force => true do |t| 
     179    t.column "a", :string, :limit => 50 
     180    t.column "b", :string, :limit => 50 
    177181  end 
    178182 
  • trunk/lib/parser/lib/parser.rb

    r546 r548  
    226226    @text, absolute_url = self.class.get_template_text(@params[:template], @options[:helper], @options[:current_folder]) 
    227227     
     228    absolute_url += "::#{@params[:part].gsub('/','_')}" if @params[:part] 
    228229    if absolute_url 
    229230      if @options[:included_history].include?(absolute_url) 
     
    237238    @text = before_parse(@text) 
    238239    enter(:void) # scan fetched text 
    239     @included_blocks = @blocks 
     240    if @params[:part] 
     241      @included_blocks = [find_part(@params[:part])] 
     242    else 
     243      @included_blocks = @blocks 
     244    end 
    240245     
    241246    @blocks = [] 
    242247    @text = text 
    243248    enter(:void) # normal scan on content 
     249  end 
     250   
     251  def find_part(path) 
     252    res    = self 
     253    path.split('/').reject {|e| e==''}.each do |name| 
     254      res.blocks.each do |b| 
     255        next if b.kind_of?(String) 
     256        if b.params[:name] == name 
     257          res    = b 
     258          name   = nil 
     259          break 
     260        end 
     261      end 
     262      return nil if name # block not found 
     263    end 
     264    res 
    244265  end 
    245266   
  • trunk/lib/parser/lib/rules/zena.rb

    r546 r548  
    811811    def r_cache 
    812812      kpath   = @params[:kpath]   || Page.kpath 
    813       context = @params[:context] || @context[:name] || @options[:included_history][0] 
     813      context = @params[:context] || @context[:name] || (@options[:included_history][0] || '').split('::')[0] 
    814814      out "<% #{cache} = Cache.with(visitor.id, visitor.group_ids, #{helper.send(:lang).inspect}, #{kpath.inspect}, #{context.inspect}) do capture do %>" 
    815815      out expand_with 
     
    10631063     
    10641064    def unique_name 
    1065       "#{@options[:included_history][0]}/#{((@context[:name] || 'list').split('/')[-1]).gsub(/[^\w\/]/,'_')}" 
     1065      "#{@options[:included_history][0].split('::')[0]}/#{((@context[:name] || 'list').split('/')[-1]).gsub(/[^\w\/]/,'_')}" 
    10661066    end 
    10671067        
  • trunk/lib/parser/test/parser_test.rb

    r541 r548  
    22#require 'ruby-debug' 
    33#Debugger.start 
     4unless Module.const_defined?(:ActiveRecord) 
     5  # blank definition from active_support/core_ext/blank.rb 
     6  class String #:nodoc: 
     7    def blank? 
     8      empty? || strip.empty? 
     9    end 
     10  end 
     11end 
    412 
    513module Zafu 
     
    3644  testfile :zafu, :zafu_asset, :zafu_insight, :zazen 
    3745  def test_single 
    38     do_test('zafu', 'include_replace_same') 
     46    do_test('zafu', 'include_self') 
    3947  end 
    4048   
  • trunk/lib/parser/test/zafu.yml

    r541 r548  
    9393  src: "include_menu: <r:include template='/default/menu'/>" 
    9494  res: "include_menu: the [test]menu[/test] is nice" 
     95 
     96named_parts: 
     97  src: "named_parts: <r:test name='start'>start from here to <r:hello name='sub'>sub</r:hello></r:test> ok." 
     98  res: "named_parts: [test {= :name=>'start'} {> :name=>'start'}]start from here to [hello {= :name=>'sub'}]sub[/hello][/test] ok." 
     99 
     100include_self: 
     101  src: "IS: I like <r:void name='sub'>sub <r:hello/></r:void> and <r:include template='/include/self' part='sub'/>" 
     102  res: "IS: I like sub hello world! and sub hello world!" 
     103 
     104include_part: 
     105  src: "IP: <r:include template='/named/parts' part='start/sub'/> PI." 
     106  res: "IP: hello world! PI." 
    95107 
    96108include_context: 
  • trunk/lib/tasks/zena.rake

    r523 r548  
    144144  end 
    145145   
    146   desc "Enable fulltext search in production mode" 
    147   task :init_fulltext => :environment do 
    148     ActiveRecord::Base.connection.execute "ALTER TABLE versions ENGINE = MyISAM;" 
    149     # add fulltext index 
    150     ActiveRecord::Base.connection.add_index "versions", ["title", "text", "summary"], :index_type => "FULLTEXT"    
    151   end 
    152    
    153146  desc "Migrate the database through scripts in db/migrate. Target specific brick and version with BRICK=x and VERSION=x" 
    154147  task :migrate => :environment do 
  • trunk/test/integration/navigation_test.rb

    r545 r548  
    1313    Site.connection.execute "UPDATE sites SET authentication = 1 WHERE id = 1" # test.host 
    1414    get 'http://test.host/' 
     15    assert_redirected_to 'http://test.host/login' 
     16     
     17    reset! 
     18    post 'http://test.host/session', :login=>'tiger', :password=>'tiger' 
     19    assert_redirected_to 'http://test.host/users/4' 
     20     
     21    # 2. navigating out of '/oo' but logged in and format is not data 
     22    get 'http://test.host/fr' 
     23    assert_redirected_to 'http://test.host/oo' 
     24    follow_redirect! 
     25    assert_response :success 
     26    get 'http://test.host/fr/textdocument53.css' # data 
     27    assert_response :success 
     28  end 
     29   
     30  def test_authorize_http_auth 
     31    Site.connection.execute "UPDATE sites SET http_auth = 1 WHERE id = 1" # test.host 
     32    get 'http://test.host/' 
     33    assert_redirected_to 'http://test.host/en' 
     34    follow_redirect! 
     35    assert_response :success 
     36     
     37    # 1. site forces authentication  
     38    Site.connection.execute "UPDATE sites SET authentication = 1 WHERE id = 1" # test.host 
     39    get 'http://test.host/' 
     40    assert_response 401 # http_auth 
    1541    assert_redirected_to 'http://test.host/login' 
    1642