Skip to content

Commit

Permalink
Fixed "static" brick to use zafu stored in file system. Fixed ajax bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jun 28, 2012
1 parent 59e98a0 commit 16ee2f4
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 109 deletions.
2 changes: 2 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Enabled rebuilding of templates on partial query.
* Enabled 'hash' property type.
* Enabled javascript on toggle.
* Enabled "static" brick to use zafu stored in brick file system.

* Minor changes
* Fixed label traduction for param.
Expand All @@ -24,6 +25,7 @@
* Added support for "target" in [zazen] when rendering links.
* Fixed kpath propagation to relations on kpath change.
* Fixed [block] in [block] with [filter] bug.
* Added support for KPATH_VALUE(ClassName) in custom queries. <==== TODO: Document

== 1.2.0, 1.2.1 2012-05-01

Expand Down
2 changes: 1 addition & 1 deletion app/models/relation_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def find_by_role(role, source_kpath = nil)
# The finder makes sure the class path is compatible with the node's class/virtual_class given as parameter.
def get_proxy(node, role)
# TODO: use find_by_role(role, node.kpath) when all tests are clear
rel = find_by_role(role)
rel = find_by_role(role, node.kpath)
if rel && (node.new_record? || node.kpath =~ /\A#{rel.this_kpath}/)
rel.start = node
rel
Expand Down
9 changes: 5 additions & 4 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def import(definitions, delete = false)
raise Exception.new("Importation needs to start with a real class: '#{name}' is not a real class.")
else
# start importing
res += import_all(klass, definition, post_import)
res += import_vclass(nil, name, definition, post_import)
end
end

Expand Down Expand Up @@ -119,7 +119,7 @@ def import_role(superclass, name, definition)

def import_vclass(superclass, name, definition, post_import)
res = []
vclass = ::Role.find_by_name_and_site_id(name, current_site.id)
vclass = VirtualClass[name]
if vclass && vclass.class != VirtualClass
# Change from role to vclass ?
# Reject
Expand All @@ -129,7 +129,7 @@ def import_vclass(superclass, name, definition, post_import)
vclass = VirtualClass.new(:name => name, :superclass => superclass)
vclass.save!
end

res << vclass

# 2. create or update columns (never delete)
Expand All @@ -153,7 +153,8 @@ def import_vclass(superclass, name, definition, post_import)
# We do not clear attributes (import is ADD/UPDATE only).
end
end
vclass.save!

vclass.save! unless vclass.real_class?

# 5. create or update sub-classes
res += import_all(vclass, definition, post_import)
Expand Down
47 changes: 28 additions & 19 deletions bricks/static/lib/bricks/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ module Bricks
module Static
ELEM = "([a-zA-Z_]+)"
ELEM_REGEXP = %r{^#{ELEM}$}
SECURE_PATH_REGEXP = %r{^[a-zA-Z_/]+$}
SECURE_PATH_REGEXP = %r{^[a-zA-Z_/\-]+$}
STATIC_SKIN_REGEXP = %r{^#{ELEM}-#{ELEM}$}
ZAFU_URL_REGEXP = %r{^\$#{ELEM}-#{ELEM}/(.+)$}
BRICK_NAME_REGEXP = %r{^#{RAILS_ROOT}/bricks/#{ELEM}/zena/skins$}

module ControllerMethods
def self.included(base)
base.alias_method_chain :get_template_text, :static
base.alias_method_chain :template_url_for_asset, :static
base.alias_method_chain :get_best_template, :static
end

def get_template_text_with_static(path, section_id = nil)
def get_template_text_with_static(path, section_id = nil, opts = {})
puts [path, section_id, opts].inspect
if path =~ ZAFU_URL_REGEXP
brick_name, skin_name, path = $1, $2, $3
text_from_static(brick_name, skin_name, path)
elsif section_id.nil? && @static_brick_name && @static_skin_name
text_from_static(@static_brick_name, @static_skin_name, path)
Skin.text_from_static(brick_name, skin_name, path, opts)
elsif !(path =~ %r{^(/|\$)}) && section_id.nil? && @static_brick_name && @static_skin_name
Skin.text_from_static(@static_brick_name, @static_skin_name, path, opts)
else
get_template_text_without_static(path, section_id)
get_template_text_without_static(path, section_id, opts)
end
end

Expand Down Expand Up @@ -58,25 +59,32 @@ def get_best_template_with_static(kpaths, format, mode, skin)
# ===> blog/img/style.css ==> brick path/zena/skins/ blog/img/style.css
# Cache in public directory
# FIXME: clear_cache should erase /home/static

private
def text_from_static(brick_name, skin_name, path)
if path =~ SECURE_PATH_REGEXP
abs_path = File.join(
RAILS_ROOT, 'bricks', brick_name,
'zena', 'skins', skin_name, path + '.zafu')
File.exist?(abs_path) ? File.read(abs_path) : nil
end
end
end # ControllerMethods

module SkinMethods
def self.included(base)
base.property do |p|
p.string 'z_static'
end


base.safe_property 'z_static'
base.validate :validate_z_static

# We move this method here so that we do not need to reference
# Bricks::Static in I18n when static brick is disabled.
def base.text_from_static(brick_name, skin_name, path, opts)
if path =~ SECURE_PATH_REGEXP
fullpath = "$#{brick_name}-#{skin_name}/#{path}"
section_id = nil
template = nil
abs_path = File.join(
RAILS_ROOT, 'bricks', brick_name,
'zena', 'skins', skin_name, path + "." + (opts[:ext] || 'zafu'))
if text = File.exist?(abs_path) ? File.read(abs_path) : nil
return text, fullpath, section_id, template
end
end
end
end

private
Expand All @@ -93,7 +101,8 @@ def self.included(base)
base.alias_method_chain :rebuild_index, :static
end

def rebuild_index_with_static(nodes = nil, page = nil, page_count = nil) if !page
def rebuild_index_with_static(nodes = nil, page = nil, page_count = nil)
if !page
Zena::SiteWorker.perform(self, :rebuild_static_index, nil)
end
rebuild_index_without_static(nodes, page, page_count)
Expand Down
6 changes: 4 additions & 2 deletions config/bricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ development:
captcha: ON
grid: ON
acls: ON
static: OFF
static: ON
gefo: ON
sphinx:
switch: OFF
activate_if:
Expand Down Expand Up @@ -74,7 +75,8 @@ production:
captcha: ON
grid: ON
acls: ON
static: OFF
static: ON
gefo: ON
single: OFF
sphinx:
switch: OFF
Expand Down
2 changes: 1 addition & 1 deletion lib/zafu/controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def fquote(text)

# This method should return the template for a given 'src' and
# 'base_path'.
def get_template_text(path, base_path)
def get_template_text(path, base_path, opts={})
[path, "#{base_path}/#{path}"].each do |p|
begin
t = self.view_paths.find_template(p, 'html') # FIXME: format ?
Expand Down
4 changes: 2 additions & 2 deletions lib/zafu/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def new_with_url(path, opts={})

# Retrieve the template text in the current folder or as an absolute path.
# This method is used when 'including' text
def get_template_text(path, helper, base_path=nil)
res = helper.send(:get_template_text, path, base_path)
def get_template_text(path, helper, base_path=nil, opts={})
res = helper.send(:get_template_text, path, base_path, opts)
return [parser_error("template '#{path}' not found", 'include'), nil, nil] unless res
res
end
Expand Down
31 changes: 20 additions & 11 deletions lib/zafu/process/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ def self.included(base)
end

def r_form
unless @params[:on].nil? || @params[:on].split(',').include?(@context[:ajax_action])
return ''
if node.dom_prefix
fnode = node
else
fnode = node.dup
fnode.dom_prefix = dom_name
end
with_context(:node => fnode) do

unless @params[:on].nil? || @params[:on].split(',').include?(@context[:ajax_action])
return ''
end

return parser_error('Cannot render update form in list context.') if node.list_context?
return parser_error('Cannot render update form in list context.') if node.list_context?

options = form_options
options = form_options

@markup.set_id(options[:id]) if options[:id]
@markup.set_param(:style, options[:style]) if options[:style]
@markup.set_id(options[:id]) if options[:id]
@markup.set_param(:style, options[:style]) if options[:style]

if descendant('form_tag')
# We have a specific place to insert our form
out expand_with(:form_options => options, :form => self, :form_prefix => dom_name)
else
r_form_tag(options)
if descendant('form_tag')
# We have a specific place to insert our form
out expand_with(:form_options => options, :form => self, :form_prefix => dom_name)
else
r_form_tag(options)
end
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/zena/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def self.included(base)

::Skin.class_eval do
Zena::Use.each_module_for('Skin') do |mod|
puts mod
include mod
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/test_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def set_context
end
end

def get_template_text(path, base_path)
def get_template_text(path, base_path, opts={})
folder = base_path.blank? ? [] : base_path[1..-1].split('/')
if path[0..0] == '/'
# just ignore the 'relative' or 'absolute' tricks.
Expand Down
5 changes: 2 additions & 3 deletions lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ module Display
module Common
def icon_finder
if rel = RelationProxy.find_by_role('icon')
finder = 'icon or image'
"icon or image group by id,l_id order by l_id desc, position asc"
else
finder = 'image'
"image order by position asc"
end
"#{finder} group by id,l_id order by l_id desc, position asc"
end
end # Common

Expand Down
12 changes: 7 additions & 5 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def form_options

opts[:form_cancel] = %Q{
<% if #{node}.new_record? %>
#{cancel_pre}<a href='javascript:void(0)' onclick='[\"<%= params[:dom_id] %>_add\", \"<%= params[:dom_id] %>\"].each(Element.toggle);return false;'>#{cancel_text}</a>#{cancel_post}
#{cancel_pre}<a href='javascript:void(0)' onclick='[\"<%= params[:dom_id] %>_add\", \"<%= params[:dom_id] %>_0\"].each(Element.toggle);return false;'>#{cancel_text}</a>#{cancel_post}
<% else %>
#{cancel_pre}<%= link_to_remote(#{cancel_text_ruby}, :url => #{node.form_name}_path(#{node}.zip) + \"/zafu?t_url=#{CGI.escape(template_url)}&dom_id=\#{params[:dom_id]}#{@context[:has_link_id] ? "&link_id=\#{#{node}.link_id}" : ''}\", :method => :get) %>#{cancel_post}
<% end %>
Expand Down Expand Up @@ -704,11 +704,13 @@ def get_input_params(params = @params)
res[:name] = "node[<%= #{node}.name %>]"
res[:value] = "<%= fquote #{node(Node)}.prop[#{node}.name] %>"
end

if node.dom_prefix && !params[:param]
res[:id] = params[:id] || "#{@context[:form_prefix]}_#{attribute}"

if params[:id]
res[:id] = params[:id]
#elsif params[:param]
# res[:id] = "#{node.dom_prefix}_#{params[:param]}"
else
res[:id] = params[:id] if params[:id]
res[:id] = "#{node.dom_prefix}_#{attribute}"
end

if params[:type] == 'checkbox' && sub_attr_ruby
Expand Down

0 comments on commit 16ee2f4

Please sign in to comment.