Changeset 315

Show
Ignore:
Timestamp:
2007-02-26 23:07:02 (2 years ago)
Author:
gaspard
Message:

Working skins !!
Automatic <div> @html_tag when class or div
Added try/catch to version preview.rjs

Files:

Legend:

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

    r313 r315  
    2828  def template_url(opts={}) 
    2929    skin  = opts[:skin] || 'default' 
    30     skin_obj = nil 
     30    @skin_obj = nil 
    3131    skin_helper = nil 
    3232    # find best match 
     
    6767    if skin 
    6868      begin 
    69         skin_obj = secure(Skin) { Skin.find_by_name(skin) } 
     69        @skin_obj = secure(Skin) { Skin.find_by_name(skin) } 
    7070        sess = @session 
    7171        response.template.instance_eval { @session = sess } 
    7272        skin_helper = response.template 
    7373      rescue 
    74         skin_obj = nil 
     74        @skin_obj = nil 
    7575      end 
    7676    end 
     
    8282      template = "/templates/compiled/#{skin}/#{template_name}_#{lang}.rhtml" 
    8383      break if File.exist?("#{RAILS_ROOT}/app/views#{template}") 
    84       # search in the skin_obj 
    85       if skin_obj 
    86         break if template = skin_obj.template_url_for_name(template_name, skin_helper) 
     84      # search in the @skin_obj 
     85      if @skin_obj 
     86        break if template = @skin_obj.template_url_for_name(template_name, skin_helper) 
    8787      end 
    8888      # continue search 
     
    9494  end 
    9595   
    96   # TODO... 
    9796  def template_text_for_url(url) 
    98     return "NOT IMPLEMENTED YET (#{url})" 
    9997    url = url[1..-1] # strip leading '/' 
    10098    url = url.split('/') 
    101     template = secure(Skin) { Skin.find_by_path(url) } 
     99    skin_name = url.shift 
     100    if @skin_obj[:name] == skin_name 
     101      skin = @skin_obj 
     102    end 
     103    skin ||= secure(Skin) { Skin.find_by_name(skin_name) } 
     104    template = skin.template_for_path(url) 
    102105    template.version.text 
    103   rescue ActiveRecord::RecordNotFound 
     106  rescue 
    104107    return nil 
    105108  end 
  • trunk/app/models/skin.rb

    r313 r315  
    66    if template_name == 'any' 
    77      template = self 
     8      zafu_url = "/#{self[:name]}/any" 
    89    else 
    9       template = secure(Template) { Template.find(:conditions=>["parent_id = ? AND name = ?", self[:id], template_name])} 
     10      template = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", self[:id], template_name])} 
     11      zafu_url = "/#{self[:name]}/#{template_name}" 
    1012    end 
    11     tmpl_name = "#{template_name}_#{visitor_lang}.rhtml
     13    tmpl_name = "#{template_name}_#{visitor_lang}
    1214    tmpl_dir = "/templates/compiled/#{self[:name]}" 
    1315    FileUtils::mkpath("#{RAILS_ROOT}/app/views#{tmpl_dir}") 
    1416    # render for the current lang 
    15     res = ZafuParser.new(template.version.text, :helper=>helper).render 
    16     File.open("#{RAILS_ROOT}/app/views#{tmpl_dir}/#{tmpl_name}", "wb") { |f| f.syswrite(res) } 
     17    res = ZafuParser.new_with_url(zafu_url, :helper=>helper).render 
     18    File.open("#{RAILS_ROOT}/app/views#{tmpl_dir}/#{tmpl_name}.rhtml", "wb") { |f| f.syswrite(res) } 
    1719    return "#{tmpl_dir}/#{tmpl_name}" 
    1820  rescue ActiveRecord::RecordNotFound 
    1921    nil 
    2022  end 
     23   
     24  def template_for_path(path) 
     25    Skin.logger.info "[#{name}] GET (#{path.inspect})" 
     26    current = self 
     27    if path == ['any'] 
     28      return current 
     29    else 
     30      while path != [] 
     31        template_name = path.shift 
     32        Skin.logger.info "[#{name}] GET ('parent_id = #{current[:id]} AND name = '#{template_name}')" 
     33        begin 
     34          current = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])} 
     35          Skin.logger.info "OK" 
     36        rescue ActiveRecord::RecordNotFound 
     37          Skin.logger.info "NOT FOUND" 
     38          break 
     39        end 
     40      end 
     41      if path == [] 
     42        current 
     43      else 
     44        nil 
     45      end 
     46    end 
     47  rescue ActiveRecord::RecordNotFound 
     48    nil 
     49  end    
    2150end 
  • trunk/app/views/version/preview.rjs

    r279 r315  
    11# page.replace_html "template", @html 
    22 
     3page << "try {" 
    34page.replace_html   "v_title#{@preview_id}", @v_title 
     5page << "} catch(err) {}" 
     6page << "try {" 
    47page.replace_html "v_summary#{@preview_id}", zazen(@v_summary, :pretty_code=>true) unless @node.kind_of?(Note) 
     8page << "} catch(err) {}" 
     9page << "try {" 
    510page.replace_html    "v_text#{@preview_id}", zazen(@v_text, :pretty_code=>true) 
     11page << "} catch(err) {}" 
    612#  
  • trunk/config/environments/development.rb

    r175 r315  
    1616config.action_controller.perform_caching             = false 
    1717config.action_view.cache_template_extensions         = false 
    18 config.action_view.debug_rjs                         = true 
     18#config.action_view.debug_rjs                         = true 
    1919 
    2020# Don't care if the mailer can't send 
  • trunk/doc/README_FOR_APP

    r286 r315  
    2727We should use attr_protected instead of filtering forms. 
    2828* Remove all .utc (now using ENV['TZ']) 
     29* Provide a 'grows with zena' // 'runs with zena' logo and link 
     30* Provide a link from zena to teti.ch 
    2931=== Optimization & Cache 
    3032* sweep public page cache : 
  • trunk/lib/parser/lib/parser.rb

    r313 r315  
    2424    # Retrieve the template text in the current folder or as an absolute path. 
    2525    # This method is used when 'including' text 
    26     def find_template_text(url, helper, current_folder='/') 
     26    def find_template_text(url, helper, current_folder=nil) 
     27      current_folder ||= '/' 
    2728      # remove trailing '/' 
    2829      if current_folder[-1..-1] == '/' 
     
    8889      @params.delete(:name) 
    8990      if @context[:name] 
    90         @context[:name] << "/#{name}" 
     91        @context[:name] += "/#{name}" 
    9192      else 
    9293        @context[:name] = name 
     
    182183    # fetch text 
    183184    text = @text 
     185    @options[:included_history] ||= [] 
     186    @options[:current_folder]   ||= '/' 
    184187    @text, absolute_url = self.class.find_template_text(@params[:template], @options[:helper], @options[:current_folder]) 
    185188    if absolute_url 
     
    365368        res << b 
    366369      else 
    367         res << b.render(new_context
     370        res << b.render(new_context.dup
    368371        if pass = b.pass 
    369372          if pass[:part] 
  • trunk/lib/parser/lib/rules/zafu.rb

    r311 r315  
    77      @context = context 
    88      @html_tag_done = false 
     9      unless @html_tag 
     10        if @params[:id] || @params[:class] 
     11          @html_tag = @params[:tag] || 'div' 
     12          @params.delete(:tag) 
     13          @html_tag_params = {} 
     14          [:id, :class].each do |k| 
     15            @html_tag_params[k] = @params[k] if @params[k] 
     16            @params.delete(k) 
     17          end 
     18        end 
     19      end 
    920      res = super 
    1021      if (@context[:parts] || {})[@context[:name]] 
  • trunk/lib/parser/lib/rules/zena.rb

    r313 r315  
    2424      end 
    2525    end 
    26     inline_methods :login_link, :visitor_link, :search_box, :menu, :path_links, :lang_links 
     26    inline_methods :login_link, :visitor_link, :search_box, :show_menu, :path_links, :lang_links 
    2727    direct_methods :uses_calendar 
    2828 
     
    9797     
    9898    def r_anchor(obj=node) 
    99       "<a name='#{node_class.to_s.downcase}<%= #{obj}[:id] %>'/>" 
     99      "<a name='#{node_class.to_s.downcase}<%= #{obj}[:id] %>'></a>" 
    100100    end 
    101101     
     
    113113      end 
    114114      res << "%>" 
    115       if @params[:status] 
     115      if @params[:status] == 'true' || (@params[:status].nil? && @params[:actions]) 
    116116        res = "<div class='s<%= #{node}.version.status %>'>#{res}</div>" 
    117117      end 
     
    362362        begin Module::const_get(klass) rescue "NilClass" end 
    363363        cond = "#{node}.kind_of?(#{klass})" 
    364       elsif klass = (@params[:klass] || @params[:class]) 
     364      elsif klass = @params[:klass] 
    365365        begin Module::const_get(klass) rescue "NilClass" end 
    366366        cond = "#{node}.class == #{klass}" 
  • trunk/lib/parser/test/parser_test.rb

    r313 r315  
    3333  testfile :zafu, :zafu_asset, :zafu_insight, :zazen 
    3434  def test_single 
    35     do_test('zafu', 'preserve_newlines') 
     35    do_test('zafu', 'names') 
    3636  end 
    3737  def test_zazen_image_no_image 
  • trunk/lib/parser/test/zafu.yml

    r313 r315  
    229229    [test]<p>blah</p>[/test] 
    230230    ok 
    231      
     231 
     232names: 
     233  src: "<p do='void' name='root'><p do='inspect' name='first'/><p do='inspect' name='second'/></p>" 
     234  res: "<p>[inspect {> :name=>'root/first'}]<p/>[/inspect][inspect {> :name=>'root/second'}]<p/>[/inspect]</p>" 
     235 
     236default_tag: 
     237  src: "<z:void class='test'>blah</z:void>" 
     238  res: "<div class='test'>blah</div>" 
     239 
     240set_tag_param: 
     241  src: "<z:void class='test' tag='p'>blah</z:void>" 
     242  res: "<p class='test'>blah</p>" 
  • trunk/public/stylesheets/zen.css

    r277 r315  
    9797.actions li:hover a { border-bottom:5px solid orange; } 
    9898 
    99 .node_actions:hover { visibility:visible;  } 
    100  
    10199/* INLINE FORMS */ 
    102100.inline_form { margin:2px; padding:3px; background:#9FA6AC; border:1px dotted grey;} 
     
    158156/* NOTES */ 
    159157#left { position:absolute; top:125px; left:20px; width:220px; } 
     158#left ul { margin:0 0 1em 1em;} 
     159#left li { padding:2px;} 
    160160#add_note, #add_note_form { margin-left:1em } 
    161161#add_note { padding:10px 3px;} 
  • trunk/test/fixtures/document_contents.yml

    r314 r315  
    6565  ext:            'html' 
    6666  size:            
     67 
     68wiki_layout: 
     69  id:             8 
     70  version_id:     39 
     71  type:           TextDocumentContent 
     72  content_type:   "text/html" 
     73  name:           "layout" 
     74  ext:            'html' 
     75  size:            
  • trunk/test/fixtures/nodes.yml

    r313 r315  
    470470  user_id:        4 
    471471  inherit:        1 
    472   log_at:         2006-10-03 
    473 <%= @defaults %> 
    474 <%= @rights %> 
     472<%= @defaults %> 
     473<%= @rights %> 
     474 
     475wiki_layout: 
     476  id:             34 
     477  type:           Template 
     478  kpath:          NPDTT 
     479  name:           layout 
     480  project_id:     1 
     481  parent_id:      33 
     482  user_id:        4 
     483  inherit:        1 
     484<%= @defaults %> 
     485<%= @rights %> 
  • trunk/test/fixtures/versions.yml

    r313 r315  
    523523  node_id:        33 
    524524  user_id:        4 
    525   comment:        very simple template for wiki 
     525  comment:        very simple skin for wiki 
    526526  title:          wiki template 
    527   summary:        This page is a *Letter*
     527  summary:        Very simple skin
    528528  text:           | 
    529     <html> 
    530       <head> 
    531         <title do='show' attr='v_title'>some title</title> 
    532       </head> 
    533       <body> 
    534         <h1 do='show_title'>super title</h1> 
    535         <h2><a name='contents'/>contents</h2> 
     529    <z:include template='layout'> 
     530      <z:with id='left' part='body/left'> 
     531      <a name='contents'></a><h2 do='trans'>Contents</h2> 
    536532        <ul do='pages'> 
    537           <li do='each' do='link' dash='true'>some link</li> 
     533          <li do='each'><z:link dash='true'>some link</z:link> 
     534            <ul do='pages'> 
     535              <li do='each' do='link' dash='true'>sub link</li> 
     536            </ul> 
     537          </li> 
    538538        </ul> 
    539          
     539      </z:with> 
     540      <z:with id='content' class='content' part='body/main/content'> 
    540541        <z:pages do='each'> 
    541           <h3><z:title anchor='true' actions='all'/> <a href='#contents'>top</a></h3
     542          <h2><z:title anchor='true' actions='all'/></h2
    542543          <z:text/> 
     544          <z:pages do='each'> 
     545            <h3><z:title anchor='true' actions='all'/></h3> 
     546            <z:text/> 
     547          </z:pages> 
    543548        </z:pages> 
    544       </body> 
     549      </z:with> 
     550  lang:           en 
     551  number:         1 
     552<%= @defaults %> 
     553 
     554layout_template_en: 
     555  type:           TextDocumentVersion 
     556  id:             39 
     557  node_id:        34 
     558  user_id:        4 
     559  comment:        layout for wiki 
     560  title:          wiki template 
     561  summary:        Layout for the wiki skin. 
     562  text:           | 
     563    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     564        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
     565     
     566    <html xmlns="http://www.w3.org/1999/xhtml" do='void' lang="en" set_lang='[v_lang]' xml:lang='en'> 
     567    <head> 
     568      <title do='show' attr='v_title' name='title'>node title</title> 
     569      <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
     570      <meta http-equiv="Content-Language" do='void' content="fr-fr" tset_content='[v_lang]_content' /> 
     571     
     572    <link href="/stylesheets/zen.css" rel="Stylesheet" type="text/css" /> 
     573    <link href="/stylesheets/comment.css" rel="Stylesheet" type="text/css" /> 
     574    <link href="/stylesheets/search.css" rel="Stylesheet" type="text/css" /> 
     575    <link href="/stylesheets/code.css" rel="Stylesheet" type="text/css" /> 
     576    <z:javascripts list='prototype,effects,zena'/> 
     577    <z:uses_calendar/> 
     578    </head> 
     579     
     580    <body do='void' name='body'> 
     581      <div class="navbar"> 
     582        <div id='lang' do='lang_links'><a>en</a> | <b>fr</b></div> 
     583        <div id='path' do='path_links'><ul><li><a href='#'>first</a></li> / <li><a href='#'>second</a></li> / <li><a href='#' class='current'>here</a></li></ul></div> 
     584        <div id='login' do='login_link'><a href='#'>login</a></div> 
     585        <div id='visitor' do='visitor_link'><a href='#'>visitor name</a></div> 
     586        <div id='search' do='search_box'><div class='search'><form><input type='text' id='search' name='search'/></form></div></div> 
     587      </div> 
     588     
     589      <div id='menu' do='show_menu'> 
     590        <ul class='menu'><li><a>first</a></li> 
     591          <li><a>second</a><ul><li><a>sub</a></li><li><a>sub</a><ul><li><a>subsub</a></li></ul></li></ul></li> 
     592        </ul> 
     593      </div> 
     594     
     595      <div id='logo' do='link' href='root'><img src='img/logo.png' width='220' height='100'/></div> 
     596     
     597      <z:flash_messages/> 
     598     
     599      <div id="left" do='void' name='left'> 
     600      </div> 
     601      <div id="main" do='void' name='main'> 
     602     
     603        <div class='content' id='content' do='void' name='content'> 
     604          dummy content 
     605        </div> 
     606     
     607        <div id="right" do='void' name='right'> 
     608        </div> 
     609      </div> 
     610    </body> 
    545611    </html> 
    546612  lang:           en 
  • trunk/test/helpers/basic.yml

    r313 r315  
    114114anchor: 
    115115  src: "<z:anchor/>" 
    116   res: "<a name='node12'/>" 
     116  res: "<a name='node12'></a>" 
    117117 
    118118show_title_anchor: 
    119119  src: "<z:title anchor='true'/>" 
    120   res: "<a name='node12'/><span id='v_title12'>status title</span>" 
     120  res: "<a name='node12'></a><span id='v_title12'>status title</span>" 
    121121   
    122122show_attr_anchor: 
    123123  src: "<z:show attr='name' anchor='true'/>" 
    124   res: "<a name='node12'/>status" 
     124  res: "<a name='node12'></a>status" 
    125125 
    126126link_version: 
     
    134134    node: 'opening' 
    135135  src: "<z:traductions><z:each join=', '><z:link tattr='lang' dash='true' anchor='true'/></z:each></z:traductions>" 
    136   res: "<a name='version17'/><a href='#version17'>french</a>" 
     136  res: "<a name='version17'></a><a href='#version17'>french</a>" 
    137137   
    138138title: 
     
    222222 
    223223case_when: 
    224   src: "<z:case><z:when kind_of='Document'>this is a document</z:when><z:when class='Page'>Page</z:when><z:when status='pub'>Pub</z:when>" 
     224  src: "<z:case><z:when kind_of='Document'>this is a document</z:when><z:when klass='Page'>Page</z:when><z:when status='pub'>Pub</z:when>" 
    225225  tem: "<% if false -%><% elsif @node.kind_of?(Document) -%>this is a document<% elsif @node.class == Page -%>Page<% elsif @node.version[:status] == 50 -%>Pub<% end -%>" 
    226226  res: "Page" 
  • trunk/test/helpers/relations.yml

    r313 r315  
    176176pages_anchor: 
    177177  src: "<z:project><z:pages do='each' join=', '><z:show attr='name' anchor='true'/></z:pages></z:project>" 
    178   res: "<a name='node13'/>lake, <a name='node12'/>status, <a name='node27'/>track" 
     178  res: "<a name='node13'></a>lake, <a name='node12'></a>status, <a name='node27'></a>track"