-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect2.sh
executable file
·100 lines (76 loc) · 2.95 KB
/
select2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
echo ~----------~----------Startingd $HOSTNAME, pwd: `pwd`, dlr0: "$0", bashsource0: "${BASH_SOURCE[0]}", $(date +"%Y-%m-%d_%H.%M.%S")
### enable select2 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gem1="gem 'select2-rails'"
echo "$gem1" >> Gemfile
bundle
#
# add line after match... sed -i '/CLIENTSCRIPT="foo"/a CLIENTSCRIPT2="hello"' file
# i think 0, means only do it for the first match..
#
pattern1='class' # changed because this is common to rails4 and rails5
line1=' has_many :product_feature\n has_many :pfeature, through: :product_feature\n'
file1='app/models/product.rb'
sed -i "0,/$pattern1/a $line1" $file1
#
# sleep 1
#
pattern1='class' # changed because this is common to rails4 and rails5
line1=' has_many :product_feature\n has_many :product, through: :product_feature\n'
file1='app/models/pfeature.rb'
sed -i "0,/$pattern1/a $line1" $file1
line1='<%= f.association :pfeature %>'
patrn='f.input :name'
sed -i "/.*$patrn.*/a $line1" app/views/products/_form.html.erb
# sleep 1
# add this.. :ptype_ids => [] ... Edit line to look like this.. params.require(:product).permit(:name, :ptype_ids => [])
# http://unix.stackexchange.com/questions/155331/sed-replace-a-character-in-a-matched-line-in-place /ipsum/{s/#//g;s/@/-at-/g;}
# add a space before the last character in the line... sed 's/.$/ &/' file
#
# find lines with $patrn and replace last characater with $str1)
patrn='params.require'
patrn='require'
str1=', :pfeature_ids=> []'
file1='app/controllers/products_controller.rb'
echo $patrn, $str1, $file1
sed -i "/$patrn/{s/.$/$str1\)/}" $file1
# rev $file1 | sed "s/)/ZaZ@Z/" | rev
sleep 1
# insert lines before line matching patrn...
ln1='<p>'
ln2='<% @product.pfeature.each do |v1| %>'
ln3=' <%= link_to v1.name, v1 %>'
ln4='<% end %>'
ln5='</p>'
patrn='edit_product_path'
sed -i "/.*$patrn.*/i $ln1\n$ln2\n$ln3\n$ln4\n$ln5\n" app/views/products/show.html.erb
sleep 1
mkdir -p app/inputs
cat << 'HEREDOC' > app/inputs/collection_select_input.rb
# app/inputs/collection_select_input.rb
class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
def input_html_classes
super.push('dgselect2')
end
end
HEREDOC
cat << 'HEREDOC' > app/assets/javascripts/dgselect2.js
//#app/assets/javascripts/dgselect2.js
$(function() {
$(".dgselect2").select2({
});
});
HEREDOC
echo '//= require select2' >> app/assets/javascripts/application.js
# this gave error.. echo '*= require select2'>> app/assets/stylesheets/application.scss
# echo '*= require select2-bootstrap'>> app/assets/stylesheets/application.scss
#
# insert lines after line matching patrn...
ln1='\ \ \*= require select2'
ln2=' \*= require select2-bootstrap'
# got error.. patrn='self'
# sed -i "/self/a "$ln1"\n"$ln2"\n" app/assets/stylesheets/application.scss
sed -i "/require_self/a $ln1\n$ln2" app/assets/stylesheets/application.scss
sleep 1
git add -A # Add all files and commit them
git commit -m "enable select2"