Skip to content

Commit

Permalink
rake task for easy layout (un)installation
Browse files Browse the repository at this point in the history
  • Loading branch information
martinerko committed Mar 6, 2011
1 parent 81b3e51 commit 7cb90b2
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 0 deletions.
86 changes: 86 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
This file specify how to create and install (uninstall) new layouts into wiki.

1. HOW TO CREATE NEW LAYOUT
-------------------------------------------------------------------------------
New layout must be packed into tar archive and must contain this directory and
files structure:

layout_name.tar:

layout_name
layout_name\definition.yml
layout_name\layout_name.html.erb
layout_name\locales
layout_name\public
layout_name\public\images
layout_name\public\layout_name.css


layout_name - directory to hold all needed files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

definition.yml - contains layout description and list of page parts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example:
name: PeWe Layout
parts: [navigation, body, caption, footer]

layout_name.html.erb - html structure of layout
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
possible parts are:
<%= render :partial => 'shared/header' %>
this part contains base html structure of head, javascript links and base css

<%= render :partial => 'shared/notice' %>
this part is responsible for users notification of actions done in wiki

<%= render :partial => 'shared/breadcrumb' %>
this is standard breadcrumb navigation

<%= yield %>
this part generates all page parts defined for current page

<%= render :partial => 'shared/footer' %>
this is footer of html page, contains google analytics, closing tag for body and html elements


locales - directory which contains localization files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example of localization file en.yml

en:
layouts:
pewe: <-- name of layout
description: "Some description" <-- short description about layout
parts:
body: "main content" <-- page part name and its description
navigation: "page menu" <-- page part name and its description
caption: "caption of the page" <-- page part name and its description
footer: "number of users online" <-- page part name and its description


public - directory which contains stylesheet and directory with images
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

images - directory for images files used in layout
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

layout_name.css - css stylesheet definition, file must be named as layout name with extension css
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





2. HOW TO INSTALL NEW LAYOUT
-------------------------------------------------------------------------------
To install new layout, run:
rake bonsai:install layout=full_path_to_layout.tar


3. HOW TO UNINSTALL LAYOUT
-------------------------------------------------------------------------------
To uninstall layout, run:
rake bonsai:uninstall layout=layout_name

Important: Just unused layouts can be removed.
103 changes: 103 additions & 0 deletions lib/tasks/layout.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
namespace :bonsai do
desc "Install new layout"
task :install do

if !ENV['layout'].nil?
if File.exist? ENV['layout']
cp "#{ENV['layout']}", "#{Rails.root}/vendor/layouts"
#prepare file name
file_name = File.basename("#{ENV['layout']}")
#prepare dir name
dir_name = file_name[0, file_name.index('.')]
FileUtils.chdir("#{Rails.root}/vendor/layouts")
`tar -xvf #{file_name}`

error = false
unless File.exist? ("#{dir_name}/definition.yml")
puts "ERROR: #{dir_name}/definition.yml does not exist!"
error = true
end
unless File.exist? ("#{dir_name}/#{dir_name}.html.erb")
puts "ERROR: #{dir_name}/#{dir_name}.html.erb does not exist!"
error = true
end
unless File.exist? ("#{dir_name}/locales")
puts "ERROR: #{dir_name}/locales does not exist!"
error = true
end
unless File.exist? ("#{dir_name}/public")
puts "ERROR: #{dir_name}/public does not exist!"
error = true
end

if error != true
#move images
mv "#{Rails.root}/vendor/layouts/#{dir_name}/public/images", "#{Rails.root}/public/images/layouts/#{dir_name}"
#move stylesheet definition
mv "#{Rails.root}/vendor/layouts/#{dir_name}/public/#{dir_name}.css", "#{Rails.root}/public/stylesheets/"
#move language definitions
mv "#{Rails.root}/vendor/layouts/#{dir_name}/locales", "#{Rails.root}/config/locales/layouts/#{dir_name}"
#move html erb file
mv "#{Rails.root}/vendor/layouts/#{dir_name}/#{dir_name}.html.erb", "#{Rails.root}/app/views/layouts/"
#remove public folder
rm_rf "#{Rails.root}/vendor/layouts/#{dir_name}/public"
#remove archive
rm_rf "#{Rails.root}/vendor/layouts/#{file_name}"

puts "Layout #{dir_name} was successfully installed."
end

else
puts "ERROR cant find this file, please check tha path"
end
else
puts "ERROR: You must specify layout to install"
end
end


desc "Uninstall layout"
task :uninstall => :environment do


if !ENV['layout'].nil?
pages = Page.all(:select => "lft, rgt", :conditions => ["layout = ?", ENV['layout']], :order => 'id asc')
if pages.empty?
path = "#{Rails.root}/public/images/layouts/#{ENV['layout']}"
if File.exist? path
rm_rf path
end

path = "#{Rails.root}/public/stylesheets/#{ENV['layout']}.css"
if File.exist? path
rm_rf path
end

path = "#{Rails.root}/app/views/layouts/#{ENV['layout']}.html.erb"
if File.exist? path
rm_rf path
end

path = "#{Rails.root}/config/locales/layouts/#{ENV['layout']}"
if File.exist? path
rm_rf path
end

path = "#{Rails.root}/vendor/layouts/#{ENV['layout']}"
if File.exist? path
rm_rf path
end

puts "Layout #{ENV['layout']} was successfully removed."
else
puts "ERROR: Layout can not be removed. This layout is currently used here:"
pages.each do |page|
puts page.get_path
end
end
else
puts "ERROR: You must specify layout to uninstall."
end
end

end

0 comments on commit 7cb90b2

Please sign in to comment.