-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsampleblog_template.rb
142 lines (125 loc) · 4.79 KB
/
sampleblog_template.rb
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Template for Sample Blog tutorial at http://www.padrinorb.com/guides/blog-tutorial
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord
# Default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"
end
APP
inject_into_file 'app/app.rb', APP_INIT, :before => "#\n end\n"
# Generating padrino admin
inject_into_file 'Gemfile', "gem 'bcrypt-ruby', :require => 'bcrypt'\n", :after => "# Component requirements\n"
run_bundler
generate :admin
rake "ar:create ar:migrate seed"
# appending timestamps to post model
generate :model, "post title:string body:text"
inject_into_file 'db/migrate/002_create_posts.rb'," t.timestamps\n",:after => "t.text :body\n"
rake 'ar:migrate'
# Generating posts controller
generate :controller, "posts get:index get:show"
gsub_file('app/controllers/posts.rb', /^\s+\#\s+.*\n/,'')
POST_INDEX_ROUTE = <<-POST
@posts = Post.all(:order => 'created_at desc')
render 'posts/index'
POST
POST_SHOW_ROUTE = <<-POST
@post = Post.find_by_id(params[:id])
render 'posts/show'
POST
inject_into_file 'app/controllers/posts.rb', POST_INDEX_ROUTE, :after => "get :index do\n"
inject_into_file 'app/controllers/posts.rb', POST_SHOW_ROUTE, :after => "get :show do\n"
inject_into_file 'app/controllers/posts.rb', ", :with => :id", :after => "get :show" # doesn't run?
# Generate admin_page for post
generate :admin_page, "post"
# Migrations to add account to post
generate :migration, "AddAccountToPost account_id:integer"
# Update Post Model with Validations and Associations
POST_MODEL = <<-POST
belongs_to :account
validates_presence_of :title
validates_presence_of :body
POST
inject_into_file 'models/post.rb', POST_MODEL, :after => "ActiveRecord::Base\n"
rake 'ar:migrate'
# Update admin app controller for post
inject_into_file 'admin/controllers/posts.rb'," @post.account = current_account\n",:after => "new(params[:post])\n"
# Include RSS Feed
inject_into_file 'app/controllers/posts.rb', ", :provides => [:html, :rss, :atom]", :after => "get :index"
# Create index.haml
POST_INDEX = <<-POST
- @title = "Welcome"
- content_for :include do
= feed_tag(:rss, url(:posts, :index, :format => :rss),:title => "RSS")
= feed_tag(:atom, url(:posts, :index, :format => :atom),:title => "ATOM")
#posts= partial 'posts/post', :collection => @posts
POST
create_file 'app/views/posts/index.haml', POST_INDEX
# Create _post.haml
POST_PARTIAL = <<-POST
.post
.title= link_to post.title, url_for(:posts, :show, :id => post)
.date= time_ago_in_words(post.created_at || Time.now) + ' ago'
.body= simple_format(post.body)
.details
.author Posted by \#{post.account.email}
POST
create_file 'app/views/posts/_post.haml', POST_PARTIAL
# Create show.haml
POST_SHOW = <<-POST
- @title = @post.title
#show
.post
.title= @post.title
.date= time_ago_in_words(@post.created_at || Time.now) + ' ago'
.body= simple_format(@post.body)
.details
.author Posted by \#{@post.account.email}
%p= link_to 'View all posts', url_for(:posts, :index)
POST
create_file 'app/views/posts/show.haml', POST_SHOW
APPLICATION = <<-LAYOUT
!!! Strict
%html
%head
%title= [@title, "Padrino Sample Blog"].compact.join(" | ")
= stylesheet_link_tag 'reset', 'application'
= javascript_include_tag 'jquery', 'application'
= yield_content :include
%body
#header
%h1 Sample Padrino Blog
%ul.menu
%li= link_to 'Blog', url_for(:posts, :index)
%li= link_to 'About', url_for(:about)
#container
#main= yield
#sidebar
= form_tag url_for(:posts, :index), :method => 'get' do
Search for:
= text_field_tag 'query', :value => params[:query]
= submit_tag 'Search'
%p Recent Posts
%ul.bulleted
%li Item 1 - Lorem ipsum dolorum itsum estem
%li Item 2 - Lorem ipsum dolorum itsum estem
%li Item 3 - Lorem ipsum dolorum itsum estem
%p Categories
%ul.bulleted
%li Item 1 - Lorem ipsum dolorum itsum estem
%li Item 2 - Lorem ipsum dolorum itsum estem
%li Item 3 - Lorem ipsum dolorum itsum estem
%p Latest Comments
%ul.bulleted
%li Item 1 - Lorem ipsum dolorum itsum estem
%li Item 2 - Lorem ipsum dolorum itsum estem
%li Item 3 - Lorem ipsum dolorum itsum estem
#footer
Copyright (c) 2009-2010 Padrino
LAYOUT
create_file 'app/views/layouts/application.haml', APPLICATION
get 'https://github.com/padrino/sample_blog/raw/master/public/stylesheets/reset.css', 'public/stylesheets/reset.css'
get "https://github.com/padrino/sample_blog/raw/master/app/stylesheets/application.sass", 'app/stylesheets/application.sass'