Skip to content

Commit

Permalink
Merge branch 'master' of github.com:radiant/radiant
Browse files Browse the repository at this point in the history
* 'master' of github.com:radiant/radiant:
  Undefine prototype rake tasks in instance mode. Closes radiant#17
  Verify that the cache directory exists before trying to store a response. Closes radiant#12
  Fix page-part deletion in JS. Closes radiant#16
  Don't cache extension-defined javascripts, but do cache the defaults.
  Update history.
  created spec for and implemented fix in development mode behavior when Radiant::Config['dev.host'] is defined
  Revert "Merge branch 'tab'"
  • Loading branch information
jlong committed Sep 29, 2009
2 parents 3b4557e + 279253f commit 485bb4b
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 68 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG
Expand Up @@ -2,7 +2,23 @@

=== Edge

* Simplify the adding of tabs and links in navigation [Jim Gay]
* Undefine prototype rake tasks in instance mode. [Sean Cribbs]
* Verify that the cache directory exists before trying to store a response.
[Sean Cribbs]
* Fix page-part deletion in JS. [Sean Cribbs]
* Don't cache extension-defined javascripts, but do cache the defaults.
[Sean Cribbs]
* Fix dev-site behavior when 'dev.host' is configured. [Chris Ricca]
* Use HTML 5 doctype. [John Muhl]
* Concatenate admin javascript files. [John Muhl]
* Use more descriptive page titles. [John Muhl]
* Allow non-standard controller methods for render_region. [Jim Gay]
* Updated to use Radius 0.6.1. [John Long]
* Use root_path instead of "/" on View Site link. [John Long]
* Correct type on content-type and move to more/hide language. [John Long]
* Add some helpful shortcut keys. [Sean Cribbs]
* Implement "Blade" user-interface. [John Long, Chris Parrish, Daniel Beach,
Brandon Mathis, Sean Cribbs, Ben Morrow, John Muhl]

=== 0.8.1 Luster

Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTORS
Expand Up @@ -5,7 +5,15 @@ core:

=== Edge

* Chris Ricca
* Jim Gay
* John Muhl
* Ben Morrow
* Sean Cribbs
* Brandon Mathis
* Daniel Beach
* Chris Parrish
* John Long

=== 0.8.1 Luster

Expand Down
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -70,6 +70,5 @@ def set_javascripts_and_stylesheets
@stylesheets ||= []
@stylesheets.concat %w(admin/main)
@javascripts ||= []
@javascripts.concat %w(admin/prototype admin/effects admin/lowpro admin/cookie admin/popup admin/status admin/utility admin/codearea admin/tabcontrol admin/ruledtable admin/sitemap admin/shortcuts admin/application)
end
end
7 changes: 5 additions & 2 deletions app/models/standard_tags.rb
Expand Up @@ -1017,7 +1017,10 @@ def attr_or_error(tag, options = {})
end

def dev?(request)
dev_host = Radiant::Config['dev.host']
request && ((dev_host && dev_host == request.host) || request.host =~ /^dev\./)
if dev_host = Radiant::Config['dev.host']
dev_host == request.host
else
request.host =~ /^dev\./
end
end
end
8 changes: 5 additions & 3 deletions app/views/layouts/application.html.haml
@@ -1,13 +1,15 @@
<!DOCTYPE html>
%html{html_attrs}
%head
%meta{"http-equiv"=>"Content-type", :content=>"text/html; charset=utf-8"}/
%meta{"http-equiv"=>"Content-type", :content=>"text/html;charset=utf-8"}/
%title= @page_title || default_page_title
- @stylesheets.uniq.each do |stylesheet|
= stylesheet_link_tag stylesheet
= javascript_include_tag %w(admin/prototype admin/effects admin/lowpro admin/cookie admin/popup admin/status admin/utility admin/codearea admin/tabcontrol admin/ruledtable admin/sitemap admin/shortcuts admin/application), :cache => 'admin/all'
/[if lt IE 7]
%script{:type=>"text/javascript", :src=>"/javascripts/pngfix.js"}
= javascript_include_tag @javascripts, :cache => 'admin/all'
= javascript_include_tag 'admin/pngfix'
- @javascripts.uniq.each do |javascript|
= javascript_include_tag javascript
- if @content_for_page_scripts
= javascript_tag @content_for_page_scripts
- if @content_for_page_css
Expand Down
45 changes: 21 additions & 24 deletions lib/radiant/admin_ui.rb
Expand Up @@ -11,11 +11,10 @@ class DuplicateTabNameError < StandardError; end
# The NavTab Class holds the structure of a navigation tab (including
# its sub-nav items).
class NavTab < Array
attr_reader :name, :proper_name
attr_reader :name, :proper_name, :visibility

def initialize(name, proper_name = nil)
@name = name
@proper_name = proper_name || name.to_s.titleize
def initialize(name, proper_name, visibility = [:all])
@name, @proper_name, @visibility = name, proper_name, Array(visibility)
end

def [](id)
Expand Down Expand Up @@ -49,14 +48,14 @@ def <<(*args)
end

alias :add :<<

