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
|
# File 'lib/railsbricks/post_builder.rb', line 10
def self.build_post(app_dir, options)
new_line(2)
wputs "----> Generating Post resources ...", :info
rbricks_dir = File.dirname(__FILE__)
add_string = ""
FileUtils.cp_r(rbricks_dir + "/assets/migrations/20141010133702_create_posts.rb", app_dir + "/db/migrate")
wputs "--> Migration created."
FileUtils.cp_r(rbricks_dir + "/assets/lib/markdown_writer.rb", app_dir + "/lib")
wputs "--> MarkdownWriter helper created."
FileHelpers.replace_string(/BRICK_POST_ROUTES/, FileHelpers.get_file(:brick_post_routes), app_dir + "/config/routes.rb")
FileHelpers.replace_string(/BRICK_ADMIN_POST_ROUTES/, FileHelpers.get_file(:brick_admin_post_routes), app_dir + "/config/routes.rb")
wputs "--> Routes updated."
FileUtils.cp_r(rbricks_dir + "/assets/views/pages/posts.html.erb", app_dir + "/app/views/pages")
FileUtils.cp_r(rbricks_dir + "/assets/views/pages/show_post.html.erb", app_dir + "/app/views/pages")
wputs "--> Views created."
FileHelpers.replace_string(/BRICK_POSTS_CONTROLLER/, FileHelpers.get_file(:brick_posts_controller), app_dir + "/app/controllers/pages_controller.rb")
wputs "--> Pages controller updated."
FileHelpers.replace_string(/BRICK_POSTS/, '<li><%= link_to "Posts", posts_path %></li>', app_dir + "/app/views/layouts/_navigation_links.html.erb")
wputs "--> Navigation links updated."
FileHelpers.replace_string(/BRICK_POST_COUNT/, '@post_count = Post.count', app_dir + "/app/controllers/admin/base_controller.rb")
wputs "--> Base controller updated."
FileHelpers.replace_string(/BRICK_POSTS_LINK/, FileHelpers.get_file(:brick_admin_posts_link), app_dir + "/app/views/admin/base/index.html.erb")
wputs "--> Admin view updated."
FileUtils.cp_r(rbricks_dir + "/assets/controllers/admin/posts_controller.rb", app_dir + "/app/controllers/admin")
wputs "--> Admin posts controller created."
FileUtils.mkdir_p(app_dir + "/app/views/admin/posts")
FileUtils.cp_r(rbricks_dir + "/assets/views/admin/posts/.", app_dir + "/app/views/admin/posts")
wputs "--> Admin posts views created."
FileHelpers.replace_string(/BRICK_POSTS_RELATION/, "\n# Relations\nhas_many :posts\n", app_dir + "/app/models/user.rb")
FileUtils.cp_r(rbricks_dir + "/assets/models/post.rb", app_dir + "/app/models")
wputs "--> Models created and updated."
new_line
wputs "----> Post resources generated.", :info
rescue
Errors.display_error("Something went wrong and the post resources couldn't be generated. Stopping app creation.", true)
abort
end
|