Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better theme UI. Now shows preview image, allows you to select the th…
…eme you want to apply right now and also checks to make sure the theme directory is writable for Heroku. If it's not then disable adding and editing themes.
  • Loading branch information
djones committed Jan 19, 2010
1 parent 4299e1f commit e192fd3
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 43 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
public/system/*
public/themes/*
log/*.log
tmp/**/*
.DS_Store
Expand All @@ -13,4 +14,5 @@ db/*.sqlite3
*.autobackupbyrefinery.*
refinerycms*.gem
public/javascripts/cache
public/stylesheets/cache
public/stylesheets/cache
config/database.yml.example
Binary file added public/images/refinery/icons/star-dull.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/refinery/icons/star.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vendor/plugins/resources/app/models/resource.rb
@@ -1,8 +1,8 @@
class Resource < ActiveRecord::Base

has_attachment :storage => (USE_S3_BACKEND ? :s3 : :file_system),
:size => 0.kilobytes..50.megabytes,
:path_prefix => (USE_S3_BACKEND ? nil : 'public/system/resources')
:size => 0.kilobytes..50.megabytes,
:path_prefix => (USE_S3_BACKEND ? nil : 'public/system/resources')

acts_as_indexed :fields => [:title, :type_of_content],
:index_file => [RAILS_ROOT,"tmp","index"]
Expand Down
4 changes: 3 additions & 1 deletion vendor/plugins/resources/config/routes.rb
@@ -1,7 +1,9 @@
ActionController::Routing::Routes.draw do |map|

map.resources :resources

map.namespace(:admin) do |admin|
admin.resources :resources, :collection => {:insert => :get}
end
end

end
21 changes: 19 additions & 2 deletions vendor/plugins/themes/app/controllers/admin/themes_controller.rb
Expand Up @@ -2,7 +2,24 @@ class Admin::ThemesController < Admin::BaseController

crudify :theme, :order => "updated_at DESC"

# allows the user to both select a theme on the index page
# and upload a zip file (new/create/update) which saves the unzipped version of it
before_filter :find_theme, :only => [:update, :destroy, :edit, :preview_image, :activate]

# accessor method for theme preview image
def preview_image
if File.exists? @theme.preview_image
send_file(@theme.preview_image, :type => 'image/png',
:disposition => 'inline',
:stream => true)
else
return error_404
end
end

def activate
RefinerySetting[:theme] = @theme.title

flash[:notice] = "'#{@theme.title}' applied to live site."
redirect_to admin_themes_url
end

end
37 changes: 23 additions & 14 deletions vendor/plugins/themes/app/models/theme.rb
Expand Up @@ -5,20 +5,25 @@ class Theme < ActiveRecord::Base

before_save :read_theme

has_attachment :storage => :file_system,
:size => 0.kilobytes..15.megabytes,
:content_type => 'application/zip'

# Once a zip is uploaded it unzips it into the themes directory
has_attachment :storage => (USE_S3_BACKEND ? :s3 : :file_system),
:size => 0.kilobytes..15.megabytes,
:path_prefix => (USE_S3_BACKEND ? nil : 'public/system/themes'),
:content_type => 'application/zip'

# Once a zip is uploaded it unzips it into the themes directory if writable
def after_attachment_saved
# make the folder for the them
FileUtils.mkdir(self.theme_path) unless File.exists?(self.theme_path)
if theme_directory_is_writable?
# make the folder for the them
FileUtils.mkdir(self.theme_path) unless File.exists? self.theme_path

# extracts the contents of the zip file into the theme directory
Zip::ZipFile.foreach(self.filename) do |entry|
FileUtils.mkdir_p(File.dirname("#{theme_path}/#{entry}"))
entry.extract("#{theme_path}/#{entry}") { true }
end
# extracts the contents of the zip file into the theme directory
Zip::ZipFile.foreach(self.filename) do |entry|
FileUtils.mkdir_p(File.dirname("#{theme_path}/#{entry}"))
entry.extract("#{theme_path}/#{entry}") { true }
end
else
raise "Theme directory not writable"
end
end

def theme_folder_title
Expand All @@ -36,13 +41,17 @@ def preview_image
def read_theme
self.title = File.basename(self.filename).split(".").first.titleize

if File.exists?(File.join(theme_path, "LICENSE"))
if File.exists? File.join(theme_path, "LICENSE")
self.license = File.open(File.join(theme_path, "LICENSE")).read
end

if File.exists?(File.join(theme_path, "README"))
if File.exists? File.join(theme_path, "README")
self.description = File.open(File.join(theme_path, "README")).read
end
end

def theme_directory_is_writable?
File.writable? File.join(RAILS_ROOT, "themes") # Heroku users will receive false here
end

end
40 changes: 23 additions & 17 deletions vendor/plugins/themes/app/views/admin/themes/_theme.html.erb
@@ -1,18 +1,24 @@
<li class='clearfix record <%= cycle("on", "on-hover") %>'>
<span class='title'>
<span class='actions'>
<%= link_to refinery_icon_tag('page_white_put.png'), theme.public_filename,
:title => "Download this theme (#{number_to_human_size(theme.size)})" %>
<%= link_to refinery_icon_tag('application_edit.png'), edit_admin_theme_url(theme),
:title => "Edit this theme" %>
<%= link_to refinery_icon_tag('delete.png'), admin_theme_path(theme),
:confirm => "Are you sure you want to delete '#{theme.title}'?",
:class => "cancel", :method => :delete,
:title => "Remove this theme forever" %>
</span>
<%=h theme.title %>
<span class="preview">
- <%= number_to_human_size(theme.size) %> - <%= theme.theme_path -%>
</span>
</span>
<li class=''>

<p>
<%=h theme.title %>
</p>
<%= image_tag(preview_image_admin_theme_url(theme), :width => 135, :height => 135) %>
<p>

<span class='actions'>
<%= link_to refinery_icon_tag('star.png'), activate_admin_theme_url(theme) %>
<%= link_to refinery_icon_tag('page_white_put.png'), theme.public_filename,
:title => "Download this theme (#{number_to_human_size(theme.size)})" %>
<% if Theme.first.theme_directory_is_writable? %>
<%= link_to refinery_icon_tag('application_edit.png'), edit_admin_theme_url(theme),
:title => "Edit this theme" %>
<% end %>
<%= link_to refinery_icon_tag('delete.png'), admin_theme_path(theme),
:confirm => "Are you sure you want to delete '#{theme.title}'?",
:class => "cancel", :method => :delete,
:title => "Remove this theme forever" %>
</span>
</p>

</li>
12 changes: 7 additions & 5 deletions vendor/plugins/themes/app/views/admin/themes/index.html.erb
Expand Up @@ -3,23 +3,25 @@
<li>
<%= render :partial => "/shared/admin/search", :locals => {:url => admin_themes_url} %>
</li>
<li>
<%= link_to "Upload New Theme", new_admin_theme_url, :class => "add_icon" %>
</li>
<% if Theme.first.theme_directory_is_writable? %>
<li>
<%= link_to "Upload New Theme", new_admin_theme_url, :class => "add_icon" %>
</li>
<% end %>
</ul>
</div>
<div id='records'>
<% if searching? %>
<h2>Search Results for "<%= params[:search] %>"</h2>
<% if @themes.size > 0 %>
<%= render :partial => "resource", :collection => @themes %>
<%= render :partial => "theme", :collection => @themes %>
<% else %>
<p>Sorry, no results found.</p>
<% end %>
<% else %>
<% if @themes.size > 0 -%>
<%= will_paginate @themes, :previous_label => '&laquo;', :next_label => '&raquo;' %>
<ul>
<ul id='image_grid'>
<%= render :partial => "theme", :collection => @themes %>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion vendor/plugins/themes/config/routes.rb
@@ -1,7 +1,7 @@
ActionController::Routing::Routes.draw do |map|

map.namespace(:admin) do |admin|
admin.resources :themes
admin.resources :themes, :member => {:preview_image => :get, :activate => :get}
end

map.connect 'stylesheets/theme/:filename*extension', :controller => 'themes', :action => 'stylesheets'
Expand Down

0 comments on commit e192fd3

Please sign in to comment.