def visible?(user)
any? { |sub_item| sub_item.visible?(user) }
visibility.include?(:all) || visibility.any? {|v| user.has_role?(v) }
end

def deprecated_add(name, url, caller)
ActiveSupport::Deprecation.warn("admin.tabs.add is no longer supported in Radiant 0.9+. Please update your code to use admin.nav", caller)
NavSubItem.new(url, name.underscore.to_sym, name)
NavSubItem.new(name.underscore.to_sym, name, url)
end
end

Expand All @@ -65,14 +64,12 @@ class NavSubItem
attr_reader :name, :proper_name, :url
attr_accessor :tab

def initialize(url, name = nil, proper_name = nil)
@url = url
@name = name || url.sub(/^\/admin/,'').parameterize('_').underscore.wrapped_string.to_sym
@proper_name = proper_name || @name.to_s.titleize
def initialize(name, proper_name, url = "#")
@name, @proper_name, @url = name, proper_name, url
end

def visible?(user)
visible_by_controller?(user)
tab.visible?(user) && visible_by_controller?(user)
end

def relative_url
Expand Down Expand Up @@ -119,23 +116,23 @@ def initialize
end

def load_default_nav
content = nav_tab(:content)
content << nav_item("/admin/pages")
content << nav_item("/admin/snippets")
content = nav_tab(:content, "Content")
content << nav_item(:pages, "Pages", "/admin/pages")
content << nav_item(:snippets, "Snippets", "/admin/snippets")
nav << content

design = nav_tab(:design)
design << nav_item("/admin/layouts")
design = nav_tab(:design, "Design", [:developer, :admin])
design << nav_item(:layouts, "Layouts", "/admin/layouts")
nav << design

# media = nav_tab(:assets)
# media << nav_item("/admin/assets/", :all)
# media << nav_item("/admin/assets/unattached/", :unattached)
# media = NavTab.new(:assets, "Assets")
# media << NavSubItem.new(:all, "All", "/admin/assets/")
# media << NavSubItem.new(:all, "Unattached", "/admin/assets/unattached/")

settings = nav_tab(:settings)
settings << nav_item("/admin/preferences/edit", :general, 'Personal')
settings << nav_item("/admin/users")
settings << nav_item("/admin/extensions")
settings = nav_tab(:settings, "Settings")
settings << nav_item(:general, "Personal", "/admin/preferences/edit")
settings << nav_item(:users, "Users", "/admin/users")
settings << nav_item(:extensions, "Extensions", "/admin/extensions")
nav << settings
end

Expand Down
12 changes: 12 additions & 0 deletions lib/radiant/cache.rb
Expand Up @@ -37,6 +37,12 @@ def initialize(root="#{Rails.root}/tmp/cache/entity")
def clear
Dir[File.join(self.root, "*")].each {|file| FileUtils.rm_rf(file) }
end

def write(body)
# Verify that the cache directory exists before attempting to write
FileUtils.mkdir_p(self.root, :mode => 0755) unless File.directory?(self.root)
super
end
end

class MetaStore < Rack::Cache::MetaStore::Disk
Expand All @@ -49,6 +55,12 @@ def clear
Dir[File.join(self.root, "*")].each {|file| FileUtils.rm_rf(file) }
end

def store(request, response, entitystore)
# Verify that the cache directory exists before attempting to store
FileUtils.mkdir_p(self.root, :mode => 0755) unless File.directory?(self.root)
super
end

