From 221588b29062e62a48ab55ed5613c0ed3642b51a Mon Sep 17 00:00:00 2001 From: Andrew vonderLuft Date: Fri, 22 Apr 2011 15:32:46 -0700 Subject: [PATCH] major refactor and upgrade for Radiant 1.0.0 --- HELP.textile | 11 ++ README | 15 -- README.textile | 51 +++++++ Rakefile | 15 ++ app/controllers/admin/search_controller.rb | 13 ++ app/controllers/searches_controller.rb | 7 - .../search_helper.rb} | 11 +- app/views/admin/_sitemap_search.html.haml | 21 --- app/views/admin/pages/index.html.haml | 28 ++++ .../admin/pages/page_list_view.html.haml | 27 ++++ app/views/admin/search/_banner.html.haml | 11 ++ .../search/_banner_index_bottom.html.haml | 5 + app/views/admin/search/_layout.html.haml | 8 ++ .../search/_layout_index_bottom.html.haml | 5 + app/views/admin/search/_results_nav.html.haml | 15 ++ .../admin/search/_search_action.html.haml | 7 + app/views/admin/search/_snippet.html.haml | 8 ++ .../search/_snippet_index_bottom.html.haml | 5 + app/views/admin/search/_template.html.haml | 8 ++ .../search/_template_index_bottom.html.haml | 4 + app/views/admin/search/index.html.haml | 128 ++++++++++++++++++ app/views/searches/_snippet.html.haml | 7 - app/views/searches/index.html.haml | 99 -------------- config/locales/en.yml | 7 + config/routes.rb | 3 + lib/sitemap_search.rb | 2 - lib/sitemap_search/model.rb | 15 +- sitemap_search_extension.rb | 35 +++-- spec/controllers/search_controller_spec.rb | 111 +++++++++++++++ spec/controllers/searches_controller_spec.rb | 38 ------ spec/models/page_extensions_spec.rb | 21 ++- 31 files changed, 516 insertions(+), 225 deletions(-) create mode 100644 HELP.textile delete mode 100644 README create mode 100644 README.textile create mode 100644 app/controllers/admin/search_controller.rb delete mode 100644 app/controllers/searches_controller.rb rename app/helpers/{searches_helper.rb => admin/search_helper.rb} (76%) delete mode 100644 app/views/admin/_sitemap_search.html.haml create mode 100644 app/views/admin/pages/index.html.haml create mode 100644 app/views/admin/pages/page_list_view.html.haml create mode 100644 app/views/admin/search/_banner.html.haml create mode 100644 app/views/admin/search/_banner_index_bottom.html.haml create mode 100644 app/views/admin/search/_layout.html.haml create mode 100644 app/views/admin/search/_layout_index_bottom.html.haml create mode 100644 app/views/admin/search/_results_nav.html.haml create mode 100644 app/views/admin/search/_search_action.html.haml create mode 100644 app/views/admin/search/_snippet.html.haml create mode 100644 app/views/admin/search/_snippet_index_bottom.html.haml create mode 100644 app/views/admin/search/_template.html.haml create mode 100644 app/views/admin/search/_template_index_bottom.html.haml create mode 100644 app/views/admin/search/index.html.haml delete mode 100644 app/views/searches/_snippet.html.haml delete mode 100644 app/views/searches/index.html.haml create mode 100644 config/locales/en.yml create mode 100644 config/routes.rb delete mode 100644 lib/sitemap_search.rb create mode 100644 spec/controllers/search_controller_spec.rb delete mode 100644 spec/controllers/searches_controller_spec.rb diff --git a/HELP.textile b/HELP.textile new file mode 100644 index 0000000..a8a4a5d --- /dev/null +++ b/HELP.textile @@ -0,0 +1,11 @@ +The *Sitemap Search* extension, as its name implies, enables you to search your sitemap; pages, snippets and layouts + +h2. Usage + +The Search tab is located under 'Content' to the right of 'Pages' + +The Search box is located in the lower bar of the index page for Pages, Snippets, Layouts. +If you have the the BannerRotator extension and/or the Templates extension installed, it will be on those index pages also. +And of course it is also on the Search Results page. + +Enter your search string, and click the button. Results are sortable by attribute. diff --git a/README b/README deleted file mode 100644 index cec3d88..0000000 --- a/README +++ /dev/null @@ -1,15 +0,0 @@ -= Sitemap Search - -Originally created by Sean Cribbs, fall 2007. Revised and generalized August -2008. - -Provides a simple search for pages within the sitemap. Contains rudimentary -support for scoping searches within a given site when using the multi_site -extension. - -= Acknowledgments - -Thanks to Digital Pulp for funding the initial development of this extension -as part of the Redken.com project. - -Further support for generalization and release was provided by Con-way. \ No newline at end of file diff --git a/README.textile b/README.textile new file mode 100644 index 0000000..2ffbf99 --- /dev/null +++ b/README.textile @@ -0,0 +1,51 @@ +h2. Sitemap Search + +Created by Sean Cribbs in Fall 2007. +Revised and generalized by Sean Cribbs and Andrew vonderLuft in August 2008. +Extended and refactored by Andrew vonderLuft since then. + +Provides a simple content search of pages, snippets, and layouts. +Contains rudimentary support for scoping searches within a given site when using the multi_site extension. + +h2. Revision History + +* 4/2011 - UI upgrade for Radiant >= 1.0.0; added Layouts; added templates to search from "Templates extension":https://github.com/avonderluft/radiant-templates-extension +* 2/2010 - add banners to search, from "BannerRotator extension":https://github.com/avonderluft/radiant-banner_rotator-extension +* 2/2009 - upgraded for compatibility with Radiant 0.7 +* 12/2008 - initial commit + +h2. Requirements + +* current version requires Radiant >= 1.0.0 +* tag 0.7.2 available for earlier versions + +page_list_view extension must be installed + +From your RADIANT_ROOT: + +
+$ script/extension install page_list_view
+
+ +h2. Installation + +From your RADIANT_ROOT: + +
+$ script/extension install sitemap_search
+
+ +Restart your radiant app, and you should be good to go. + +h2. Usage + +See the Help doc. + +h2. To do + +* Include page fields, e.g. 'keywords' and 'description' + +h2. Acknowledgments + +Thanks to Digital Pulp for funding the initial development of this extension as part of the Redken.com project. +Further support for generalization and release was provided by Con-way. \ No newline at end of file diff --git a/Rakefile b/Rakefile index 2add3c3..cdfeced 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,18 @@ +begin + require 'jeweler' + Jeweler::Tasks.new do |gem| + gem.name = "radiant-sitemap_search-extension" + gem.summary = %Q{Sitemap Search Extension for Radiant CMS} + gem.description = %Q{Adds search feature for pages, snippets, layouts, et al.} + gem.email = "avonderluft@avlux.net" + gem.homepage = "https://github.com/avonderluft/radiant-sitemap_search-extension" + gem.authors = ['Andrew vonderLuft','Sean Cribbs'] + gem.add_dependency 'radiant', ">=1.0.0" + # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings + end +rescue LoadError + puts "Jeweler (or a dependency) not available. This is only required if you plan to package banner_rotator as a gem." +end # I think this is the one that should be moved to the extension Rakefile template # In rails 1.2, plugins aren't available in the path until they're loaded. diff --git a/app/controllers/admin/search_controller.rb b/app/controllers/admin/search_controller.rb new file mode 100644 index 0000000..f43ae24 --- /dev/null +++ b/app/controllers/admin/search_controller.rb @@ -0,0 +1,13 @@ +class Admin::SearchController < ApplicationController + def index + if params[:q] + @pages = Page.search(params[:q]) + if current_user.designer? || current_user.admin? + @snippets = Snippet.search(params[:q]) + @layouts = Layout.search(params[:q]) + @templates = Template.search(params[:q]) if defined?(TemplatesExtension) + @banners = Banner.search(params[:q]) if defined?(BannerRotatorExtension) + end + end + end +end diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb deleted file mode 100644 index 0c4a95d..0000000 --- a/app/controllers/searches_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class SearchesController < ApplicationController - def index - @pages = Page.search(params[:q]) - @snippets = Snippet.search(params[:q]) - @banners = Banner.search(params[:q]) if defined?(BannerRotator) - end -end diff --git a/app/helpers/searches_helper.rb b/app/helpers/admin/search_helper.rb similarity index 76% rename from app/helpers/searches_helper.rb rename to app/helpers/admin/search_helper.rb index d466a9a..ae69eae 100644 --- a/app/helpers/searches_helper.rb +++ b/app/helpers/admin/search_helper.rb @@ -1,4 +1,4 @@ -module SearchesHelper +module Admin::SearchHelper include Admin::ListViewHelper def link_text(object) @@ -15,12 +15,9 @@ def link_text(object) def link_url(object) case object - when Page - page_edit_path(:id => object) - when Snippet - snippet_edit_path(:id => object) - when Banner - edit_admin_banner_path(:id => object) + when Page; edit_admin_page_path(:id => object) + when Snippet; edit_admin_snippet_path(:id => object) + when Banner; edit_admin_banner_path(:id => object) end end diff --git a/app/views/admin/_sitemap_search.html.haml b/app/views/admin/_sitemap_search.html.haml deleted file mode 100644 index aa90028..0000000 --- a/app/views/admin/_sitemap_search.html.haml +++ /dev/null @@ -1,21 +0,0 @@ -- form_tag searches_path, :method => :get, :id => "site_search" do - %p - - if defined?(Site) && @site - = hidden_field_tag :site_id, @site.id - - if defined?(BannerRotator) - = text_field_tag :q, params[:q], :title => "Search for pages, snippets and banners" - - else - = text_field_tag :q, params[:q], :title => "Search for pages and snippets" - %input{:type =>"submit", :value =>"Search"} -- content_for :page_css do - :sass - #site_search - float: right - margin-top: -60px - margin-right: 220px - html>body #site_search - *margin-right: 20px - *margin-top: -40px - * html #site_search - margin-right: 20px - margin-top: -40px \ No newline at end of file diff --git a/app/views/admin/pages/index.html.haml b/app/views/admin/pages/index.html.haml new file mode 100644 index 0000000..2fbd41c --- /dev/null +++ b/app/views/admin/pages/index.html.haml @@ -0,0 +1,28 @@ +- @page_title = t('pages') + ' - ' + default_page_title + +.outset + = render_region :top + %table.index#pages{:summary=>t('page_hierarchy')} + %thead + %tr + - render_region :sitemap_head do |sitemap_head| + - sitemap_head.title_column_header do + %th.name= t('page') + - sitemap_head.status_column_header do + %th.status= t('status') + - sitemap_head.actions_column_header do + %th.actions= t('modify') + %tbody + - if @homepage + = render_node @homepage + - else + %tr + %td.empty{:colspan => admin.page.index.node.length}= t('no_pages') + = render_region :bottom + +#actions + %ul + - unless @homepage + %li= link_to image('plus') + " " + t("new_homepage"), new_admin_page_path, :class => 'action_button' + - else + = render :partial => 'admin/search/search_action' \ No newline at end of file diff --git a/app/views/admin/pages/page_list_view.html.haml b/app/views/admin/pages/page_list_view.html.haml new file mode 100644 index 0000000..4d2829f --- /dev/null +++ b/app/views/admin/pages/page_list_view.html.haml @@ -0,0 +1,27 @@ +- include_javascript 'admin/tablekit' +- include_javascript 'admin/ruledtable' +- @page_title = t('pages') + ' - ' + default_page_title + +.outset + = render_region :top + %table.index.sortable{:summary=>"Sortable list of pages"} + %thead + %tr + - list_display_attributes.each do |att| + %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } + %a + %span.w1= att.humanize + %tbody + - if @pages.any? + = render :partial => 'page', :collection => @pages + - else + %tr + %td.empty{:colspan => list_display_attributes.length}= t('no_pages') +#actions + = pagination_for(@pages) + %ul + - unless @pages.any? + %li= link_to image('plus') + " " + t("new_homepage"), new_admin_page_path, :class => 'action_button' + = render :partial => 'admin/search/search_action' + += render :partial => 'page_list_view_styles' \ No newline at end of file diff --git a/app/views/admin/search/_banner.html.haml b/app/views/admin/search/_banner.html.haml new file mode 100644 index 0000000..a0c4388 --- /dev/null +++ b/app/views/admin/search/_banner.html.haml @@ -0,0 +1,11 @@ +%tr[banner] + %td.preview + %a{:href => edit_admin_banner_url(banner)} + %img.snapshot{:src => banner.background_image, :alt => "#{banner.name} #{t('banner_rotator.banner')}", :title => "#{t('banner_rotator.edit')} #{banner.name} #{t('banner_rotator.banner')}"} + %td.name= link_to banner.name, edit_admin_banner_url(banner) + %td.status + = banner.description if banner.description + %td.status{:style=>"font-size:75%"} + = banner.link_url if banner.link_url + %td.status + = banner.updated_at.strftime("%m/%d/%Y at %I:%M %p") if banner.updated_at \ No newline at end of file diff --git a/app/views/admin/search/_banner_index_bottom.html.haml b/app/views/admin/search/_banner_index_bottom.html.haml new file mode 100644 index 0000000..bae3580 --- /dev/null +++ b/app/views/admin/search/_banner_index_bottom.html.haml @@ -0,0 +1,5 @@ +#actions + = pagination_for(@banners) + %ul + %li= link_to image('plus') + " " + t('banner_rotator.new_banner'), new_admin_banner_url + = render :partial => 'admin/search/search_action' \ No newline at end of file diff --git a/app/views/admin/search/_layout.html.haml b/app/views/admin/search/_layout.html.haml new file mode 100644 index 0000000..a57e00e --- /dev/null +++ b/app/views/admin/search/_layout.html.haml @@ -0,0 +1,8 @@ +%tr[layout] + %td.name + = image('layout', :alt => '') + = link_to layout.name, edit_admin_layout_url(layout) + %td.status + = layout.updated_by.name if layout.updated_by + %td.status + = layout.updated_at.strftime("%m/%d/%Y at %I:%M %p") if layout.updated_at \ No newline at end of file diff --git a/app/views/admin/search/_layout_index_bottom.html.haml b/app/views/admin/search/_layout_index_bottom.html.haml new file mode 100644 index 0000000..583099b --- /dev/null +++ b/app/views/admin/search/_layout_index_bottom.html.haml @@ -0,0 +1,5 @@ +#actions + = pagination_for(@layouts) + %ul + %li= link_to image('plus') + " " + t('new_layout'), new_admin_layout_url, :class => 'action_button' + = render :partial => 'admin/search/search_action' \ No newline at end of file diff --git a/app/views/admin/search/_results_nav.html.haml b/app/views/admin/search/_results_nav.html.haml new file mode 100644 index 0000000..7085cd2 --- /dev/null +++ b/app/views/admin/search/_results_nav.html.haml @@ -0,0 +1,15 @@ +.nav + = link_to t('pages') + " (#{@pages.size})", '#pages' + - if designer? + • + = link_to t('snippets') + " (#{@snippets.size})", '#snippets' + • + = link_to t('layouts') + " (#{@layouts.size})", '#layouts' + - if defined?(TemplatesExtension) + • + = link_to t('templates') + " (#{@templates.size})", '#templates' + - if defined?(BannerRotatorExtension) + • + = link_to t('banner_rotator.banners') + " (#{@banners.size})", '#banners' + • + = link_to 'Top', '#top' \ No newline at end of file diff --git a/app/views/admin/search/_search_action.html.haml b/app/views/admin/search/_search_action.html.haml new file mode 100644 index 0000000..a23c573 --- /dev/null +++ b/app/views/admin/search/_search_action.html.haml @@ -0,0 +1,7 @@ +%li + #site_search.action_button + - form_for :site_search, :url => search_path, :html => { :class => 'button_form', :multipart => true } do |f| + %span + = f.label :site_search, image('search') + = text_field_tag :q, params[:q], :title => t('sitemap_search.search_content'), :cols => "20" + = f.submit t('sitemap_search.search_content') \ No newline at end of file diff --git a/app/views/admin/search/_snippet.html.haml b/app/views/admin/search/_snippet.html.haml new file mode 100644 index 0000000..e853d2a --- /dev/null +++ b/app/views/admin/search/_snippet.html.haml @@ -0,0 +1,8 @@ +%tr[snippet] + %td.name + = image('snippet', :alt => '') + = link_to snippet.name, edit_admin_snippet_url(snippet) + %td.status + = snippet.updated_by.name if snippet.updated_by + %td.status + = snippet.updated_at.strftime("%m/%d/%Y at %I:%M %p") if snippet.updated_at \ No newline at end of file diff --git a/app/views/admin/search/_snippet_index_bottom.html.haml b/app/views/admin/search/_snippet_index_bottom.html.haml new file mode 100644 index 0000000..69b114a --- /dev/null +++ b/app/views/admin/search/_snippet_index_bottom.html.haml @@ -0,0 +1,5 @@ +#actions + = pagination_for(@snippets) + %ul + %li= link_to image('plus') + " " + t('new_snippet'), new_admin_snippet_url, :class => 'action_button' + = render :partial => 'admin/search/search_action' \ No newline at end of file diff --git a/app/views/admin/search/_template.html.haml b/app/views/admin/search/_template.html.haml new file mode 100644 index 0000000..12216a0 --- /dev/null +++ b/app/views/admin/search/_template.html.haml @@ -0,0 +1,8 @@ +%tr[template] + %td.name + = image('template', :alt => '') + = link_to template.name, edit_admin_template_url(template) + %td.status + = template.page_class_name if template.page_class_name + %td.status + = template.updated_at.strftime("%m/%d/%Y at %I:%M %p") if template.updated_at \ No newline at end of file diff --git a/app/views/admin/search/_template_index_bottom.html.haml b/app/views/admin/search/_template_index_bottom.html.haml new file mode 100644 index 0000000..a42ccc7 --- /dev/null +++ b/app/views/admin/search/_template_index_bottom.html.haml @@ -0,0 +1,4 @@ +#actions + %ul + %li= link_to image('plus') + " " + t('new_template'), new_admin_template_url + = render :partial => 'admin/search/search_action' \ No newline at end of file diff --git a/app/views/admin/search/index.html.haml b/app/views/admin/search/index.html.haml new file mode 100644 index 0000000..0b0a9ef --- /dev/null +++ b/app/views/admin/search/index.html.haml @@ -0,0 +1,128 @@ +- include_javascript 'admin/ruledtable' +- include_javascript 'admin/tablekit' +- @page_title = t('sitemap_search.search_content') + ' - ' + default_page_title + +- if params[:q] + - query = ': ' + t('sitemap_search.search_results_for') + " '#{params[:q]}'" + - results_label = t('pages') + query + %h3#pages{:style=>"margin-top:-10px"} + = results_label + = render :partial => 'results_nav' + %table#page_list.index.sortable{:summary=>results_label} + %thead + %tr + - list_display_attributes.each do |att| + %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } + %a + %span.w1= att.humanize + %tbody + - unless @pages.blank? + = render :partial => "admin/pages/page", :collection => @pages + - else + %tr + %td.note{:colspan => list_display_attributes.size } + = params[:q].blank? ? "Empty search." : "No results from query." + + - if designer? + - results_label = t('snippets') + query + %h3#snippets + = results_label + = render :partial => 'results_nav' + %table#snippet_list.index.sortable{:summary=>results_label} + %thead + %tr + - atts = %w{name updated_by updated_at} + - atts.each do |att| + %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } + %a + %span.w1= att.humanize + %tbody + - unless @snippets.blank? + = render :partial => "snippet", :collection => @snippets + - else + %tr + %td.note{:colspan => atts.size } + = params[:q].blank? ? "Empty search." : "No results from query." + + - results_label = t('layouts') + query + %h3#layouts + = results_label + = render :partial => 'results_nav' + %table#layout_list.index.sortable{:summary=>results_label} + %thead + %tr + - atts = %w{name updated_by updated_at} + - atts.each do |att| + %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } + %a + %span.w1= att.humanize + %tbody + - unless @layouts.blank? + = render :partial => "layout", :collection => @layouts + - else + %tr + %td.note{:colspan => atts.size } + = params[:q].blank? ? "Empty search." : "No results from query." + + - results_label = t('templates') + query + %h3#templates + = results_label + = render :partial => 'results_nav' + %table#template_list.index.sortable{:summary=>results_label} + %thead + %tr + - atts = %w{name page_class_name updated_at} + - atts.each do |att| + %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } + %a + %span.w1= att.humanize + %tbody + - unless @templates.blank? + = render :partial => "template", :collection => @templates + - else + %tr + %td.note{:colspan => atts.size } + = params[:q].blank? ? "Empty search." : "No results from query." + + - if defined?(BannerRotatorExtension) + - results_label = t('banner_rotator.banners') + query + %h3#banners + = results_label + = render :partial => 'results_nav' + %table#banner_list.index.sortable{:summary=>results_label} + %thead + %tr + %th.image + - atts = %w{name description link_url updated_at} + - atts.each do |att| + %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } + %a + %span.w1= att.humanize + %tbody + - unless @banners.blank? + = render :partial => "banner", :collection => @banners + - else + %tr + %td.note{:colspan => atts.size + 1 } + = params[:q].blank? ? "Empty search." : "No results from query." +- else + %h3= t('sitemap_search.search_content') + = t('sitemap_search.instructions') + +#actions + %ul + = render :partial => 'search_action' + += render :partial => 'admin/pages/page_list_view_styles' +- content_for :page_css do + :sass + .nav + float: right + font-size: 80% + h3 + padding: 5px + td + .snapshot + height: 40px + max-width: 320px + border: 1px solid d5f0ff \ No newline at end of file diff --git a/app/views/searches/_snippet.html.haml b/app/views/searches/_snippet.html.haml deleted file mode 100644 index ef7869e..0000000 --- a/app/views/searches/_snippet.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%tr{:class => 'node level-4'} - %td{:class => cell_class(snippet)} - %span.w1= link_to link_text(snippet), link_url(snippet), link_attrs(snippet) - %td - %span.w1= snippet.updated_by.name if snippet.updated_by - %td - %span.w1= snippet.updated_at.strftime("%m/%d/%Y at %I:%M %p") if snippet.updated_at \ No newline at end of file diff --git a/app/views/searches/index.html.haml b/app/views/searches/index.html.haml deleted file mode 100644 index d621f28..0000000 --- a/app/views/searches/index.html.haml +++ /dev/null @@ -1,99 +0,0 @@ -- include_javascript 'admin/ruledtable' -- include_javascript 'admin/tablekit' - -%h1 Search Results - -= render :partial => 'admin/sitemap_search' - -%p - Jump to: - = link_to 'Pages', '#pages' - = link_to 'Snippets', '#snippets' - - if defined?(BannerRotator) - = link_to 'Banners', '#banners' - -%h2#pages Pages - -%table.index.sortable{:summary=>"Page search results for your query '#{params[:q]}'"} - %thead - %tr - - list_display_attributes.each do |att| - %th{:class => attribute_header_class(att), :id => attribute_header_id(att) } - %a - %span.w1= att.humanize - %tbody - - if !@pages.blank? - = render :partial => "admin/pages/page", :collection => @pages - - else - %tr - %td.note{:colspan => list_display_attributes.size } - = params[:q].blank? ? "Empty search." : "No results from query." - Please try again. - -%h2#snippets Snippets - -%table#snippet_list.index.sortable{:summary=>"Snippet search results for your query '#{params[:q]}'"} - %thead - %tr - %th - %a - %span.w1 Name - %th - %a - %span.w1 Updated by name - %th - %a - %span.w1 Updated at - %tbody - - if !@snippets.blank? - = render :partial => "snippet", :collection => @snippets - - else - %tr - %td.note{:colspan => 3 } - = params[:q].blank? ? "Empty search." : "No results from query." - Please try again. - -- if defined?(BannerRotatorExtension) - - %h2#banners Banners - - %table#banner_list.index.sortable{:summary=>"Banner search results for your query '#{params[:q]}'"} - %thead - %tr - %th - %a - %span.w1 Name - %th - %a - %span.w1 Link URL - %th - %a - %span.w1 Updated at - %tbody - - if !@banners.blank? - = render :partial => "banner", :collection => @banners - - else - %tr - %td.note{:colspan => 3 } - = params[:q].blank? ? "Empty search." : "No results from query." - Please try again. - -- content_for :page_css do - :sass - #content - table.index.sortable - th - background-position: right center - background-repeat: no-repeat - &.sortasc - background-image: url(/images/admin/move_lower.png) ! important - background-color: #ff8 ! important - &.sortdesc - background-image: url(/images/admin/move_higher.png) ! important - background-color: #8ff ! important - th a - color: black - text-decoration: none - font-weight: bold - &:hover - text-decoration: underline \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..aed4527 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,7 @@ +--- +en: + sitemap_search: + instructions: "Enter query string at bottom of page to search." + search: "Search" + search_content: "Search Content" + search_results_for: "Search Results for" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..f5af2f7 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +ActionController::Routing::Routes.draw do |map| + map.search 'admin/search', :controller => 'admin/search', :action => 'index' +end \ No newline at end of file diff --git a/lib/sitemap_search.rb b/lib/sitemap_search.rb deleted file mode 100644 index be9f3ea..0000000 --- a/lib/sitemap_search.rb +++ /dev/null @@ -1,2 +0,0 @@ -module SitemapSearch -end \ No newline at end of file diff --git a/lib/sitemap_search/model.rb b/lib/sitemap_search/model.rb index 8b0aaea..3ca13da 100644 --- a/lib/sitemap_search/model.rb +++ b/lib/sitemap_search/model.rb @@ -4,14 +4,19 @@ def self.included(base) base.send :cattr_accessor, :search_fields base.send :cattr_accessor, :includes if base == Page - base.search_fields = [:title, :slug, :keywords, :description, :content] - base.search_fields << :draft_content if defined?(ConcurrentDraft) + base.search_fields = [:title, :slug, :breadcrumb, :content] + base.search_fields << :draft_content if defined?(ConcurrentDraftExtension) base.includes = [:parts] elsif base == Snippet base.search_fields = [:name, :content] - base.search_fields << :draft_content if defined?(ConcurrentDraft) - elsif defined?(BannerRotator) && base == Banner - base.search_fields = [:name, :background_image, :foreground_image, :link_url] + base.search_fields << :draft_content if defined?(ConcurrentDraftExtension) + elsif base == Layout + base.search_fields = [:name, :content] + base.search_fields << :draft_content if defined?(ConcurrentDraftExtension) + elsif defined?(TemplatesExtension) && base == Template + base.search_fields = [:name, :content] + elsif defined?(BannerRotatorExtension) && base == Banner + base.search_fields = [:name, :description, :background_image, :foreground_image, :link_url] end end diff --git a/sitemap_search_extension.rb b/sitemap_search_extension.rb index 8effe4f..52d4b59 100644 --- a/sitemap_search_extension.rb +++ b/sitemap_search_extension.rb @@ -2,25 +2,34 @@ # require_dependency 'application' class SitemapSearchExtension < Radiant::Extension - version "1.2" - description "Adds a simple search feature to pages, snippets and banners" - url "http://github.com/avonderluft/radiant-sitemap_search-extension/tree/master" - - define_routes do |map| - map.resources :searches, :path_prefix => '/admin' - end - + version "#{File.read(File.expand_path(File.dirname(__FILE__)) + '/VERSION')}" + description "Adds simple search feature for pages, snippets, layouts, et al." + url "https://github.com/avonderluft/radiant-sitemap_search-extension" + def activate unless defined?(PageListView) raise "The Page List View extension is required - install from RAILS_ROOT with 'script/extension install page_list_view'" end - Page.send :include, SitemapSearch::Model - Snippet.send :include, SitemapSearch::Model - admin.page.index.add :top, 'admin/sitemap_search' - admin.snippet.index.add :top, 'admin/sitemap_search' + tab "Content" do + add_item "Search", '/admin/search' + end + [Page, Snippet, Layout].each do |klass| + klass.send :include, SitemapSearch::Model + end + admin.snippet.index.bottom.delete 'new_button' + admin.snippet.index.add :bottom, 'admin/search/snippet_index_bottom' + admin.layout.index.bottom.delete 'new_button' + admin.layout.index.add :bottom, 'admin/search/layout_index_bottom' + if defined?(TemplatesExtension) + Template.send :include, SitemapSearch::Model + admin.template.index.bottom.delete 'new_button' + admin.template.index.add :bottom, 'admin/search/banner_index_bottom' + end if defined?(BannerRotatorExtension) Banner.send :include, SitemapSearch::Model - admin.banner.index.add :top, 'admin/sitemap_search' + admin.banner.index.bottom.delete 'new_button' + admin.banner.index.add :bottom, 'admin/search/template_index_bottom' end end + end \ No newline at end of file diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb new file mode 100644 index 0000000..edbcc12 --- /dev/null +++ b/spec/controllers/search_controller_spec.rb @@ -0,0 +1,111 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Admin::SearchController do + dataset :users + + [:admin, :designer].each do |user| + describe "search as user with #{user} privileges" do + before :each do + @page, @snippet, @layout = mock_model(Page), mock_model(Snippet), mock_model(Layout) + Page.stub!(:search).and_return([@page]) + Snippet.stub!(:search).and_return([@snippet]) + Layout.stub!(:search).and_return([@layout]) + login_as user + end + + def do_get + get :index, :q => 'radiant' + end + it "should search pages" do + Page.should_receive(:search).with('radiant').and_return([@page]) + do_get + end + it "should search snippets" do + Snippet.should_receive(:search).with('radiant').and_return([@snippet]) + do_get + end + it "should search layouts" do + Layout.should_receive(:search).with('radiant').and_return([@layout]) + do_get + end + if defined?(TemplatesExtension) + it "should search templates" do + @banner = mock_model(Template) + Template.stub!(:search).and_return([@template]) + Template.should_receive(:search).with('radiant').and_return([@template]) + do_get + end + end + if defined?(BannerRotatorExtension) + it "should search banners" do + @banner = mock_model(Banner) + Banner.stub!(:search).and_return([@banner]) + Banner.should_receive(:search).with('radiant').and_return([@banner]) + do_get + end + end + it "should render the index template" do + do_get + response.should render_template('index') + end + it "should be successful" do + do_get + response.should be_success + end + end + end + + [:existing, :non_admin].each do |user| + describe "search as user with #{user} privileges" do + before :each do + @page, @snippet, @layout = mock_model(Page), mock_model(Snippet), mock_model(Layout) + Page.stub!(:search).and_return([@page]) + Snippet.stub!(:search).and_return([@snippet]) + Layout.stub!(:search).and_return([@layout]) + login_as user + end + + def do_get + get :index, :q => 'radiant' + end + + it "should search pages" do + Page.should_receive(:search).with('radiant').and_return([@page]) + do_get + end + it "should not search snippets" do + Snippet.should_not_receive(:search).with('radiant') + do_get + end + it "should not search layouts" do + Layout.should_not_receive(:search).with('radiant') + do_get + end + if defined?(TemplatesExtension) + it "should not search templates" do + @banner = mock_model(Template) + Template.stub!(:search).and_return([@template]) + Template.should_not_receive(:search).with('radiant') + do_get + end + end + if defined?(BannerRotatorExtension) + it "should not search banners" do + @banner = mock_model(Banner) + Banner.stub!(:search).and_return([@banner]) + Banner.should_not_receive(:search).with('radiant') + do_get + end + end + it "should render the index template" do + do_get + response.should render_template('index') + end + it "should be successful" do + do_get + response.should be_success + end + end + end + +end diff --git a/spec/controllers/searches_controller_spec.rb b/spec/controllers/searches_controller_spec.rb deleted file mode 100644 index 1a24a09..0000000 --- a/spec/controllers/searches_controller_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe SearchesController do - dataset :users - - before :each do - @snippet, @page = mock_model(Snippet), mock_model(Page) - Snippet.stub!(:search).and_return([@snippet]) - Page.stub!(:search).and_return([@page]) - login_as :existing - end - - describe "GET to /admin/searches" do - def do_get - get :index, :q => 'radiant' - end - - it "should search snippets" do - Snippet.should_receive(:search).with('radiant').and_return([@snippet]) - do_get - end - - it "should search pages" do - Page.should_receive(:search).with('radiant').and_return([@page]) - do_get - end - - it "should render the index template" do - do_get - response.should render_template('index') - end - - it "should be successful" do - do_get - response.should be_success - end - end -end diff --git a/spec/models/page_extensions_spec.rb b/spec/models/page_extensions_spec.rb index 47fa26e..406427b 100644 --- a/spec/models/page_extensions_spec.rb +++ b/spec/models/page_extensions_spec.rb @@ -4,6 +4,7 @@ dataset :pages before :each do + pages(:radius).update_attributes(:breadcrumb => "Wheat and Rye") if defined?(ConcurrentDraft) pages(:first).parts.first.update_attributes(:draft_content => "Special draft content") else @@ -12,25 +13,23 @@ end it "should find pages from words in the title" do - Page.search('radius').should include(pages(:radius)) + Page.search('wheat').should include(pages(:radius)) end - - it "should find pages from words in the keywords" do - Page.search('harmonious').should include(pages(:assorted)) - end - - it "should find pages from words in the description" do - Page.search('sweet').should include(pages(:assorted)) + it "should find pages from words in the breadcrumb" do + Page.search('f').should include(pages(:f)) end - + # it "should find pages from words in the keywords" do + # Page.search('harmonious').should include(pages(:assorted)) + # end + # it "should find pages from words in the description" do + # Page.search('sweet').should include(pages(:assorted)) + # end it "should find pages from words in the slug" do Page.search('article-4').should include(pages(:article_4)) end - it "should find pages from words in the parts content" do Page.search('world!').should include(pages(:home)) end - it "should find pages from words in the content" do Page.search('special').should include(pages(:first)) end