lib/zena/foxy_parser.rb in zena-1.0.0.beta3 vs lib/zena/foxy_parser.rb in zena-1.0.0.rc1

- old
+ new

@@ -292,10 +292,12 @@ def make_prop(prop) prop.each do |key, value| if key == 'cached_role_ids' prop[key] = value.split(',').map {|role_name| FoxyParser.id(site, role_name.strip)} + elsif value.kind_of?(Date) + prop[key] = Time.utc(value.year, value.month, value.day) elsif value.kind_of?(String) value.gsub!(%r{\[FILE:(.*?)\]}) do File.read("#{Zena::ROOT}/#{$1}") end end @@ -313,12 +315,12 @@ if groups = v['groups'] v['groups'] = groups.split(',').map {|g| "#{site}_#{g.strip}"}.join(', ') v[:header_keys] << 'groups' end - v[:header_keys] << 'contact' - v['contact'] ||= k + v[:header_keys] << 'node' + v['node'] ||= k if v['status'] v[:header_keys] << 'status' v['status'] = User::Status[v['status'].to_sym] end @@ -347,25 +349,23 @@ if template = node.delete('template') add_template(template, name) end - if !node.has_key?('node_name') - node['node_name'] = name - node[:header_keys] << 'node_name' - end - - node['node_name'] = node['node_name'].url_name - if node.keys.include?('title') || node.keys.detect {|k| k =~ /^v_/} # need version defaults @defaults.each do |key,value| next unless key =~ /^v_/ node[key] = value end end + if !node.has_key?('_id') + node['_id'] = name + node[:header_keys] << '_id' + end + # FIXME: better filtering, in a hurry right now prop_field = nil %w{text title summary comment}.each do |k| if value = node.delete(k) unless prop_field @@ -424,24 +424,19 @@ node['inherit'] = node['inherit'] ? 'yes' : 'no' end build_inherited_fields - - # build fullpath - elements.each do |k, node| - make_paths(node, k) - end end def make_paths(node, name) if !node['fullpath'] if node['parent'] && parent = elements[node['parent']] parent_fullpath = make_paths(parent, node['parent']) # Unquote content if it was an empty quoted string. parent_fullpath = '' if parent_fullpath == "''" - node['fullpath'] = (parent_fullpath.split('/') + [node['node_name'] || name]).join('/') + node['fullpath'] = (parent_fullpath.split('/') + [node['zip']]).join('/') klass = if roles[site] && vc = roles[site][node['class']] vc['real_class'] else node['class'] end @@ -517,21 +512,24 @@ end end def insert_headers node = elements[name] - # we compute 'zip' here so that the order of the file is kept + # we compute 'zip' here so that the order of the elements in file is kept @zip_counter[site] ||= 0 if node['zip'] if node['zip'] > @zip_counter[site] @zip_counter[site] = node['zip'] end else @zip_counter[site] += 1 node['zip'] = @zip_counter[site] end + # build fullpath + make_paths(node, name) + super end def ignore_key?(k) @@ -639,11 +637,11 @@ version[:header_keys] += %w{number lang status} version['status'] = Zena::Status[version['status'].to_sym] version['prop'] ||= {} - version['prop']['title'] ||= raw_nodes[version['node']]['node_name'] || version['node'] + version['prop']['title'] ||= version['node'] if prop = version.delete('prop') version['properties'] = make_prop(prop) unless prop.blank? end @@ -788,14 +786,35 @@ private def set_defaults super elements.each do |name, col| if !col['role'] - col['role'], col['name'] = name.split('_') + if name =~ %r{^([^_]+)_(.+)$} + col['role'], col['name'] = $1, $2 + end col[:header_keys] << :role col[:header_keys] << :name end end + end + end + + + class FoxyRolesParser < FoxyParser + private + def set_defaults + super + + elements.each do |name, col| + if prop = col.delete('prop') + col[:header_keys] << :properties + col['properties'] = make_prop(prop) unless prop.blank? + end + end + end + + def make_prop(prop) + Role.encode_properties(Property::Properties[prop]) end end class FoxyNodesRolesParser < FoxyParser private