Skip to content

Commit

Permalink
Lightweight site template support (for jqtouch)
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Jun 24, 2010
1 parent 03b188d commit ad68c2c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 62 deletions.
3 changes: 1 addition & 2 deletions app/models/site_template.rb
Expand Up @@ -84,10 +84,9 @@ def domain_file_id=(df_id)

# Make sure the updating works with setting the file as well as the id
def domain_file=(df); self.domain_file_id=(df.id); end

protected


def initial_parser_context

parser_context = SiteTemplate::InitialParserContext.new do |c|
Expand Down
2 changes: 0 additions & 2 deletions app/views/edit/page.rhtml
Expand Up @@ -5,8 +5,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script> var AUTH_TOKEN = "<%= form_authenticity_token.to_s %>";</script>
<%= stylesheet_link_tag 'common' %>
<%= @output.head %>
<%= theme_stylesheet_link_tag "main" %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag "builder" %>
Expand Down
96 changes: 42 additions & 54 deletions app/views/layouts/page.rhtml
Expand Up @@ -2,67 +2,55 @@
<%= @output.doctype || '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' %>
<%= tag 'html', {:xmlns => "http://www.w3.org/1999/xhtml"}.merge(@output.includes[:html_tag] || {}), true %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><%= @cms_module_page_title || @output.title %></title>
<meta http-equiv='Content-Language' content='<%= @output.language %>' />
<% if @output.meta_description || @output.includes[:meta_description] -%>
<meta name='DESCRIPTION' content='<%= vh (@output.includes[:meta_description] || @output.meta_description).to_s %>'/>
<% end -%>
<% if @output.meta_keywords%>
<meta name='KEYWORDS' content='<%= vh @output.meta_keywords%>'/>
<% end -%>
<% if @robots.length > 0 %>
<meta name='ROBOTS' content='<%= @robots.join(',') %>'/>
<% end -%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><%= @cms_module_page_title || @output.title %></title>
<meta http-equiv='Content-Language' content='<%= @output.language %>' />
<% if @output.meta_description || @output.includes[:meta_description] -%>
<meta name='DESCRIPTION' content='<%= vh (@output.includes[:meta_description] || @output.meta_description).to_s %>'/>
<% end -%>
<% if @output.meta_keywords%>
<meta name='KEYWORDS' content='<%= vh @output.meta_keywords%>'/>
<% end -%>
<% if @robots.length > 0 %>
<meta name='ROBOTS' content='<%= @robots.join(',') %>'/>
<% end -%>
<%= javascript_include_tag 'swfobject' %>
<% if @output.includes[:head_html] -%>
<%= @output.includes[:head_html].join("\n") %>
<% end-%>
<% if @output.includes[:js] || @js_header -%>
<% if @js_header; @output.includes[:js] ||= []; @output.includes[:js] += @js_header; end -%>
<% @output.includes[:js].uniq.each do |js| -%>
<% if js.to_s.include?('http://') -%>
<script src="<%= vh js %>" type='text/javascript'></script>
<% else -%>
<%= javascript_include_tag js %>
<% end -%>
<% end -%>
<% end -%>
<% if @output.includes[:css] || @css_header -%>
<% if @css_header; @output.includes[:css] ||= []; @output.includes[:css] += @css_header; end -%>
<% @output.includes[:css].uniq.each do |css| -%>
<%= stylesheet_link_tag css %>
<% end -%>
<% end -%>
<%= @extra_header.uniq.join("\n") if @extra_header %>
<link href="/stylesheet/<%= @output.css_site_template_id.to_s + ".css" %>" rel="Stylesheet" type="text/css" />
<%= stylesheet_link_tag 'edit_page_link', :media => :all if page_editor? -%>
<%= @output.head %>

