Skip to content

Commit

Permalink
Merge commit 'core/apply-theme' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Aug 4, 2010
2 parents f17ec1d + fd01f94 commit d963f1a
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 32 deletions.
17 changes: 16 additions & 1 deletion app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def expire_site
hdr(:options, 'template_type', :label => 'Type',:options => :type_options),
hdr(:order, 'IF(parent_id,parent_id,id), parent_id, name',:label => 'Parent'),
hdr(:string, 'description'),
hdr(:static, '')
hdr(:static, ''), # Create child theme
hdr(:static, '') # Apply theme
]
def type_options; SiteTemplate.template_type_select_options; end

Expand Down Expand Up @@ -140,6 +141,20 @@ def import_bundle
end
end

def apply_theme
cms_page_path [ "Options", "Themes" ], "Apply Theme"

@site_template = SiteTemplate.find(params[:path][0])

if request.post?
if params[:commit]
@site_template.apply_to_site SiteVersion.current, :features => params[:features]
flash[:notice] = 'Applied %s theme' / @site_template.name
end
redirect_to :action => 'index'
end
end

def new
@site_template = SiteTemplate.new(params[:site_template])

Expand Down
4 changes: 3 additions & 1 deletion app/models/page_paragraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class PageParagraph < DomainModel
belongs_to :content_publication



named_scope :live_paragraphs, {:joins => :page_revision, :conditions => 'page_revisions.active=1 AND page_revisions.revision_type="real"'}
named_scope :with_feature, lambda { |display_module, display_type| {:conditions => ['display_module = ? and display_type = ?', display_module, display_type]} }

# PageParagraph file instance support is in PageRevisions
# process_file_instance :display_body, :display_body_html
apply_content_filter(:display_body => :display_body_html) do |para|
Expand Down
15 changes: 15 additions & 0 deletions app/models/site_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,19 @@ def export_to_bundle(bundler)
bundler.add_folder(self.image_folder) if self.image_folder
self.attributes.slice('name', 'description', 'feature_type', 'body', 'options', 'css', 'category', 'archived', 'image_folder_id', 'preprocessor')
end

def self.feature_hash
paragraph_list = ParagraphController.get_editor_paragraphs + SiteModule.get_module_paragraphs.values
output = {}

paragraph_list.each do |para_list|
para_list[2].each do |paragraph|
next unless paragraph[4][0]
output[paragraph[4][0]] ||= []
output[paragraph[4][0]] << [ paragraph[3], paragraph[1] ]
end
end

output
end
end
6 changes: 3 additions & 3 deletions app/models/site_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def push_subpage(title, type='P')
end

def push_modifier(type)
framework = self.site_node_modifiers.find_by_modifier_type(type) || self.add_modifier(type)
md = self.site_node_modifiers.find_by_modifier_type(type) || self.add_modifier(type)
if block_given?
yield framework
yield md
end
framework
md
end

def create_temporary_revision(revision_id) #:nodoc:
Expand Down
46 changes: 43 additions & 3 deletions app/models/site_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,19 +746,24 @@ def export_to_bundle(bundler)
data
end

def self.import_bundle(bundler, data)
def self.import_bundle(bundler, data, opts={})
# Get the new images folder
domain_file_id = data['domain_file_id'] ? bundler.get_new_input_id(DomainFile, data['domain_file_id']) : nil

# Create the site template
site_template = SiteTemplate.create data.slice('name', 'description', 'template_html', 'options', 'style_struct', 'style_design', 'template_type', 'head', 'doctype', 'partial', 'lightweight', 'preprocessor', 'parent_id').merge('domain_file_id' => domain_file_id)
site_template = nil
site_template = SiteTemplate.find_by_parent_id_and_name(data['parent_id'], data['name']) if opts[:replace_same]
site_template ||= SiteTemplate.new(:parent_id => data['parent_id'], :name => data['name'])
site_template.update_attributes data.slice('description', 'template_html', 'options', 'style_struct', 'style_design', 'template_type', 'head', 'doctype', 'partial', 'lightweight', 'preprocessor').merge('domain_file_id' => domain_file_id)

# Create the zones
site_template.site_template_zones.clear
data['zones'].each_with_index do |name, idx|
site_template.site_template_zones.create :name => name, :position => (idx+1)
end

# Create the features
site_template.site_features.clear
data['features'].each do |feature|
image_folder_id = feature['image_folder_id'] ? bundler.get_new_input_id(DomainFile, feature['image_folder_id']) : nil
site_template.site_features.create feature.merge('image_folder_id' => image_folder_id)
Expand All @@ -767,9 +772,44 @@ def self.import_bundle(bundler, data)
# Create the templates children
data['children'].each do |child|
child['parent_id'] = site_template.id
SiteTemplate.import_bundle bundler, child
SiteTemplate.import_bundle bundler, child, opts
end

site_template
end

def apply_to_site(version, opts={})
version.root_node.push_modifier('template') do |mod|
mod.options.template_id = self.id
mod.move_to_top
mod.save
end

# Apply theme features to existing paragraphs
if opts[:features]
feature_hash = SiteFeature.feature_hash

