From f00d786d7942ecb9d2a78c380080f928fab24fc7 Mon Sep 17 00:00:00 2001 From: Sean Cribbs Date: Fri, 15 Aug 2008 11:09:30 -0400 Subject: [PATCH 1/3] Added more render regions to layout, snippet, user, and extension views. --- CHANGELOG | 1 + app/views/admin/extension/index.html.haml | 30 ++++++++++++----- app/views/admin/layout/index.html.haml | 41 ++++++++++++++--------- app/views/admin/snippet/index.html.haml | 30 +++++++++++------ app/views/admin/user/index.html.haml | 40 ++++++++++++++-------- lib/radiant/admin_ui.rb | 29 +++++++++++++++- spec/lib/radiant/admin_ui_spec.rb | 21 ++++++++++++ 7 files changed, 142 insertions(+), 50 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2b87b101d..69c17f511 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ == Change Log === Edge +* Added more render regions to layout, snippet, user, and extension views. [Sean Cribbs] * Fixed the radiant:update:scripts to find the proper directory [Jim Gay] * Factor out dev? functionality in StandardTags, allowing other tags to access it. [Sean Cribbs] diff --git a/app/views/admin/extension/index.html.haml b/app/views/admin/extension/index.html.haml index 8c70e0958..0b04a8543 100644 --- a/app/views/admin/extension/index.html.haml +++ b/app/views/admin/extension/index.html.haml @@ -11,18 +11,30 @@ %h1 Extensions += render_region :top + %table#extensions.index{:cellspacing=>"0", :border=>"0", :cellpadding=>"0"} %thead %tr - %th.extension Extension - %th.website Website - %th.version Version + - render_region :thead do |thead| + - thead.title_header do + %th.extension Extension + - thead.website_header do + %th.website Website + - thead.version_header do + %th.version Version %tbody - @extensions.each do |extension| %tr.node.level-1 - %td.extension - %h4= h extension.extension_name - %p= h extension.description - %td.website - = extension.url.nil? || extension.url.empty? ? "" : link_to("Website", extension.url, :target => "_blank") - %td.version= h extension.version \ No newline at end of file + - render_region :tbody do |tbody| + - tbody.title_cell do + %td.extension + %h4= h extension.extension_name + %p= h extension.description + - tbody.website_cell do + %td.website + = extension.url.nil? || extension.url.empty? ? "" : link_to("Website", extension.url, :target => "_blank") + - tbody.version_cell do + %td.version= h extension.version + += render_region :bottom \ No newline at end of file diff --git a/app/views/admin/layout/index.html.haml b/app/views/admin/layout/index.html.haml index f918fb593..8cdf89471 100644 --- a/app/views/admin/layout/index.html.haml +++ b/app/views/admin/layout/index.html.haml @@ -1,25 +1,34 @@ %h1 Layouts - -%p - Use layouts to apply a visual look to a Web page. Layouts can contain special tags to include - page content and other elements such as the header or footer. Click on a layout name below to - edit it or click Remove to delete it. +- render_region :top do |top| + - top.help_text do + %p + Use layouts to apply a visual look to a Web page. Layouts can contain special tags to include + page content and other elements such as the header or footer. Click on a layout name below to + edit it or click Remove to delete it. %table#layouts.index{:cellspacing=>"0", :border=>"0", :cellpadding=>"0" } %thead %tr - %th.layout - Layout - %th.modify - Modify + - render_region :thead do |thead| + - thead.title_header do + %th.layout + Layout + - thead.modify_header do + %th.modify + Modify %tbody - @layouts.each do |layout| %tr.node.level-1 - %td.layout - = image('layout', :alt => 'layout-icon') - = link_to layout.name, layout_edit_url(:id => layout) - %td.remove - = link_to image('remove', :alt => 'Remove Layout'), layout_remove_url(:id => layout) + - render_region :tbody do |tbody| + - tbody.title_cell do + %td.layout + = image('layout', :alt => 'layout-icon') + = link_to layout.name, layout_edit_url(:id => layout) + - tbody.modify_cell do + %td.remove + = link_to image('remove', :alt => 'Remove Layout'), layout_remove_url(:id => layout) -%p - = link_to image('new-layout', :alt => "New Layout"), layout_new_url +- render_region :bottom do |bottom| + - bottom.new_button do + %p + = link_to image('new-layout', :alt => "New Layout"), layout_new_url diff --git a/app/views/admin/snippet/index.html.haml b/app/views/admin/snippet/index.html.haml index 6b04023cd..0d984edac 100644 --- a/app/views/admin/snippet/index.html.haml +++ b/app/views/admin/snippet/index.html.haml @@ -1,20 +1,30 @@ %h1 Snippets -%p Snippets are generally small pieces of content which are included in other pages or layouts. +- render_region :top do |top| + - top.help_text do + %p Snippets are generally small pieces of content which are included in other pages or layouts. %table#snippets.index{:cellspacing=>"0", :border=>"0", :cellpadding=>"0"} %thead %tr - %th.snippet Snippet - %th.modify Modify + - render_region :thead do |thead| + - thead.title_header do + %th.snippet Snippet + - thead.modify_header do + %th.modify Modify %tbody - @snippets.each do |snippet| %tr.node.level-1 - %td.snippet - = image('snippet', :alt => 'snippet-icon') - %span= link_to snippet.name, snippet_edit_url(:id => snippet) - %td.remove - = link_to image('remove', :alt => 'Remove Snippet'), snippet_remove_url(:id => snippet) + - render_region :tbody do |tbody| + - tbody.title_cell do + %td.snippet + = image('snippet', :alt => 'snippet-icon') + %span= link_to snippet.name, snippet_edit_url(:id => snippet) + - tbody.modify_cell do + %td.remove + = link_to image('remove', :alt => 'Remove Snippet'), snippet_remove_url(:id => snippet) -%p - = link_to image('new-snippet', :alt => 'New Snippet'), snippet_new_url \ No newline at end of file +- render_region :bottom do |bottom| + - bottom.new_button do + %p + = link_to image('new-snippet', :alt => 'New Snippet'), snippet_new_url \ No newline at end of file diff --git a/app/views/admin/user/index.html.haml b/app/views/admin/user/index.html.haml index facb32b24..9a0c947b0 100644 --- a/app/views/admin/user/index.html.haml +++ b/app/views/admin/user/index.html.haml @@ -1,23 +1,35 @@ %h1 Users += render_region :top + %table#users.index{:cellspacing=>"0", :border=>"0", :cellpadding=>"0"} %thead %tr - %th.user Name / Login - %th.roles Roles - %th.modify Modify + - render_region :thead do |thead| + - thead.title_header do + %th.user Name / Login + - thead.roles_header do + %th.roles Roles + - thead.modify_header do + %th.modify Modify %tbody - @users.each do |user| %tr.node.level-1 - %td.user - = link_to user.name, user_edit_url(:id => user) - %small.login= h user.login - %td.roles= roles(user) - %td.remove - - if user == current_user - = image('remove-disabled', :alt => 'Remove') - - else - = link_to(image('remove', :alt => 'Remove User'), user_remove_url(:id => user)) + - render_region :tbody do |tbody| + - tbody.title_cell do + %td.user + = link_to user.name, user_edit_url(:id => user) + %small.login= h user.login + - tbody.roles_cell do + %td.roles= roles(user) + - tbody.modify_cell do + %td.remove + - if user == current_user + = image('remove-disabled', :alt => 'Remove') + - else + = link_to(image('remove', :alt => 'Remove User'), user_remove_url(:id => user)) -%p - = link_to image('new-user', :alt => 'New User'), user_new_url, :title => "New User" \ No newline at end of file +- render_region :bottom do |bottom| + - bottom.new_button do + %p + = link_to image('new-user', :alt => 'New User'), user_new_url, :title => "New User" \ No newline at end of file diff --git a/lib/radiant/admin_ui.rb b/lib/radiant/admin_ui.rb index b7a99bc67..f0ba37874 100644 --- a/lib/radiant/admin_ui.rb +++ b/lib/radiant/admin_ui.rb @@ -78,7 +78,7 @@ def clear attr_accessor :tabs # Region sets - attr_accessor :page, :snippet, :layout, :user + attr_accessor :page, :snippet, :layout, :user, :extension def initialize @tabs = TabSet.new @@ -90,6 +90,7 @@ def load_default_regions @snippet = load_default_snippet_regions @layout = load_default_layout_regions @user = load_default_user_regions + @extension = load_default_extension_regions end private @@ -121,6 +122,11 @@ def load_default_user_regions edit_roles edit_notes} edit.form_bottom.concat %w{edit_timestamp edit_buttons} end + user.index = RegionSet.new do |index| + index.thead.concat %w{title_header roles_header modify_header} + index.tbody.concat %w{title_cell roles_cell modify_cell} + index.bottom.concat %w{new_button} + end end end @@ -131,6 +137,12 @@ def load_default_snippet_regions edit.form.concat %w{edit_title edit_content edit_filter edit_timestamp} edit.form_bottom.concat %w{edit_buttons} end + snippet.index = RegionSet.new do |index| + index.top.concat %w{help_text} + index.thead.concat %w{title_header modify_header} + index.tbody.concat %w{title_cell modify_cell} + index.bottom.concat %w{new_button} + end end end @@ -141,6 +153,21 @@ def load_default_layout_regions edit.form.concat %w{edit_title edit_extended_metadata edit_content edit_timestamp} edit.form_bottom.concat %w{edit_buttons} end + layout.index = RegionSet.new do |index| + index.top.concat %w{help_text} + index.thead.concat %w{title_header modify_header} + index.tbody.concat %w{title_cell modify_cell} + index.bottom.concat %w{new_button} + end + end + end + + def load_default_extension_regions + returning OpenStruct.new do |extension| + extension.index = RegionSet.new do |index| + index.thead.concat %w{title_header website_header version_header} + index.tbody.concat %w{title_cell website_cell version_cell} + end end end end diff --git a/spec/lib/radiant/admin_ui_spec.rb b/spec/lib/radiant/admin_ui_spec.rb index 8a0d07817..178e6ba0c 100644 --- a/spec/lib/radiant/admin_ui_spec.rb +++ b/spec/lib/radiant/admin_ui_spec.rb @@ -52,6 +52,11 @@ snippet.edit.form.should == %w{edit_title edit_content edit_filter edit_timestamp} snippet.edit.form_bottom.should == %w{edit_buttons} + snippet.index.should_not be_nil + snippet.index.top.should == %w{help_text} + snippet.index.thead.should == %w{title_header modify_header} + snippet.index.tbody.should == %w{title_cell modify_cell} + snippet.index.bottom.should == %w{new_button} end it "should load the default layout regions" do @@ -61,6 +66,11 @@ layout.edit.form.should == %w{edit_title edit_extended_metadata edit_content edit_timestamp} layout.edit.form_bottom.should == %w{edit_buttons} + layout.index.should_not be_nil + layout.index.top.should == %w{help_text} + layout.index.thead.should == %w{title_header modify_header} + layout.index.tbody.should == %w{title_cell modify_cell} + layout.index.bottom.should == %w{new_button} end it "should load the default user regions" do @@ -70,6 +80,17 @@ user.edit.form.should == %w{edit_name edit_email edit_username edit_password edit_roles edit_notes} user.edit.form_bottom.should == %w{edit_timestamp edit_buttons} + user.index.should_not be_nil + user.index.thead.should == %w{title_header roles_header modify_header} + user.index.tbody.should == %w{title_cell roles_cell modify_cell} + user.index.bottom.should == %w{new_button} + end + + it "should load the default extension regions" do + ext = @admin.extension + ext.index.should_not be_nil + ext.index.thead.should == %w{title_header website_header version_header} + ext.index.tbody.should == %w{title_cell website_cell version_cell} end end From ae779a796c7fcc1da11236f468cae89edeb4682f Mon Sep 17 00:00:00 2001 From: Sean Cribbs Date: Sat, 16 Aug 2008 11:17:30 -0400 Subject: [PATCH 2/3] Make script/extension more friendly, adding help and info commands. --- CHANGELOG | 1 + lib/radiant/extension/script.rb | 86 +++++++++++++++++++++-- spec/lib/radiant/extension/script_spec.rb | 66 +++++++++++++++++ 3 files changed, 146 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 69c17f511..5bce64a71 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ == Change Log === Edge +* Make script/extension more friendly, adding help and info commands. [Sean Cribbs] * Added more render regions to layout, snippet, user, and extension views. [Sean Cribbs] * Fixed the radiant:update:scripts to find the proper directory [Jim Gay] * Factor out dev? functionality in StandardTags, allowing other tags to access diff --git a/lib/radiant/extension/script.rb b/lib/radiant/extension/script.rb index d16cd255f..bb417fcaa 100644 --- a/lib/radiant/extension/script.rb +++ b/lib/radiant/extension/script.rb @@ -13,6 +13,18 @@ def install def uninstall Uninstaller.new(self).uninstall end + + def inspect +%{ +Name: #{name} +Description: + #{description} +Author: #{author.first_name} #{author.last_name} <#{author.email}> +Source code: #{repository_url} +Download: #{download_url} +Install type: #{install_type} +}.strip + end end class Action @@ -145,30 +157,30 @@ class Tarball < Download def filename "#{self.name}.tar" end - + def unpack output = `cd #{Dir.tmpdir}; tar xvf #{filename}` self.path = File.join(Dir.tmpdir, output.split(/\n/).first.split('/').first) end end - + class Gzip < Tarball def filename @unpacked ? super : "#{self.name}.tar.gz" end - + def unpack system "cd #{Dir.tmpdir}; gunzip #{self.filename}" @unpacked = true super end end - + class Bzip2 < Tarball def filename @unpacked ? super : "#{self.name}.tar.bz2" end - + def unpack system "cd #{Dir.tmpdir}; bunzip2 #{self.filename}" @unpacked = true @@ -189,8 +201,13 @@ class Extension module Script class << self def execute(args) - command = args.shift - const_get(command.camelize).new(args) + command = args.shift || 'help' + begin + const_get(command.camelize).new(args) + rescue ArgumentError => e + puts e.message + Help.new [command] + end end end @@ -246,6 +263,61 @@ def initialize(args=[]) end end end + + class Info + include Util + + def initialize(args=[]) + raise ArgumentError, "You must specify an extension to get info on" if args.blank? + self.extension_name = to_extension_name(args.shift) + find_extension and puts extension.inspect + end + end + + class Help + def initialize(args=[]) + command = args.shift + command = 'help' unless self.class.instance_methods(false).include?(command) + send(command) + end + + def help + $stdout.puts %{Usage: script/extension command [arguments] + + Available commands: + #{command_names} + + For help on an individual command: + script/extension help command + } + end + + def install + $stdout.puts %{Usage: script/extension install extension_name + + Installs an extension from information in the global registry. + } + end + + def uninstall + $stdout.puts %{Usage: script/extension uninstall extension_name + + Removes a previously installed extension from the current project. + } + end + + def info + $stdout.puts %{Usage: script/extension info extension_name + + Displays registry information about the extension. + } + end + + private + def command_names + (Radiant::Extension::Script.constants - ['Util']).sort.map {|n| n.underscore }.join(", ") + end + end end end end diff --git a/spec/lib/radiant/extension/script_spec.rb b/spec/lib/radiant/extension/script_spec.rb index 03addf4e4..3132237e4 100644 --- a/spec/lib/radiant/extension/script_spec.rb +++ b/spec/lib/radiant/extension/script_spec.rb @@ -14,6 +14,19 @@ Radiant::Extension::Script::Install.should_receive(:new).with(['page_attachments']) Radiant::Extension::Script.execute ['install', 'page_attachments'] end + + it "should run the help command when no arguments are given" do + Radiant::Extension::Script::Help.should_receive(:new) + Radiant::Extension::Script.execute [] + end + + it "should run the help for a given command when it fails" do + error_message = "You must specify an extension to install." + Radiant::Extension::Script::Install.should_receive(:new).and_raise(ArgumentError.new(error_message)) + Radiant::Extension::Script.should_receive(:puts).with(error_message) + Radiant::Extension::Script::Help.should_receive(:new).with(['install']) + Radiant::Extension::Script.execute ['install'] + end end describe "Radiant::Extension::Script::Util" do @@ -100,6 +113,59 @@ end end +describe "Radiant::Extension::Script::Info" do + before :each do + @extension = mock('Extension', :uninstall => true, :name => 'archive', :inspect => '') + Registry::Extension.stub!(:find).and_return([@extension]) + end + + it "should read the extension name from the command line" do + @info = Radiant::Extension::Script::Info.new ['archive'] + @info.extension_name.should == 'archive' + end + + it "should attempt to find the extension and display its info" do + @extension.should_receive(:inspect).and_return('') + @info = Radiant::Extension::Script::Info.new ['archive'] + end + + it "should fail if an extension name is not given" do + lambda { Radiant::Extension::Script::Info.new []}.should raise_error + end +end + +describe "Radiant::Extension::Script::Help" do + it "should display the general help message when no arguments are given" do + $stdout.should_receive(:puts).with(%r{Usage: script/extension command \[arguments\]}) + Radiant::Extension::Script::Help.new + end + + it "should display the general help message when the 'help' command is specified" do + $stdout.should_receive(:puts).with(%r{Usage: script/extension command \[arguments\]}) + Radiant::Extension::Script::Help.new ['help'] + end + + it "should display the general help message when an invalid command is given" do + $stdout.should_receive(:puts).with(%r{Usage: script/extension command \[arguments\]}) + Radiant::Extension::Script::Help.new ['foo'] + end + + it "should display the install help message" do + $stdout.should_receive(:puts).with(%r{Usage: script/extension install extension_name}) + Radiant::Extension::Script::Help.new ['install'] + end + + it "should display the uninstall help message" do + $stdout.should_receive(:puts).with(%r{Usage: script/extension uninstall extension_name}) + Radiant::Extension::Script::Help.new ['uninstall'] + end + + it "should display the info help message" do + $stdout.should_receive(:puts).with(%r{Usage: script/extension info extension_name}) + Radiant::Extension::Script::Help.new ['info'] + end +end + describe "Registry::Action" do before :each do @action = Registry::Action.new From e60e553e63152bae34d96a837a9d38bbd565cd27 Mon Sep 17 00:00:00 2001 From: Josh French Date: Mon, 18 Aug 2008 15:54:30 -0400 Subject: [PATCH 3/3] Less verbose extension:update task --- lib/generators/extension/templates/tasks.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/extension/templates/tasks.rake b/lib/generators/extension/templates/tasks.rake index 8e9810cd9..af46c9d0d 100644 --- a/lib/generators/extension/templates/tasks.rake +++ b/lib/generators/extension/templates/tasks.rake @@ -15,10 +15,10 @@ namespace :radiant do desc "Copies public assets of the <%= extension_name %> to the instance public/ directory." task :update => :environment do is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) } + puts "Copying assets from <%= class_name %>" Dir[<%= class_name %>.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file| path = file.sub(<%= class_name %>.root, '') directory = File.dirname(path) - puts "Copying #{path}..." mkdir_p RAILS_ROOT + directory cp file, RAILS_ROOT + path end