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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/generators/rtrain/install_generator.rb', line 28
def run_rtrain
dir = File.dirname(__FILE__)
if options[:copy_css]
scaffold_css = "../templates/rtrain_scaffold.scss"
new_css_path = File.join(dir, scaffold_css)
new_css = open(new_css_path).read
old_css = open("app/assets/stylesheets/scaffolds.scss", "w")
old_css.write(new_css)
old_css.close
puts "
----------------------------------------------------
Rtrain Scaffold CSS now active in app/assets/stylesheets/
----------------------------------------------------
"
end
if options[:add_nav]
puts 'nav'
old_applayout = open("app/views/layouts/application.html.erb").read
app_name = old_applayout.split("<title>")[1].split("</title>")[0]
app_name = "\n<h1>"+app_name+"</h1>\n"
tables = ActiveRecord::Base.connection.tables[1..-1]
list_items = []
tables.each do |t|
link = "<li><%=link_to '" + t.titleize + "'," + t + "_path%></li>"
list_items.push(link)
end
nav = "\n<div id=\"main-navbar\">\n\t<ul id=\"menu\">\n\t\t" + list_items.join("\n\t\t") + "\n\t</ul>\n</div>\t\n\n\n"
new_layout = old_applayout.split("<body>")
old_applayout = open("app/views/layouts/application.html.erb", "w")
old_applayout.write(new_layout[0] + "<body>" + app_name + nav + new_layout[1])
old_applayout.close
nav_css = "../templates/nav-bar.scss"
nav_css_path = File.join(dir, nav_css)
stylesheets = "app/assets/stylesheets/"
FileUtils.cp(nav_css_path, stylesheets)
puts "
----------------------------------------------------
Rtrain Nav Bar and App Title now active in app/views/layouts/application.html.erb\n
IMPORTANT! If re-running this command, be sure to remove the HTML for the previous nav bar
as it will be duplicated within the text of app/views/layouts/application.html.erb.
----------------------------------------------------
"
end
if options[:add_homepage]
FileUtils.mkdir("app/views/main/")
home_page = "../templates/home.html.erb"
home_page_path = File.join(dir, home_page)
main_view_dir = "app/views/main/"
FileUtils.cp(home_page_path, main_view_dir)
main = "../controllers/main_controller.rb"
main_path = File.join(dir, main)
controllers = "app/controllers"
FileUtils.cp(main_path, controllers)
root = open("config/routes.rb").read
root ["# root 'welcome#index'"] = "root 'main#show', page: 'home'
get '/main/:page' => 'pages#show'"
routes = open("config/routes.rb","w")
routes.write(root)
routes.close
puts "
----------------------------------------------------
Rtrain Homepage Now Active and set as root URL
----------------------------------------------------
"
end
end
|