Skip to content

Instantly share code, notes, and snippets.

@DouglasAllen
Forked from achiurizo/blog_template.rb
Created January 26, 2016 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DouglasAllen/44d3191c5ebf9118c1a9 to your computer and use it in GitHub Desktop.
Save DouglasAllen/44d3191c5ebf9118c1a9 to your computer and use it in GitHub Desktop.
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, :after => "#\n end\n"
#generating padrino admin
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 'app/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', ", :respond_to => [: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 'http://github.com/padrino/sample_blog/raw/master/public/stylesheets/reset.css', 'public/stylesheets/reset.css'
get "http://github.com/padrino/sample_blog/raw/master/app/stylesheets/application.sass", 'app/stylesheets/application.sass'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment