radiant-find_replace-extension 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,20 +13,44 @@ class Admin::SearchController < ApplicationController
13
13
  srch = Regexp.new(qry, params[:case_insensitive])
14
14
 
15
15
  if class_name == 'page'
16
- [:slug, :title, :breadcrumb].each do |attr|
17
- to_replace.send("#{attr}=", to_replace.send(attr).gsub(srch, params[:replace]))
16
+ if params[:include_page_title_fields]
17
+ [:slug, :title, :breadcrumb].each do |attr|
18
+ to_replace.send("#{attr}=", to_replace.send(attr).gsub(srch, params[:replace]))
19
+ end
18
20
  end
19
21
  to_replace.parts.each do |page_part|
20
- page_part.content = page_part.content.gsub(srch, params[:replace])
21
- page_part.name = page_part.name.gsub(srch, params[:replace]) if params[:include_field_and_part_names]
22
+ if params[:include_page_part_contents]
23
+ page_part.content = page_part.content.gsub(srch, params[:replace])
24
+ end
25
+ if params[:include_page_part_names]
26
+ page_part.name = page_part.name.gsub(srch, params[:replace])
27
+ end
22
28
  end
23
29
  to_replace.fields.each do |field|
24
- field.content = field.content.gsub(srch, params[:replace])
25
- field.name = field.name.gsub(srch, params[:replace]) if params[:include_field_and_part_names]
30
+ if params[:include_page_field_contents]
31
+ field.content = field.content.gsub(srch, params[:replace])
32
+ end
33
+ if params[:include_page_field_names]
34
+ field.name = field.name.gsub(srch, params[:replace])
35
+ end
26
36
  end
27
- page.save
37
+ to_replace.save
38
+ elsif class_name == 'snippet'
39
+ if params[:include_snippet_contents]
40
+ to_replace.content = to_replace.content.gsub(srch, params[:replace])
41
+ end
42
+ if params[:include_snippet_names]
43
+ to_replace.name = to_replace.name.gsub(srch, params[:replace])
44
+ end
45
+ to_replace.save
28
46
  else
29
- to_replace.update_attribute :content, to_replace.content.gsub(srch, params[:replace])
47
+ if params[:include_layout_contents]
48
+ to_replace.content = to_replace.content.gsub(srch, params[:replace])
49
+ end
50
+ if params[:include_layout_names]
51
+ to_replace.name = to_replace.name.gsub(srch, params[:replace])
52
+ end
53
+ to_replace.save
30
54
  end
31
55
  end
32
56
  end
@@ -50,14 +74,38 @@ class Admin::SearchController < ApplicationController
50
74
  pages_with_matching_slug = Page.find(:all, :conditions => ["slug #{like} ?", match])
51
75
 
52
76
  includes = [ :parts, :fields ]
53
- cols = %w(page_parts.content pages.slug pages.breadcrumb pages.title page_fields.content)
54
- cols+= %w(page_fields.name page_parts.name) if params[:include_field_and_part_names]
77
+ cols = []
78
+ cols += %w(pages.slug pages.breadcrumb pages.title) if params[:include_page_title_fields]
79
+ cols << "page_parts.content" if params[:include_page_part_contents]
80
+ cols << "page_parts.name" if params[:include_page_part_names]
81
+ cols << "page_fields.content" if params[:include_page_field_contents]
82
+ cols << "page_fields.name" if params[:include_page_field_names]
83
+
55
84
  # Is not [page, ...] but [[page, boolean], ...] to mark dangerous matches
56
85
  conditions = cols.map{|c| "#{c} #{like} ?"}.join(' OR ')
57
- @page_results = Page.find(:all, :include => includes, :conditions => [conditions, [match]* cols.size].flatten).map{|page| [page, pages_with_matching_slug.include?(page)]}
86
+ @page_results = if cols.size > 0
87
+ Page.find(:all, :include => includes, :conditions => [conditions, [match]* cols.size].flatten).map{|page| [page, pages_with_matching_slug.include?(page)]}
88
+ else
89
+ []
90
+ end
91
+
92
+ snippet_cols = []
93
+ snippet_cols << "content" if params[:include_snippet_contents]
94
+ snippet_cols << "name" if params[:include_snippet_names]
95
+ @snippet_results = if snippet_cols.size > 0
96
+ Snippet.find(:all, :conditions => [snippet_cols.map{|c| "#{c} #{like} ?"}.join(' OR '), [match]*snippet_cols.size])
97
+ else
98
+ []
99
+ end
58
100
 
59
- @snippet_results = Snippet.find(:all, :conditions => ["content #{like} ?", match])
60
- @layout_results = Layout.find(:all, :conditions => ["content #{like} ?", match])
101
+ layout_cols = []
102
+ layout_cols << "content" if params[:include_layout_contents]
103
+ layout_cols << "name" if params[:include_layout_names]
104
+ @layout_results = if layout_cols.size > 0
105
+ Layout.find(:all, :conditions => [layout_cols.map{|c| "#{c} #{like} ?"}.join(' OR '), [match]*layout_cols.size])
106
+ else
107
+ []
108
+ end
61
109
  end
62
110
 
63
111
  end
@@ -1,21 +1,21 @@
1
1
  - @page_title = 'Search'
2
-
2
+ - include_stylesheet 'admin/find_replace'
3
3
  .outset
4
- %form
4
+ %form#find_replace_form
5
5
  - if params[:query]
6
- %table.index#results{:summary=>"Results", :style => "margin-bottom: 60px"}
6
+ %table.index#results{:summary=>"Results"}
7
7
  %thead
8
8
  %tr
9
- %th{:style => "width: 2.5em"}
9
+ %th
10
10
  %input{:type => 'checkbox', :id => 'toggler', :onclick => "toggle_cbs()"}
11
11
  %th.identifier Search result
12
12
  %tbody
13
13
  - if @page_results.select{|page, bool| bool}.any?
14
- %tr
14
+ %tr.warning
15
15
  %td{:colspan => 2}
16
- %em{:style => "font-weight: bold"} Warning:
16
+ %em Warning:
17
17
  pages marked with an
18
- %span{:style => "color: red; font-weight: bold"} !
18
+ %span !
19
19
  have a match in their slug. Replacing these matches will change the URL of the page, and consequently those of all children it may have (irrespective of whether they themselves match the search term or not).
20
20
  - @page_results.each do |page, slug_matches|
21
21
  %tr
@@ -56,36 +56,76 @@
56
56
  = params[:query]
57
57
  \.
58
58
 
59
- #actions{:style => "color: #eee"}
60
- %ul
61
- %li
62
- Find:
63
- %input{:type => 'text', :name => 'query', :value => params[:query]}
64
- %li
65
- Replace:
66
- %input{:type => 'text', :name => 'replace', :value => params[:replace]}
67
- %li
68
- %input{:type => 'checkbox', :name => 'regex_mode', :checked => params[:regex_mode] }
69
- Use regular expressions
70
- %li
71
- %input{:type => 'checkbox', :name => 'case_insensitive', :checked => params[:case_insensitive] }
72
- Ignore case
73
- %li
74
- %input{:type => 'checkbox', :name => 'include_field_and_part_names', :checked => params[:include_field_and_part_names] }
75
- Also search page field- and part-names
76
- %li
77
- %input{:type => :submit, :class => 'action_button', :value => 'Find all'}
78
- - if params[:query]
59
+ %footer
60
+ .left
61
+ %ul
62
+ %li.find
63
+ %label
64
+ Find:
65
+ %input{:type => 'text', :name => 'query', :value => params[:query]}
66
+ %li.replace
67
+ %label
68
+ Replace:
69
+ %input{:type => 'text', :name => 'replace', :value => params[:replace]}
70
+ %li
71
+ %label
72
+ %input{:type => 'checkbox', :name => 'regex_mode', :checked => params[:regex_mode] }
73
+ Use
74
+ %a{:href => "http://rubular.com/"} regular expressions
75
+
76
+ %label
77
+ %input{:type => 'checkbox', :name => 'case_insensitive', :checked => params[:case_insensitive] }
78
+ Ignore case
79
+ %li
80
+ %input{:type => :submit, :class => 'action_button', :value => 'Find all'}
81
+ - if params[:query]
82
+ = submit_tag 'Replace selected', {:class => 'action_button', :name => 'doReplace', :confirm => "Are you sure you want to replace all instances of '#{params[:query]}#{params[:replace] ? '\' with \'' + params[:replace]: ''}' in all of the selected Pages, Snippets and Layouts? This can not be reverted!"}
83
+ .right
84
+ %ul
79
85
  %li
80
- = submit_tag 'Replace selected', {:class => 'action_button', :name => 'doReplace', :confirm => "Are you sure you want to replace all instances of '#{params[:query]}#{params[:replace] ? '\' with \'' + params[:replace]: ''}' in all of the selected Pages, Snippets and Layouts? This can not be reverted!"}
81
- / %input{:type => :submit}
86
+ Page
87
+ %label
88
+ %input{:type => 'checkbox', :name => 'include_page_title_fields', :checked => params[:include_page_title_fields] || !params[:query] }
89
+ title, slug and breadcrumb
90
+ %br
91
+ Page part
92
+ %label
93
+ %input{:type => 'checkbox', :name => 'include_page_part_names', :checked => params[:include_page_part_names] }
94
+ names
95
+ %label
96
+ %input{:type => 'checkbox', :name => 'include_page_part_contents', :checked => params[:include_page_part_contents] || !params[:query] }
97
+ contents
98
+ %br
99
+ Page field
100
+ %label
101
+ %input{:type => 'checkbox', :name => 'include_page_field_names', :checked => params[:include_page_field_names] }
102
+ names
103
+ %label
104
+ %input{:type => 'checkbox', :name => 'include_page_field_contents', :checked => params[:include_page_field_contents] || !params[:query] }
105
+ contents
106
+ %br
107
+ Layout
108
+ %label
109
+ %input{:type => 'checkbox', :name => 'include_layout_names', :checked => params[:include_layout_names] }
110
+ names
111
+ %label
112
+ %input{:type => 'checkbox', :name => 'include_layout_contents', :checked => params[:include_layout_contents] || !params[:query] }
113
+ contents
114
+ %br
115
+ Snippet
116
+ %label
117
+ %input{:type => 'checkbox', :name => 'include_snippet_names', :checked => params[:include_snippet_names] }
118
+ names
119
+ %label
120
+ %input{:type => 'checkbox', :name => 'include_snippet_contents', :checked => params[:include_snippet_contents] || !params[:query] }
121
+ contents
82
122
 
83
123
  :javascript
84
124
  function toggle_cbs() {
85
125
  if($("toggler").checked){
86
- $$('input[type="checkbox"]').slice(1,-2).each(function(e){ e.checked = 1 });
126
+ $$('td input[type="checkbox"]').each(function(e){ e.checked = 1 });
87
127
  }
88
128
  else{
89
- $$('input[type="checkbox"]').slice(1,-2).each(function(e){ e.checked = 0 });
129
+ $$('td input[type="checkbox"]').each(function(e){ e.checked = 0 });
90
130
  }
91
131
  }
@@ -1,5 +1,5 @@
1
1
  module RadiantFindReplaceExtension
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  SUMMARY = "Find Replace for Radiant CMS"
4
4
  DESCRIPTION = "Adds backend search and replace functionality to Radiant CMS!"
5
5
  URL = "https://github.com/jomz/radiant-find_replace-extension"
@@ -0,0 +1,37 @@
1
+ #find_replace_form
2
+ table.index
3
+ margin-bottom: 90px
4
+ th:nth-child(1)
5
+ width: 2.5em
6
+ tr.warning
7
+ em
8
+ font-weight: bold
9
+ span
10
+ color: red
11
+ font-weight: bold
12
+ footer
13
+ display: flex
14
+ position: fixed
15
+ left: 0
16
+ right: 0
17
+ bottom: 0
18
+ background: #777777
19
+ background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #555555), color-stop(33.333%, #666666), color-stop(66.667%, #777777), color-stop(100%, #777777))
20
+ background-image: -webkit-linear-gradient(top, #555555, #666666, #777777, #777777)
21
+ background-image: -moz-linear-gradient(top, #555555, #666666, #777777, #777777)
22
+ background-image: -o-linear-gradient(top, #555555, #666666, #777777, #777777)
23
+ background-image: -ms-linear-gradient(top, #555555, #666666, #777777, #777777)
24
+ background-image: linear-gradient(top, #555555, #666666, #777777, #777777)
25
+ color: #eee
26
+ .left, .right
27
+ flex: 1
28
+ padding: 0.5em
29
+ li.find, li.replace
30
+ label
31
+ display: flex
32
+ margin-bottom: 0.2em
33
+ input
34
+ flex: auto
35
+ label
36
+ a
37
+ color: #eee
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-find_replace-extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-23 00:00:00.000000000 Z
12
+ date: 2017-11-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Adds backend search and replace functionality to Radiant CMS!
15
15
  email:
@@ -29,10 +29,12 @@ files:
29
29
  - find_replace_extension.rb
30
30
  - lib/radiant-find_replace-extension.rb
31
31
  - lib/tasks/find_replace_extension_tasks.rake
32
+ - public/stylesheets/sass/admin/find_replace.sass
32
33
  - radiant-find_replace-extension-1.0.0.gem
33
34
  - radiant-find_replace-extension-1.0.1.gem
34
35
  - radiant-find_replace-extension-1.0.2.gem
35
36
  - radiant-find_replace-extension-1.0.3.gem
37
+ - radiant-find_replace-extension-1.0.4.gem
36
38
  - radiant-find_replace-extension.gemspec
37
39
  - Rakefile
38
40
  - README.md