revisions = {}
self.site_features.each do |feature|
next unless feature_hash[feature.feature_type]
feature_hash[feature.feature_type].each do |info|
PageParagraph.live_paragraphs.with_feature(*info).group_by(&:page_revision_id).each do |page_revision_id, paragraphs|
revisions[page_revision_id] ||= []
revisions[page_revision_id] += paragraphs.map { |para| [para.identity_hash, feature.id] }
end
end
end

revisions.each do |page_revision_id, paragraphs|
rv = PageRevision.find(page_revision_id).create_temporary
paragraphs.each do |info|
para = rv.page_paragraphs.detect { |p| p.identity_hash == info[0] }
para.update_attribute :site_feature_id, info[1]
end
rv.make_real
end
end

DomainModel.expire_site
end
end
30 changes: 20 additions & 10 deletions app/models/webiva_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class WebivaBundler < HashModel

attr_accessor :importing

attributes :version => nil, :name => nil, :thumb_id => nil, :domain_files => nil, :modules => nil, :inputs => nil, :creator_id => nil, :bundle_file_id => nil
attributes :version => nil, :name => nil, :thumb_id => nil, :domain_files => nil, :modules => nil, :inputs => nil, :creator_id => nil, :bundle_file_id => nil, :replace_same => true

boolean_options :replace_same

domain_file_options :thumb_id, :bundle_file_id

Expand Down Expand Up @@ -54,9 +56,9 @@ def export_object(obj)
self.data << {'data' => obj.export_to_bundle(self), 'name' => obj.name, 'handler' => obj.class.to_s.underscore}
end

def import_object(info)
def import_object(info, opts={})
handler = info['handler'].camelcase.constantize
handler.import_bundle(self, info['data'])
handler.import_bundle(self, info['data'], opts)
end

def export
Expand Down Expand Up @@ -119,22 +121,29 @@ def import
self.modules = manifest['modules']

unless manifest['folders'].empty?
theme_folder = DomainFile.create(:name => self.name, :parent_id => DomainFile.themes_folder.id, :file_type => 'fld', :creator_id => self.creator_id)
theme_folder = self.get_folder(self.name, DomainFile.themes_folder.id)
self.import_folder(dir, manifest['folders'].shift, theme_folder)

manifest['folders'].each do |info|
folder = DomainFile.create(:name => info['name'], :parent_id => theme_folder.id, :file_type => 'fld', :creator_id => self.creator_id)
folder = self.get_folder(info['name'], theme_folder.id)
self.import_folder(dir, info, folder)
end
end

@data = YAML.load_file("#{dir}/#{manifest['data']}")['data']

self.data.each { |info| self.import_object(info) }
self.data.each { |info| self.import_object(info, :replace_same => self.replace_same) }

FileUtils.rm_rf(dir)
end

def get_folder(name, parent_id)
folder = nil
folder = DomainFile.find_by_file_type_and_parent_id_and_name('fld', parent_id, name) if self.replace_same
folder ||= DomainFile.create(:name => name, :parent_id => parent_id, :file_type => 'fld', :creator_id => self.creator_id)
folder
end

def export_folder(dir, folder)
return nil unless folder.file_type == 'fld'

Expand All @@ -155,6 +164,7 @@ def import_folder(dir, info, theme_folder)
`cd #{dir}; unzip ../#{info['filename']}`
file_ids = DomainFile.new(:creator_id => self.creator_id).extract_directory(dir, theme_folder.id)
DomainFile.find(file_ids).each { |file| file.post_process!(false) }
DomainFile.find(file_ids).map(&:replace_same) if self.replace_same
FileUtils.rm_rf(dir)
end

Expand All @@ -175,11 +185,11 @@ def get_bundle_info
self.inputs = manifest['inputs']
self.modules = manifest['modules']

unless manifest['thumb'].blank? || self.thumb
if ! manifest['thumb'].blank? && self.thumb.nil?
thumbnail_folder = DomainFile.find(:first,:conditions => "name = 'Thumbnails' and parent_id = #{DomainFile.themes_folder.id}") || DomainFile.create(:name => 'Thumbnails', :parent_id => DomainFile.themes_folder.id, :file_type => 'fld')
`cd #{dir}; tar zxf #{self.bundle_file.name} #{manifest['thumb']}`
File.open("#{dir}/#{manifest['thumb']}", "r") do |fd|
self.thumb_id = DomainFile.create :filename => fd, :parent_id => thumbnail_folder.id, :process_immediately => true
self.thumb_id = DomainFile.create(:filename => fd, :parent_id => thumbnail_folder.id, :process_immediately => true).id
end
end

Expand All @@ -189,11 +199,11 @@ def get_bundle_info
end

def run_worker
DomainModel.run_worker(self.class.to_s, nil, :import_bundle, :bundle_file_id => self.bundle_file_id, :inputs => self.inputs)
DomainModel.run_worker(self.class.to_s, nil, :import_bundle, :bundle_file_id => self.bundle_file_id, :inputs => self.inputs, :replace_same => self.replace_same)
end