<%= javascript_include_tag 'swfobject' %>
<%= @output.includes[:head_html].join("\n") if @output.includes[:head_html] -%>
<% if @output.includes[:js] || @js_header -%>
<% if @js_header; @output.includes[:js] ||= []; @output.includes[:js] += @js_header; end -%>
<% @output.includes[:js].uniq.each do |js| -%>
<%= javascript_include_tag js %>
<% end -%>
<% end -%>
<% if @output.includes[:css] || @css_header -%>
<% if @css_header; @output.includes[:css] ||= []; @output.includes[:css] += @css_header; end -%>
<% @output.includes[:css].uniq.each do |css| -%>
<%= stylesheet_link_tag css %>
<% end -%>
<% end -%>
<%= @output.includes[:extra_head_html].join("\n") if @output.includes[:extra_head_html] -%>
<%= @extra_header.uniq.join("\n") if @extra_header -%>
<link href="/stylesheet/<%= @output.css_site_template_id.to_s + ".css" %>" rel="Stylesheet" type="text/css" />
<%= stylesheet_link_tag 'edit_page_link', :media => :all if page_editor? && !@output.lightweight-%>
<%= @output.head -%>
</head>
<body>
<div id="overDiv" style="position:absolute; left:0px; top:0px; visibility:hidden; z-index:1000;"></div>
<% if page_editor? -%>
<div id='cms_edit_page_link' style='width:0px;' onmouseover='this.style.width="auto";' onmouseout='this.style.width="0px"'>
<%= content_node_links(@output.content_nodes) -%>
<a href='/website/edit/page/page/<%= @page.id %>?return_to_site=1'><%= "Edit Page".t %></a><br/>
<a href='/website/dashboard#cms_page_title'><%= "Dashboard".t %></a><br/>
<a href='/website/structure'><%= "Structure".t %></a><br/>
</div>
<% end -%>
<% unless @output.lightweight -%>
<div id="overDiv" style="position:absolute; left:0px; top:0px; visibility:hidden; z-index:1000;"></div>
<% if page_editor? -%>
<div id='cms_edit_page_link' style='width:0px;' onmouseover='this.style.width="auto";' onmouseout='this.style.width="0px"'>
<%= content_node_links(@output.content_nodes) -%>
<a href='/website/edit/page/page/<%= @page.id %>?return_to_site=1'><%= "Edit Page".t %></a><br/>
<a href='/website/dashboard#cms_page_title'><%= "Dashboard".t %></a><br/>
<a href='/website/structure'><%= "Structure".t %></a><br/>
</div>
<% end -%>
<% end -%>
<%= @output.includes[:body_start] -%>
<% end -%>
<%= render_output(@page,@output) -%>
<% unless @partial_page || @output.partial -%>
<% if @google_analytics[:enabled] == 'enabled' -%>
Expand Down
1 change: 1 addition & 0 deletions app/views/templates/_template_options.rhtml
Expand Up @@ -3,6 +3,7 @@
<%= f.text_area :description, :cols => 40, :rows => 3 %>
<%= f.text_field :doctype, :size => 120, :label => 'Doctype',:description => 'Override the default doctype of XHTML 4.01 Transitional' %>
<%= f.yes_no :partial, :label => 'Partial Template', :description => 'Skip HTML header and footer (useful for AJAX template)' %>
<%= f.yes_no :lightweight, :description => "Lightweight templates don't include any additional wrapper HTML for paragraphs\n (cannot be used with ajax enabled paragraphs)" %>
<% end -%>
<% unless @site_template.parent_template %>
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20100624150433_extra_template_headers.rb
@@ -0,0 +1,13 @@
class ExtraTemplateHeaders < ActiveRecord::Migration
def self.up
add_column :site_templates, :lightweight, :boolean, :default => false
add_column :site_templates, :preprocessor, :string
add_column :site_features, :preprocessor, :string
end

def self.down
remove_column :site_templates, :lightweight
remove_column :site_templates, :preprocessor
remove_column :site_features, :preprocessor
end
end
24 changes: 20 additions & 4 deletions lib/site_node_engine.rb
Expand Up @@ -393,10 +393,14 @@ def render_output(page,output_obj)
elsif blk.is_a?(Hash)
blk[:paragraphs].each do |para|
if para.is_a?(String)
output += webiva_post_process_paragraph(para)
output << webiva_post_process_paragraph(para)
else
para_id = para.is_a?(ParagraphRenderer::ParagraphOutput) ? "id='cmspara_#{para.rnd.paragraph.id}'" : ""
output+= "<div class='paragraph' #{para_id}>#{webiva_post_process_paragraph(render_paragraph page, output_obj.revision, para)}</div>"
if output_obj.lightweight
output << webiva_post_process_paragraph(render_paragraph page, output_obj.revision,para)
else
para_id = para.is_a?(ParagraphRenderer::ParagraphOutput) ? "id='cmspara_#{para.rnd.paragraph.id}'" : ""
output << "<div class='paragraph' #{para_id}>#{webiva_post_process_paragraph(render_paragraph page, output_obj.revision, para)}</div>"
end
end
end
end
Expand Down Expand Up @@ -448,6 +452,7 @@ class PageOutput < Output #:nodoc:all
attr_accessor :head
attr_accessor :body
attr_accessor :partial
attr_accessor :lightweight
attr_accessor :doctype
attr_accessor :revision
attr_accessor :includes
Expand Down Expand Up @@ -782,6 +787,7 @@ def run(controller,user,options = {})
@output.content_nodes = @page_information.content_nodes
@output.partial = @page_information.partial
@output.doctype = @page_information.doctype
@output.lightweight = @page_information.lightweight
@output
end

Expand Down Expand Up @@ -957,6 +963,7 @@ def compile_page_information(user)
@page_information[:head] = SiteTemplate.render_template_head(@page_information[:css_site_template_id],@language)
@page_information[:doctype] = @active_template.doctype.blank? ? nil : @active_template.doctype
@page_information[:partial] = @active_template.partial?
@page_information[:lightweight] = @active_template.lightweight?


if @mode == 'edit'
Expand All @@ -968,6 +975,7 @@ def compile_page_information(user)

self.render_page_elements()
end
self.cleanup_page_information
end


Expand Down Expand Up @@ -1021,6 +1029,10 @@ def render_page_elements()
# Save the includes from the cached paragraphs
@page_information[:includes] = includes


end

def cleanup_page_information
# Kill the zone_paragraphs hash as we don't need to store it in
# page information
@page_information[:zone_paragraphs] = nil
Expand Down Expand Up @@ -1067,7 +1079,11 @@ def pre_process_paragraph(compiled_parts,para,zone_idx,includes)
skip = false
if !para.display_module
if !para.display_body.blank? && para.display_body != ''
body = "<div class='#{para.display_type}_paragraph'>" + para.display + "</div>"
if @page_information.lightweight
body = para.display
else
body = "<div class='#{para.display_type}_paragraph'>" + para.display + "</div>"
end
else
skip=true
end
Expand Down

0 comments on commit ad68c2c

Please sign in to comment.