Changeset 468

Show
Ignore:
Timestamp:
2007-05-01 16:18:54 (2 years ago)
Author:
gaspard
Message:

[init,zafu] Deep changes on the way templates are included, on where they live, etc. Static zafu templates do not exist anymore, the default skin (default.tgz) is imported during 'mksite'. Controllers start to work (badly). More tests, fixes needed.

Files:

Legend:

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

    r466 r468  
    33class ApplicationController < ActionController::Base 
    44  helper_method :prefix, :zen_path, :zen_url, :data_path, :node_url, :notes, :error_messages_for, :render_errors, :processing_error 
    5   helper_method :template_text_for_url, :template_url_for_asset, :save_erb_to_url, :lang, :visitor, :fullpath_from_template_url 
     5  helper_method :get_template_text, :template_url_for_asset, :save_erb_to_url, :lang, :visitor, :fullpath_from_template_url 
    66  helper 'main' 
    77  before_filter :check_env 
     
    132132      @skin_name = @skin_name.gsub(/[^a-zA-Z]/,'') # security 
    133133      mode      = opts[:mode]   || params[:mode] 
     134      puts mode.inspect 
    134135      format    = opts[:format] || params[:format] || 'html' 
    135136      klass     = @node.class 
     
    142143        :conditions => ["tkpath IN (?) AND format = ? AND mode #{mode ? '=' : 'IS'} ? AND template_contents.node_id = nodes.id", klasses, format, mode], 
    143144        :from       => "nodes, template_contents", 
    144         :select     => "nodes.*, template_contents.*, (template_contents.skin_name = #{@skin_name}) AS skin_ok", 
     145        :select     => "nodes.*, template_contents.skin_name, template_contents.klass, (template_contents.skin_name = #{@skin_name.inspect}) AS skin_ok", 
    145146        :order      => "length(tkpath) DESC, skin_ok DESC" 
    146147      )} 
     
    154155      skin_path = "/#{template[:skin_name]}/#{template[:klass]}#{mode}.#{format}" 
    155156      main_path = "/#{visitor.lang}/main.erb" 
    156       url = "#{skin_root}/zafu.compiled#{skin_path}#{main_path}" 
    157        
    158       if File.exists?(url) 
    159         # FIXME: use CachedPage to store the compiled template instead of this File.stat test 
    160         if File.stat(url).mtime < template.v_updated_at 
    161           # template changed, render 
    162           FileUtils.rmtree("#{skin_root}/zafu.compiled#{skin_path}") 
    163           response.template.instance_variable_set(:@session, session) 
    164           skin_helper = response.template 
    165           res = ZafuParser.new_with_url(skin_path, :helper => skin_helper).render 
    166           FileUtils::mkpath(File.dirname(url)) unless File.exists?(File.dirname(url)) 
    167           File.open(url, "wb") { |f| f.syswrite(res) } 
    168         end 
     157      url = "#{skin_root}/zafu#{skin_path}#{main_path}" 
     158       
     159      # FIXME: use CachedPage to store the compiled template instead of this File.stat test 
     160      if true #!File.exists?(url) || (File.stat(url).mtime < template.v_updated_at) 
     161        # template changed, render 
     162        FileUtils.rmtree("#{skin_root}/zafu#{skin_path}") 
     163        response.template.instance_variable_set(:@session, session) 
     164        skin_helper = response.template 
     165        res = ZafuParser.new_with_url(skin_path, :helper => skin_helper).render 
     166        FileUtils::mkpath(File.dirname(url)) unless File.exists?(File.dirname(url)) 
     167        File.open(url, "wb") { |f| f.syswrite(res) } 
    169168      end 
    170169     
     
    176175    # start with a '/' we use the full url directly. 
    177176    # tested in MainControllerTest 
    178     def template_text_for_url(url) 
    179       @skin ||= {} 
    180       if url =~ /^\// 
    181         url = url[1..-1].split('/') 
    182         skin_names = [url.shift] 
    183       else 
    184         url = url.split('/') 
    185         skin_names = [@skin_name, url.shift] 
    186       end 
    187        
    188       partial = nil 
    189       skin_names.each do |skin_name| 
    190         skin = @skin[skin_name] ||= secure(Skin) { Skin.find_by_name(skin_name) } 
    191         path = (skin.fullpath.split('/') + url).join('/') 
    192         break if partial = secure(TextDocument) { TextDocument.find_by_path(path) } 
    193       end 
    194       partial ? partial.version.text : nil 
     177    def get_template_text(opts) 
     178      return nil unless doc = find_template_document(opts) 
     179      doc.version.text 
    195180    end 
    196181 
    197182    # TODO: implement 
    198183    def template_url_for_asset(opts) 
    199      
    200       # 1. find in current skin ? 
    201       url = opts[:current_template][1..-1].split('/') + opts[:src].split('/') 
    202       url.compact! 
    203       skin_name = url.shift 
    204       if @skin_obj && @skin_obj[:name] == skin_name 
    205         skin = @skin_obj 
    206       end 
    207       skin ||= secure(Skin) { Skin.find_by_name(skin_name) } 
    208       asset = skin.asset_for_path(url.join('/'), Document) 
    209       asset ? node_url(asset) : nil 
     184      return nil unless asset = find_template_document(opts) 
     185      asset ? data_path(asset, :prefix=>lang) : nil 
    210186    rescue ActiveRecord::RecordNotFound 
    211187      return nil 
     188    end 
     189     
     190    # opts should contain :current_template and :src 
     191    def find_template_document(opts) 
     192      src    = opts[:src].split('.') 
     193      mode   = src.pop 
     194      src    = src.join('.') 
     195      folder = (opts[:current_folder] && opts[:current_folder] != '') ? opts[:current_folder].split('/') : [] 
     196      @skin ||= {} 
     197       
     198      if src =~ /^\// 
     199        # /default       /fun/layout.html 
     200        # look in fun --> layout.html 
     201        url = src[1..-1].split('/') 
     202        skin_names = [url.shift] 
     203      else 
     204        # /default       default.css 
     205        # look in @skin_name, default --> default.css 
     206        url = folder + src.split('/') 
     207        skin_names = [@skin_name] 
     208        skin_names << url.shift if url.size > 1 
     209      end 
     210 
     211      document = nil 
     212      skin_names.each do |skin_name| 
     213        next unless skin = @skin[skin_name] ||= secure(Skin) { Skin.find_by_name(skin_name) } 
     214        path = (skin.fullpath.split('/') + url).join('/') 
     215        break if document = secure(TextDocument) { TextDocument.find_by_path(path) } 
     216      end 
     217      document 
    212218    end 
    213219   
     
    230236 
    231237      if template_url[0] == 'default' 
    232         "#{SITES_ROOT}/shared/zafu.compiled#{path}" 
    233       else 
    234         "#{SITES_ROOT}/#{visitor.site.host}/zafu.compiled#{path}" 
     238        "#{SITES_ROOT}/shared/zafu#{path}" 
     239      else 
     240        "#{SITES_ROOT}/#{visitor.site.host}/zafu#{path}" 
    235241      end 
    236242    end 
     
    356362    # /////// The following methods are common to controllers and views //////////// # 
    357363   
    358     def data_path(obj
    359       zen_path(obj, :format => obj.c_ext
     364    def data_path(obj, opts={}
     365      zen_path(obj, {:format => obj.c_ext}.merge(opts)
    360366    end 
    361367   
  • trunk/app/controllers/nodes_controller.rb

    r467 r468  
    2424  def index 
    2525    @node = site.root_node 
    26     params[:mode] = 'index' 
    27     respond_to do |format| 
    28       format.html { render_and_cache } 
     26    respond_to do |format| 
     27      format.html { render_and_cache(:mode => 'index') } 
    2928      format.xml  { render :xml => @node.to_xml } 
    3029    end 
     
    3332  def not_found 
    3433    @node = site.root_node 
    35     params[:mode] = 'not_found' 
    36     respond_to do |format| 
    37       format.html { render_and_cache } 
     34    respond_to do |format| 
     35      format.html { render_and_cache(:mode => 'not_found') } 
    3836      format.all { render :nothing => true } 
    3937    end 
  • trunk/app/controllers/session_controller.rb

    r455 r468  
    1515  def destroy 
    1616    reset_session 
    17     redirect_to :controller=>'node', :action=>'index', :prefix=>(visitor.site.monolingual? ? '' : visitor.lang) 
     17    redirect_to :controller=>'nodes', :action=>'index', :prefix=>(visitor.site.monolingual? ? '' : visitor.lang) 
    1818  end 
    1919   
  • trunk/app/models/node.rb

    r467 r468  
    128128  after_save         :spread_project_and_section 
    129129  before_destroy     :node_on_destroy 
    130   attr_protected     :site_id, :zip, :id, :section_id, :project_id, :publish_from, :max_status 
     130  attr_protected     :site_id, :zip, :id, :section_id, :project_id, :publish_from, :max_status, :v_status 
    131131  acts_as_secure_node 
    132132  acts_as_multiversioned 
     
    140140     
    141141    # TODO: cleanup and rename with something indicating the attrs cleanup that this method does. 
    142     def create_node(attrs) 
     142    def create_node(new_attributes) 
     143      attributes = new_attributes.stringify_keys 
     144      publish = (attributes.delete('v_status').to_i == Zena::Status[:pub]) 
     145      klass   = attributes.delete('class') || attributes.delete('klass')|| self.to_s 
     146       
    143147      scope   = self.scoped_methods[0] || {} 
    144148      visitor = scope[:create][:visitor] 
    145       klass = attrs.delete('class') || attrs.delete('klass') || attrs.delete(:class) || attrs.delete(:klass) || self.to_s 
    146149       
    147       if parent_id = attrs.delete(:_parent_id
    148         attrs.delete('parent_id') 
     150      if parent_id = attributes.delete('_parent_id'
     151        attributes.delete('parent_id') 
    149152      else 
    150          p = attrs['parent_id'] 
     153         p = attributes['parent_id'] 
    151154        if p && p.to_i.to_s != p.to_s.strip 
    152155          # find by name 
    153156          parent_id = Node.with_exclusive_scope(scope) { Node.find_by_name(p) }[:id] 
    154           attrs.delete('parent_id') 
    155         end 
    156       end 
    157  
    158       attrs.keys.each do |key| 
    159         if key.to_s =~ /^(\w+)_id$/ && ! ['rgroup_id', 'wgroup_id', 'pgroup_id', 'user_id'].include?(key.to_s
    160           attrs[key] = Node.connection.execute( "SELECT id FROM nodes WHERE site_id = #{visitor.site[:id]} AND zip = '#{attrs[key].to_i}'" ).fetch_row[0] 
    161         end 
    162       end 
    163  
    164       attrs['parent_id'] = parent_id if parent_id 
    165  
    166       attrs.delete('file') if attrs['file'] == '' 
     157          attributes.delete('parent_id') 
     158        end 
     159      end 
     160 
     161      attributes.keys.each do |key| 
     162        if key =~ /^(\w+)_id$/ && ! ['rgroup_id', 'wgroup_id', 'pgroup_id', 'user_id'].include?(key
     163          attributes[key] = Node.connection.execute( "SELECT id FROM nodes WHERE site_id = #{visitor.site[:id]} AND zip = '#{attributes[key].to_i}'" ).fetch_row[0] 
     164        end 
     165      end 
     166 
     167      attributes['parent_id'] = parent_id if parent_id 
     168 
     169      attributes.delete('file') if attributes['file'] == '' 
    167170 
    168171      klass = Module::const_get(klass.to_sym) 
    169172      raise NameError unless klass.ancestors.include?(Node) 
    170       if klass != self 
    171         klass.with_exclusive_scope(scope) { klass.create(attrs) } 
     173       
     174      node = if klass != self 
     175        klass.with_exclusive_scope(scope) { klass.create(attributes) } 
    172176      else 
    173         self.create(attrs) 
    174       end 
     177        self.create(attributes) 
     178      end 
     179      node.publish if publish 
     180      node 
    175181    rescue NameError => err 
    176182      node = self.new 
    177       node.instance_eval { @attributes = attrs } 
     183      node.instance_eval { @attributes = attributes } 
    178184      node.errors.add('klass', 'invalid') 
    179185      # This is to show the klass in the form seizure 
     
    183189    end 
    184190     
    185      
     191    # Create new nodes from the data in a folder or archive. 
    186192    def create_nodes_from_folder(opts) 
     193      # TODO: all this method needs cleaning, it's a mess. 
    187194      return nil unless (opts[:folder] || opts[:archive]) && (opts[:parent] || opts[:parent_id]) 
    188195      scope = self.scoped_methods[0] || {} 
    189196      parent_id = opts[:parent_id] || opts[:parent][:id] 
    190197      folder    = opts[:folder] 
    191       defaults  = opts[:defaults] || {} 
     198      defaults  = (opts[:defaults] || {}).stringify_keys 
     199      res       = [] 
    192200       
    193201      # create from archive 
     
    205213          # FIXME: is there a security risk here ? 
    206214          system "tar -C '#{folder}' -xz < '#{archive.path}'" 
    207           res = create_nodes_from_folder(:folder => folder, :parent_id => parent_id, :defaults => defaults) 
     215          res += create_nodes_from_folder(:folder => folder, :parent_id => parent_id, :defaults => defaults) 
    208216        ensure 
    209217          FileUtils::rmtree(folder) 
     
    232240          attrs['v_lang'] ||= lang 
    233241          current_obj = create_node(attrs) 
     242          res << current_obj 
    234243        else 
    235244          # document 
     
    253262            current_obj.remove if current_obj.v_lang == attrs['v_lang'] 
    254263            current_obj.edit!(attrs['v_lang']) 
     264             
    255265            # FIXME: This should pass through the 'attrs' cleanup... 
    256266            current_obj.update_attributes(attrs.merge(:parent_id => parent_id)) 
     267            current_obj.publish if attrs['v_status'].to_i == Zena::Status[:pub] 
    257268          elsif document 
    258269            # processing a document 
     
    265276              end 
    266277              current_obj = create_node(attrs.merge(:c_file => file, :klass => 'Document', :_parent_id => parent_id)) 
     278              res << current_obj 
    267279            end 
    268280            document = nil 
     
    270282            # processing a folder 
    271283            current_obj = create_node(attrs.merge(:_parent_id => parent_id)) 
     284            res << current_obj 
    272285          end 
    273286          index += 1 
     
    277290        if sub_folder 
    278291          # create minimal object to store the children 
    279           current_obj ||= Page.with_exclusive_scope(scope) { Page.create( defaults.merge(:parent_id => parent_id, :name => filename.split('.').first) )} 
    280           create_nodes_from_folder(:folder => sub_folder, :parent_id => current_obj[:id], :defaults => defaults) 
     292          unless current_obj 
     293            current_obj = Page.with_exclusive_scope(scope) { Page.create( defaults.merge(:parent_id => parent_id, :name => filename.split('.').first) )} 
     294            current_obj.publish if defaults['v_status'].to_i == Zena::Status[:pub] 
     295            res << current_obj 
     296          end 
     297          res += create_nodes_from_folder(:folder => sub_folder, :parent_id => current_obj[:id], :defaults => defaults) 
    281298        elsif document && !current_obj   
    282299          # processing a document 
     
    290307            end 
    291308            current_obj = Document.with_exclusive_scope(scope) { Document.create(defaults.merge(:c_file => file, :parent_id => parent_id, :name => filename)) } 
     309            current_obj.publish if defaults['v_status'].to_i == Zena::Status[:pub] 
     310            res << current_obj 
    292311          end 
    293312        end 
    294313      end 
    295       current_obj 
     314      res 
    296315    end 
    297316 
     
    874893      unless all_children.size == 0 
    875894        errors.add('base', "contains subpages") 
    876         return false 
     895        return false§ 
    877896      else   
    878897        # expire cache 
     
    890909    # Called after an node is 'removed' 
    891910    def after_remove 
    892       if self[:max_status] < Zena::Status[:pub] 
     911      if (self[:max_status] < Zena::Status[:pub]) && !@new_record_before_save 
    893912        # not published any more. 'remove' documents 
    894913        sync_documents(:remove) 
     
    900919    # Called after an node is 'proposed' 
    901920    def after_propose 
     921      return true if @new_record_before_save 
    902922      sync_documents(:propose) 
    903923    end 
     
    905925    # Called after an node is 'refused' 
    906926    def after_refuse 
     927      return true if @new_record_before_save 
    907928      sync_documents(:refuse) 
    908929    end 
     
    910931    # Called after an node is published 
    911932    def after_publish(pub_time=nil) 
     933      return true if @new_record_before_save 
    912934      sync_documents(:publish, pub_time) 
    913935    end 
  • trunk/app/models/page.rb

    r463 r468  
    1515      Page 
    1616    end 
    17      
    18     # Find an node by it's full path. Cache 'fullpath' if found. 
    19     def find_by_path(path) 
    20       return nil unless scope = scoped_methods[0] 
    21       return nil unless scope[:create] 
    22       visitor = scoped_methods[0][:create][:visitor] # use secure scope to get visitor 
    23       node = self.find_by_fullpath(path) 
    24       if node.nil? 
    25         path = path.split('/') 
    26         last = path.pop 
    27         Node.with_exclusive_scope do 
    28           node = Node.find(visitor.site[:root_id]) 
    29           path.each do |p| 
    30             raise ActiveRecord::RecordNotFound unless node = Node.find_by_name_and_parent_id(p, node[:id]) 
    31           end 
    32         end 
    33         raise ActiveRecord::RecordNotFound unless node = self.find_by_name_and_parent_id(last, node[:id]) 
    34         path << last 
    35         node.fullpath = path.join('/') 
    36         # bypass callbacks here 
    37         Node.connection.execute "UPDATE #{Node.table_name} SET fullpath='#{path.join('/').gsub("'",'"')}' WHERE id='#{node[:id]}'" 
    38       end 
    39       node 
    40     end 
    41      
     17   
    4218    def select_classes 
    4319      list = subclasses.inject([]) do |list, k| 
  • trunk/app/models/site.rb

    r467 r468  
    132132      # =========== LOAD INITIAL DATA (default skin) ============= 
    133133       
    134       site.send(:secure,Node) { Node.create_nodes_from_folder(:archive => File.join(RAILS_ROOT, 'db', 'init', 'default.tgz'), :parent_id => root[:id], :defaults => { :rgroup_id => pub[:id], :wgroup_id => sgroup[:id], :pgroup_id => admin[:id] } ) } 
     134      nodes = site.send(:secure,Node) { Node.create_nodes_from_folder(:archive => File.join(RAILS_ROOT, 'db', 'init', 'default.tgz'), :parent_id => root[:id], :defaults => { :v_status => Zena::Status[:pub], :rgroup_id => pub[:id], :wgroup_id => sgroup[:id], :pgroup_id => admin[:id] } ) } 
    135135       
    136136       
  • trunk/app/models/template.rb

    r467 r468  
    2020      version.content.format = nil 
    2121    end 
    22     super 
     22    if str =~ /(.+)\.(.*)/ 
     23      super($1) 
     24    else 
     25      super 
     26    end 
    2327  end 
    2428   
  • trunk/lib/multiversion.rb

    r465 r468  
    238238        end 
    239239         
    240         # Update an node's attributes or the node's version/content attributes. If the hash contains only 
    241         # :v_... or :c_... keys, then only the version will be saved. If the hash does not contain any :v_... or :c_... 
     240        # Update an node's attributes or the node's version/content attributes. If the attributes contains only 
     241        # :v_... or :c_... keys, then only the version will be saved. If the attributes does not contain any :v_... or :c_... 
    242242        # attributes, only the node is saved, without creating a new version. 
    243         def update_attributes(hash
     243        def update_attributes(new_attributes
    244244          redaction_attr = false 
    245245          node_attr      = false 
    246           hash.each do |k,v| 
     246           
     247          attributes = new_attributes.stringify_keys 
     248          attributes = remove_attributes_protected_from_mass_assignment(attributes) 
     249          attributes.each do |k,v| 
    247250            next if k.to_s == 'id' # just ignore 'id' (cannot be set but is often around) 
    248251            if k.to_s =~ /^(v_|c_)/ 
     
    257260          end 
    258261          unless node_attr 
    259             hash.each do |k,v| 
     262            attributes.each do |k,v| 
    260263              next if k.to_s == 'id' # just ignore 'id' (cannot be set but is often around) 
    261264              self.send("#{k}=".to_sym, v) 
     
    311314            end 
    312315            if @version.nil? 
    313               raise Exception.new("Node #{self[:id]} does not have any version !!") 
     316              raise Exception.new("#{self.class} #{self[:id]} does not have any version !!") 
    314317            end 
    315318          end   
  • trunk/lib/parser/lib/parser.rb

    r463 r468  
    99    end 
    1010 
    11     def template_text_for_url(url) 
    12       url = url[1..-1] if url[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. 
     11    def get_template_text(opts) 
     12      src    = opts[:src] 
     13      folder = (opts[:current_folder] && opts[:current_folder] != '') ? opts[:current_folder][1..-1].split('/') : [] 
     14      src = src[1..-1] if src[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. 
     15      url = (folder + src.split('/')).join('_') 
    1316       
    14       if test = @strings[url.gsub('/','_')
     17      if test = @strings[url
    1518        test['src'] 
    1619      else 
     
    5558    def new_with_url(url, opts={}) 
    5659      helper = opts[:helper] || ParserModule::DummyHelper.new 
    57       text, absolute_url = self.find_template_text(url,helper) 
     60      text, absolute_url = self.get_template_text(url,helper) 
    5861      current_folder     = absolute_url ? absolute_url.split('/')[1..-2].join('/') : nil 
    5962      self.new(text, :helper=>helper, :current_folder=>current_folder, :included_history=>[absolute_url]) 
     
    6265    # Retrieve the template text in the current folder or as an absolute path. 
    6366    # This method is used when 'including' text 
    64     def find_template_text(url, helper, current_folder=nil) 
     67    def get_template_text(url, helper, current_folder=nil) 
    6568       
    6669      if (url[0..0] != '/') && current_folder 
     
    6871      end 
    6972       
    70       text = helper.send(:template_text_for_url, url) || "<span class='parser_error'>template '#{url}' not found</span>" 
     73      text = helper.send(:get_template_text, :src=>url, :current_folder=>'') || "<span class='parser_error'>template '#{url}' not found</span>" 
    7174      url = "/#{url}" unless url[0..0] == '/' # has to be an absolute path 
    7275      return [text, url] 
     
    209212    @options[:included_history] ||= [] 
    210213     
    211     @text, absolute_url = self.class.find_template_text(@params[:template], @options[:helper], @options[:current_folder]) 
     214    @text, absolute_url = self.class.get_template_text(@params[:template], @options[:helper], @options[:current_folder]) 
    212215     
    213216    if absolute_url 
  • trunk/lib/parser/lib/rules/zafu.rb

    r463 r468  
    7474    def r_rename_asset 
    7575      return expand_with unless @html_tag 
    76       unless @params[:src][0..0] == '/' 
    77         opts = {:src => @params[:src]} 
    78         case @html_tag 
    79         when 'link' 
    80           if @params[:rel].downcase == 'stylesheet' 
    81             opts[:type] = :stylesheet 
    82           else 
    83             opts[:type] = :link 
    84           end 
    85         else 
    86           opts[:type] = @html_tag.to_sym 
    87         end 
    88         opts[:current_template] = @options[:included_history].last 
    89         @params[:src] = @options[:helper].send(:template_url_for_asset, opts) 
    90       end 
     76      opts = {} 
     77      case @html_tag 
     78      when 'link' 
     79        key = :href 
     80        if @params[:rel].downcase == 'stylesheet' 
     81          opts[:type] = :stylesheet 
     82        else 
     83          opts[:type] = :link 
     84        end 
     85      else 
     86        key = :src 
     87        opts[:type] = @html_tag.to_sym 
     88      end 
     89       
     90      opts[:src] = @params[key] 
     91      if opts[:src] && opts[:src][0..0] != '/' 
     92        opts[:current_folder] = @options[:current_folder] 
     93        @params[key] = @options[:helper].send(:template_url_for_asset, opts) 
     94      end 
     95       
    9196      res   = "<#{@html_tag}#{params_to_html(@params)}" 
    9297      @html_tag_done = true 
     
    243248        flush $& 
    244249        @end_tag_count += 1 unless $2 == '/' 
    245       elsif @text =~ /\A<(link|img|script).*src\s*=
     250      elsif @text =~ /\A<(link|img|script)
    246251        # puts "HTML:[#{$&}]}" # html 
    247252        make(:asset) 
    248253      elsif @text =~ /\A[^>]*?>/ 
    249254        # html tag 
     255        # puts "OTHER:[#{$&}]" 
    250256        store opts[:space_before] 
    251257        flush $& 
  • trunk/lib/parser/test/parser_test.rb

    r463 r468  
    3333  testfile :zafu, :zafu_asset, :zafu_insight, :zazen 
    3434  def test_single 
    35     do_test('zafu', 'complex_example') 
     35    do_test('zafu_asset', 'change_stylesheet') 
    3636  end 
     37   
    3738  def test_zazen_image_no_image 
    3839    file = 'zazen' 
  • trunk/lib/parser/test/zafu_asset.yml

    r279 r468  
    33  res: "this is just <h2 class='any'>a title</h2>" 
    44 
    5 change_stylesheet_src
    6   src: "<link src='local/test.css' rel='stylesheet' type='text/css'/>" 
    7   res: "<link rel='stylesheet' src='/test_stylesheet/local/test.css' type='text/css'/>" 
     5change_stylesheet
     6  src: "<link href='local/test.css' rel='stylesheet' type='text/css'/>" 
     7  res: "<link href='/test_stylesheet/local/test.css' rel='stylesheet' type='text/css'/>" 
    88 
    99ignore_absolute_path: 
    10   src: "<link rel='stylesheet' type='text/css' src='/absolute/test.css'/>" 
    11   res: "<link rel='stylesheet' src='/absolute/test.css' type='text/css'/>" 
     10  src: "<link rel='stylesheet' type='text/css' href='/absolute/test.css'/>" 
     11  res: "<link href='/absolute/test.css' rel='stylesheet' type='text/css'/>" 
     12 
     13bad_link: 
     14  src: "<link rel='stylesheet'/>" 
     15  res: "<link rel='stylesheet'/>" 
    1216   
    1317change_img_src: 
  • trunk/test/functional/application_controller_test.rb

    r455 r468  
    2121  # visitor tested in multiple_hosts integration test 
    2222   
     23  def test_find_template_document 
     24    res = @controller.instance_variable_set(:@skin_name, 'wiki') 
     25    assert false, "finish test" 
     26  end 
     27 
    2328  def test_template_url_any_project 
    2429    without_files('app/views/templates/compiled') do 
  • trunk/test/helpers/testhelp.rb

    r455 r468  
    66 
    77class TestController < ApplicationController 
    8   helper_method :template_text_for_url, :template_url_for_asset, :save_erb_to_url 
     8  helper_method :get_template_text, :template_url_for_asset, :save_erb_to_url 
    99  before_filter :set_context 
    1010  before_filter :authorize 
     
    3434  def authorize 
    3535  end 
     36   
    3637  def set_env 
    3738  end 
     
    5556  end 
    5657 
    57   def template_text_for_url(url) 
    58     url = url[1..-1] # strip leading '/' 
    59     @current_template = url 
    60     url = url.gsub('/','_') 
    61     if test = @@templates[url] 
     58  def get_template_text(url) 
     59    src    = opts[:src] 
     60    folder = (opts[:current_folder] && opts[:current_folder] != '') ? opts[:current_folder][1..-1].split('/') : [] 
     61    src = src[1..-1] if src[0..0] == '/' # just ignore the 'relative' or 'absolute' tricks. 
     62    url = (folder + src.split('/')).join('_') 
     63     
     64    if test = @strings[url] 
    6265      test['src'] 
    6366    else 
  • trunk/test/unit/node_test.rb

    r467 r468  
    109109    login(:ant) 
    110110    test_page = secure(Node) { Node.create(:name=>"yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) } 
    111     err test_page 
    112111    assert ! test_page.new_record? , "Not a new record" 
    113112    assert_equal nodes_id(:cleanWater), test_page.parent[:id] 
     113  end 
     114   
     115  def test_cannot_update_v_status 
     116    login(:ant) 
     117    test_page = secure(Node) { nodes(:status) } 
     118    assert_equal 2, test_page.v_number 
     119    test_page.update_attributes( :v_status => Zena::Status[:pub], :v_title => "New funky title") 
     120    assert_equal 3, test_page.v_number 
     121    assert_equal Zena::Status[:red], test_page.v_status 
    114122  end 
    115123   
     
    836844    parent = secure(Project) { Project.create(:name => 'import', :parent_id => nodes_id(:zena)) } 
    837845    assert !parent.new_record?, "Not a new record" 
    838     secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => parent[:id] )} 
     846    nodes = secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => parent[:id] )} 
    839847    children = parent.children 
    840848    assert_equal 2, children.size 
    841     bird, simple = children 
     849    assert_equal 2, nodes.size 
     850    bird, simple = nodes 
    842851     
    843852    assert_equal 'bird', bird[:name] 
     
    845854    assert_equal 'The sky is blue', simple.v_title 
    846855    assert_equal 'jpg', bird.c_ext 
    847     assert_equal 'Lucy in the sky', bird.v_title 
    848     versions = bird.versions 
     856    assert_equal 'Le septiÚme ciel', bird.v_title 
     857    versions = secure(Node) { Node.find(bird[:id]) }.versions 
    849858    assert_equal 2, versions.size 
    850859    assert_equal 'fr', versions[0].lang 
     
    869878  end 
    870879   
     880  def test_create_nodes_from_folder_with_publish 
     881    login(:tiger) 
     882    nodes = secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => nodes_id(:zena) )} 
     883    assert_equal Zena::Status[:red], nodes[0].v_status 
     884     
     885    nodes = secure(Node) { Node.create_nodes_from_folder(:folder => File.join(RAILS_ROOT, 'test', 'fixtures', 'import'), :parent_id => nodes_id(:cleanWater), :defaults => { :v_status => Zena::Status[:pub] }) } 
     886    assert_equal Zena::Status[:pub], nodes[0].v_status 
     887  end 
     888   
    871889  def test_create_nodes_from_archive 
    872890    login(:tiger)