private
def restore_response(hash, body=nil)
# Cribbed from the Rack::Cache source
Expand Down
3 changes: 3 additions & 0 deletions lib/tasks/undefine.rake
Expand Up @@ -14,6 +14,9 @@ unless Radiant.app?
radiant:repackage
radiant:uninstall_gem
radiant:import:prototype:styles
radiant:import:prototype:images
radiant:import:prototype:javascripts
radiant:import:prototype:assets
rails:freeze:edge
rails:freeze:gems
rails:unfreeze
Expand Down
4 changes: 4 additions & 0 deletions public/javascripts/admin/tabcontrol.js
Expand Up @@ -32,8 +32,12 @@ var TabControl = Class.create({
var tab = this.selected;
var index = this.tabs.indexOf(tab);
var newSelectedTab = this.tabs[index-1];
var idInput = tab.page.down('.id_input');
var deleteInput = tab.page.down('.delete_input');
deleteInput.setValue('true');
tab.remove();
this.tabs = this.tabs.without(tab);
this.element.insert(idInput).insert(deleteInput);
this.select(newSelectedTab || this.tabs.first());
},

Expand Down
58 changes: 23 additions & 35 deletions spec/lib/radiant/admin_ui/nav_tabs_spec.rb
Expand Up @@ -12,11 +12,6 @@
it "should have a proper name" do
@tab.proper_name.should == "Content"
end

it "should set the proper name according to the name if no proper_name is given" do
@tab = Radiant::AdminUI::NavTab.new(:a_new_tab)
@tab.proper_name.should == "A New Tab"
end

it "should be Enumerable" do
Enumerable.should === @tab
Expand All @@ -31,16 +26,16 @@
end

it "should assign the tab on the sub-item when adding" do
subtab = Radiant::AdminUI::NavSubItem.new("/admin/pages")
subtab = Radiant::AdminUI::NavSubItem.new(:pages, "Pages", "/admin/pages")
@tab << subtab
subtab.tab.should == @tab
end

describe "inserting sub-items in specific places" do
before :each do
@pages = Radiant::AdminUI::NavSubItem.new("/admin/pages")
@snippets = Radiant::AdminUI::NavSubItem.new("/admin/snippets")
@comments = Radiant::AdminUI::NavSubItem.new("/admin/comments")
@pages = Radiant::AdminUI::NavSubItem.new(:pages, "Pages", "/admin/pages")
@snippets = Radiant::AdminUI::NavSubItem.new(:snippets, "Snippets", "/admin/snippets")
@comments = Radiant::AdminUI::NavSubItem.new(:comments, "Comments", "/admin/comments")
@tab << @pages
@tab << @snippets
end
Expand Down Expand Up @@ -69,19 +64,21 @@
describe "visibility" do
dataset :users

it "should not be visible if it is empty" do
@tab.should_not be_visible(users(:admin))
it "should be visible by default" do
User.all.each {|user| @tab.should be_visible(user) }
end

it "should be visible if any of the sub items are visible to the current user" do
@subitem = Radiant::AdminUI::NavSubItem.new("/admin/pages")
@tab << @subitem
@tab.should be_visible(users(:admin))
it "should restrict to a specific role" do
@tab.visibility.replace [:developer]
@tab.should be_visible(users(:developer))
@tab.should_not be_visible(users(:admin))
@tab.should_not be_visible(users(:existing))
end

it "should not be visible if any of the sub items are not visible to the current user" do
@subitem = Radiant::AdminUI::NavSubItem.new("/admin/users")
@tab << @subitem
it "should restrict to a group of roles" do
@tab.visibility.replace [:developer, :admin]
@tab.should be_visible(users(:developer))
@tab.should be_visible(users(:admin))
@tab.should_not be_visible(users(:existing))
end
end
Expand All @@ -96,8 +93,8 @@

describe Radiant::AdminUI::NavSubItem do
before :each do
@tab = Radiant::AdminUI::NavTab.new(:content)
@subitem = Radiant::AdminUI::NavSubItem.new("/admin/pages")
@tab = Radiant::AdminUI::NavTab.new(:content, "Content")
@subitem = Radiant::AdminUI::NavSubItem.new(:pages, "Pages", "/admin/pages")
@tab << @subitem
end

Expand All @@ -113,21 +110,6 @@
@subitem.url.should == "/admin/pages"
end

it "should create it's name based on the given URL" do
@subitem = Radiant::AdminUI::NavSubItem.new('/admin/all_around/town')
@subitem.name.should == :all_around_town
end

it "should parameterize and underscore a generated name" do
@subitem = Radiant::AdminUI::NavSubItem.new('/admin/things/to-do')
@subitem.name.should == :things_to_do
end

it "should generate a titilized proper name when given no proper_name" do
@subitem = Radiant::AdminUI::NavSubItem.new('/admin/things/to-do')
@subitem.proper_name.should == 'Things To Do'
end

describe "generating a relative url" do
it "should return the original url when no relative_url_root is set" do
@subitem.relative_url.should == "/admin/pages"
Expand Down Expand Up @@ -160,6 +142,12 @@
User.all.each {|user| @subitem.should be_visible(user) }
end

it "should not be visible when the parent tab is not visible to the user" do
@tab.visibility.replace [:admin]
@subitem.should_not be_visible(users(:developer))
@subitem.should_not be_visible(users(:existing))
end

describe "when the controller limits access to the action" do
before :each do
@subitem.url.sub!('pages', 'users')
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/radiant/admin_ui_spec.rb
Expand Up @@ -15,7 +15,7 @@
end

it "should create a new nav tab" do
@admin.nav_tab(:content).should be_kind_of(Radiant::AdminUI::NavTab)
@admin.nav_tab(:content, "Content").should be_kind_of(Radiant::AdminUI::NavTab)
end

it "should create a new nav item" do
Expand Down
7 changes: 6 additions & 1 deletion spec/models/standard_tags_spec.rb
Expand Up @@ -71,7 +71,12 @@
it "should include draft pages by default on the dev host" do
page.should render('<r:children:each by="slug"><r:slug /> </r:children:each>').as('a b c d draft e f g h i j ').on('dev.site.com')
end


it 'should not list draft pages on dev.site.com when Radiant::Config["dev.host"] is set to something else' do
Radiant::Config['dev.host'] = 'preview.site.com'
page.should render('<r:children:each by="title"><r:slug /> </r:children:each>').as('a b c d e f g h i j ').on('dev.site.com')
end

it 'should error with invalid "limit" attribute' do
message = "`limit' attribute of `each' tag must be a positive number between 1 and 4 digits"
page.should render(page_children_each_tags(%{limit="a"})).with_error(message)
Expand Down

0 comments on commit 485bb4b

Please sign in to comment.