Skip to content

Commit

Permalink
Custome tag lib in liquid fixed bugs on caching
Browse files Browse the repository at this point in the history
  • Loading branch information
anupnivargi committed Feb 16, 2010
1 parent b49b933 commit fb699db
Show file tree
Hide file tree
Showing 78 changed files with 5,372 additions and 516 deletions.
6 changes: 3 additions & 3 deletions app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def get_allowed_item_types(container=nil)
# - current_workspace : Workspace instance (default: nil)
def item_types_allowed_to(user, action, current_container=nil)
if current_container
items = (current_container.available_items.to_s.split(',') & @configuration['sa_items']).delete_if{ |e| !user.has_container_permission(current_container.id, e, action, current_container.class.to_s) }
@items ||= (current_container.available_items.to_s.split(',') & @configuration['sa_items']).delete_if{ |e| !user.has_container_permission(current_container.id, e, action, current_container.class.to_s) }
else
items = available_items_list.delete_if{ |e| Workspace.allowed_user_with_permission(user, e+'_'+action,'workspace').size == 0 }
@items ||= available_items_list.delete_if{ |e| Workspace.allowed_user_with_permission(user, e+'_'+action,'workspace').size == 0 }
end
items.sort!
@items.sort!
end

# Method checking superadministrator role for current user
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setting_searching_params(*args)
options = options[:from_params]#.merge({ :cat => nil, :models => nil })
end
return {
:user => @current_website.creator,
:user => $current_website.creator,
:permission => 'show',
:models => options[:m] || (options[:cat] ? ((options[:cat] == 'item') ? @configuration['sa_items'] : [options[:cat]]) : @configuration['sa_items']),
:containers => options[:containers],
Expand All @@ -36,11 +36,11 @@ def current_website
site_url = params[:site_url] || request.url.split('//').second.split('/').first
#wsu = WebsiteUrl.find_by_sql("SELECT website_urls.website_id FROM website_urls WHERE website_urls.name = '#{ws_url}' LIMIT 1").first
if params[:site_title] && Website.exists?(:title => params[:site_title], :website_state => 'published')
@current_website = Website.find_by_title(params[:site_title])
$current_website ||= @current_website ||= Website.find_by_title(params[:site_title])
session[:website_id] = @current_website.id
return true
elsif WebsiteUrl.exists?(:name => site_url)
@current_website = WebsiteUrl.find_by_name(site_url).website
$current_website = @current_website ||= WebsiteUrl.find_by_name(site_url).website
session[:website_id] = @current_website.id
return true
else
Expand Down
24 changes: 17 additions & 7 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module ApplicationHelper
#include TagLib

include TagLib
def layout(website)
if WEBSITE_TEMPLATES.include?(website.template)
render :file => WEBSITE_TEMPLATES_FOLDER + "/" + website.template + "/layout.html.erb"
Expand All @@ -11,9 +10,20 @@ def layout(website)
end
end

# def liquidize(content)
# @template = Liquid::Template.parse(content)
# @template.render('page_title' => page_title,
# 'page_body' => (render :partial => 'page'))
# end
def liquidize(content)
@template = Liquid::Template.parse(content)
@template.render('page_title' => page_title,
'page_description' => page_description,
'page_keywords' => page_keywords,
'path' => path,
'site_title' => site_title,
'site_description' => site_description,
'powered_by' => powered_by,
'page_body' => page_body)
end

def liquidize_page_body(content)
@template = Liquid::Template.parse(content)
@template.render('contact_form' => (render :partial => 'websites/contact'))
end
end
1 change: 0 additions & 1 deletion app/helpers/websites_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module WebsitesHelper
include TagLib

def menu_generator(ul_class='', li_class='')
str = ""
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/websites/application.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= layout(@current_website) %>
<%= liquidize(layout(@current_website)) %>
3 changes: 2 additions & 1 deletion app/views/websites/_contact.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% form_for @person, :url => contacts_path, :html => {:method => :post, :onsubmit => 'return validate_contact();'} do |f| %>
<% @email_values = session[:email] || {} %>
<% form_for @person = (session[:person] || Person.new), :url => contacts_path, :html => {:method => :post, :onsubmit => 'return validate_contact();'} do |f| %>
<% if !@person.errors.empty? %>
<% attributes = {'first_name' => 'Nom','last_name' => 'Prénom', 'email' => 'Email', 'primary_phone' => 'Téléphone'} %>
<ul style="height:auto;" >
Expand Down
3 changes: 1 addition & 2 deletions lib/authorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def acts_as_authorizable
module InstanceMethods
# Generic method called on an instance to check if the permission is matching or no
def has_permission_for?(permission, user, container)
return @aa ||= accepting_action(user, permission, container)
return accepting_action(user, permission, container)
end
end

Expand Down Expand Up @@ -236,7 +236,6 @@ def accepting_action(user, action, container, active=true)
end
end # if item available in ws
end
# go away
false
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/authorized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module InstanceMethods
# Usage :
# <tt>user.system_role</tt>
def system_role
@role ||= Role.find(self.system_role_id)
@role ||= Role.find(self.system_role_id, :include => [:permissions])
end

# Method returning true if the user has the system role passed in params, false else
Expand All @@ -36,7 +36,7 @@ def system_role
# Usage :
# <tt>user.has_system_role('admin')</tt>
def has_system_role(role_name)
(self.system_role.name == role_name) || self.system_role.name == 'superadmin'
(self.system_role.name == role_name) || (self.system_role.name == 'superadmin')
end

# Method returning true if the user has the workspace role passed in params, false else
Expand Down Expand Up @@ -67,8 +67,8 @@ def system_permissions
# Usage :
# <tt>user.workspace_permissions(2)</tt>
def container_permissions(container_id, container)
if @users_container ||= UsersContainer.find(:first, :conditions => {:user_id => self.id, :containerable_id => container_id, :containerable_type => container})
return @permissions ||= @users_container.role.permissions
if @users_container = UsersContainer.find(:first, :conditions => {:user_id => self.id, :containerable_id => container_id, :containerable_type => container})
return @permissions = @users_container.role.permissions
else
return []
end
Expand Down
60 changes: 60 additions & 0 deletions lib/custom_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module CustomTags
class Item < Liquid::Tag
#include ActionView::Helpers::UrlHelper
def initialize(tag_name, markup, tokens)
super
p markup
@tag_name = tag_name
@args = eval('{' + markup + '}')
end

def render(context)
send(@args[:item].pluralize, @args)
end

ITEMS.each do |item|
define_method item.pluralize.to_sym do |*args|
options = args.extract_options!
items = item.classify.constantize.get_da_objects_list(build_params(options.merge!(:items => [item])))
str = ""
items.each do |item|
str += "<li><a href='/#{item.class.to_s.underscore}/#{item.title_sanitized}'>#{item.title}</a></li>"
#str += "<li>" item.title, "/#{item}/#{item.title_sanitized}") + "</li>"
end
return str
end
end

# def items(*args)
# options = args.extract_options!
# options[:items] ||= @current_website.available_items.split(',')
# search = Search.new(setting_searching_params(:from_params => build_params(options)))
# items = search.do_search
# str = ""
# items.each do |item|
# str += "<li>" + (link_to item.title, "/#{item.class.to_s.underscore}/#{item.title_sanitized}") + "</li>"
# end
# return str
# end

protected

def build_params(options)
options[:field] ||= 'created_at'
options[:order] ||= 'desc'
options[:limit] ||= 5
hash = {
:models => options[:items],
:filter => { :field => options[:field], :way => options[:order]},
:pagination => { :page => options[:page] || 1, :per_page => options[:limit]},
:containers => {:website => [$current_website.id.to_s]},
:user => $current_website.creator,
:permission => 'show',
:opti => options[:opti] ? options[:opti] : 'skip_pag_but_filter'
}
hash
end

end
Liquid::Template.register_tag('items', Item)
end
1 change: 0 additions & 1 deletion lib/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def acts_as_searchable(*args)
def get_da_objects_list(*args)
options = args.extract_options!
#req is of type of the object in use. Article, Image....
"Inside get_da_objects_list"
req = self
# 1. text if there
req = req.searching_text_with_xapian(options[:full_text]) if options[:full_text]
Expand Down
37 changes: 15 additions & 22 deletions lib/tag_lib.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
module TagLib

# class Item < Liquid::Tag
# def initialize(tag_name, markup, tokens)
# super
# p markup
# @args = markup
# end

# def render(context)
# articles(:field => @field, :order => @order, :limit => @limit)
# end
# end
# Liquid::Template.register_tag('items', Item)
include CustomTags

def page_body
liquidize_page_body(render :partial => 'websites/page')
end

def page_title
result ||= @site_page || @item || @current_website
Expand Down Expand Up @@ -46,16 +37,16 @@ def powered_by
end

ITEMS.each do |item|
define_method item.pluralize.to_sym do |*args|
options = args.extract_options!
items = item.classify.constantize.get_da_objects_list(setting_searching_params(:from_params => build_params(options.merge!(:items => [item]))))
str = ""
items.each do |item|
str += "<li>" + (link_to item.title, "/#{item}/#{item.title_sanitized}") + "</li>"
define_method item.pluralize.to_sym do |*args|
options = args.extract_options!
items = item.classify.constantize.get_da_objects_list(setting_searching_params(:from_params => build_params(options.merge!(:items => [item]))))
str = ""
items.each do |item|
str += "<li>" + (link_to item.title, "/#{item}/#{item.title_sanitized}") + "</li>"
end
return str
end
return str
end
end

def items(*args)
options = args.extract_options!
Expand All @@ -79,7 +70,9 @@ def build_params(options)
:m => options[:items],
:by => "#{options[:field]}-#{options[:order]}",
:per_page => options[:limit],
:containers => {:website => [@current_website.id.to_s]}
:containers => {:website => ['1']}
}
end


end
Loading

0 comments on commit fb699db

Please sign in to comment.