def self.import_bundle(opts={})
bundler = WebivaBundler.new :bundle_file_id => opts[:bundle_file_id], :inputs => opts[:inputs]
bundler = WebivaBundler.new :bundle_file_id => opts[:bundle_file_id], :inputs => opts[:inputs], :replace_same => opts[:replace_same]
bundler.import
end
end
43 changes: 36 additions & 7 deletions app/models/wizards/members_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,7 @@ def run_wizard
rv.push_paragraph '/editor/auth', 'user_register', {:success_page_id => success_page_id}
end

# Missing Password
group_node.push_subpage('missing-password') do |nd, rv|
# remove basic paragraph
self.destroy_basic_paragraph(rv)
rv.push_paragraph '/editor/auth', 'missing_password'
end

edit_account_page_id = nil
# Members View Account
group_node.push_subpage('members') do |members_node, rv|
# Add members only lock
Expand All @@ -97,6 +91,7 @@ def run_wizard

# Members Edit Account
members_node.push_subpage('edit-account') do |nd, rv|
edit_account_page_id = nd.id
# remove basic paragraph
self.destroy_basic_paragraph(rv)
rv.push_paragraph '/editor/auth', 'user_edit_account', {:success_page_id => members_node.id}
Expand All @@ -105,6 +100,40 @@ def run_wizard
login_para.data[:success_page] = members_node.id
login_para.save
end

# Missing Password
group_node.push_subpage('missing-password') do |nd, rv|
# remove basic paragraph
self.destroy_basic_paragraph(rv)
rv.push_paragraph '/editor/auth', 'missing_password', {:reset_password_page => edit_account_page_id, :email_template => self.get_missing_password_mail_template.id}
end
end
end

def get_missing_password_mail_template
mail_template = MailTemplate.find_by_name 'Reset Password'
return mail_template if mail_template

MailTemplate.create :name => 'Reset Password', :subject => 'Reset Password', :language => 'en', :body_text => self.reset_password_mail_body_text, :body_html => self.reset_password_mail_body_html, :category => self.members_group_node_name, :template_type => 'site'
end

def reset_password_mail_body_html
<<-BODY
<p>
<strong>Reset your Password</strong><br/>
<br/>
You can reset your password by following:<br/>
<a href="%%verification%%" target="_blank">%%verification%%</a>
</p>
BODY
end

def reset_password_mail_body_text
<<-BODY
Reset your Password
You can reset your password by following:
%%verification%%
BODY
end
end
13 changes: 6 additions & 7 deletions app/models/wizards/simple_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,16 @@ def set_defaults(params)
end

def run_wizard
self.root_node.site_node_modifiers.each do |modifier|
modifier.destroy if modifier.modifier_type == 'template'
end

self.root_node.reload

self.root_node.push_modifier('framework') do |framework|
framework.new_revision do |rv|
rv.push_paragraph '/editor/menu', 'automenu', {:root_page => self.root_node.id, :levels => 1}, :zone => 2
end
end

self.root_node.add_modifier('template') do |mod|
self.root_node.push_modifier('template') do |mod|
mod.options.template_id = self.create_simple_theme.id
mod.move_to_top
mod.save
end

@pages.each do |name|
Expand All @@ -66,6 +62,9 @@ def run_wizard
end

def create_simple_theme
site_template = SiteTemplate.find_by_template_type_and_name('site', 'Simple Site Theme')
return site_template if site_template

site_template = SiteTemplate.create :template_type => 'site', :name => 'Simple Site Theme', :description => '', :template_html => self.simple_template_html, :style_design => self.simple_style_design, :style_struct => self.simple_style_struct

['Content', 'Main Menu', 'Sidebar'].each_with_index do |name, idx|
Expand Down
1 change: 1 addition & 0 deletions app/views/templates/_templates_table.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</td>
<td><%= t.description %></td>
<td><a href="<%= url_for :action => 'new', :path => t.id %>">Create child theme</a></td>
<td><a href="<%= url_for :action => 'apply_theme', :path => t.id %>">Apply theme</a></td>
</tr>


Expand Down
9 changes: 9 additions & 0 deletions app/views/templates/apply_theme.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="admin_content">

<% admin_form_for :site_template, @site_template do |f| -%>
<%= f.custom_field('Features', :value => "<label>" + check_box_tag('features', '1', true) + " apply site features to existing paragraphs.</lable>") %>
<%= f.spacer %>
<%= f.cancel_submit_buttons %>
<% end -%>

</div>
2 changes: 2 additions & 0 deletions app/views/templates/import_bundle.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<% admin_form_for :bundler, @bundler do |f| -%>
<%= f.hidden_field :bundle_file_id %>
<%= f.hidden_field :thumb_id %>
<%= f.check_boxes :replace_same, [['Replace matching bundle elements', true]], :single => true, :label => '' %>
<%= f.spacer %>
<%= f.cancel_submit_buttons 'Cancel', 'Import' %>
<% end -%>
<% else -%>
Expand Down

0 comments on commit d963f1a

Please sign in to comment.