Skip to content

Instantly share code, notes, and snippets.

@nesquena
Forked from achiurizo/blog_template.rb
Created April 6, 2010 07:28
Show Gist options
  • Select an option

  • Save nesquena/357318 to your computer and use it in GitHub Desktop.

Select an option

Save nesquena/357318 to your computer and use it in GitHub Desktop.

Revisions

  1. nesquena revised this gist Apr 6, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion blog_template.rb
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@

    # generating posts controller
    generate :controller, "posts get:index get:show"
    gsub_file('app/controllers/posts.rb',/^\#\s+/,'')
    gsub_file('app/controllers/posts.rb', /^\s+\#\s+.*\n/,'')
    POST_INDEX_ROUTE = <<-POST
    @posts = Post.all(:order => 'created_at desc')
    render 'posts/index'
  2. @achiurizo achiurizo revised this gist Apr 6, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions blog_template.rb
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,7 @@

    # generating posts controller
    generate :controller, "posts get:index get:show"
    gsub_file('app/controllers/posts.rb',/^\#\s+/,'')
    POST_INDEX_ROUTE = <<-POST
    @posts = Post.all(:order => 'created_at desc')
    render 'posts/index'
  3. @achiurizo achiurizo revised this gist Apr 6, 2010. 1 changed file with 11 additions and 13 deletions.
    24 changes: 11 additions & 13 deletions blog_template.rb
    Original file line number Diff line number Diff line change
    @@ -22,20 +22,18 @@
    rake 'ar:migrate'

    # generating posts controller
    generate :controller, "posts"
    POST_CONTROLLER = <<-POST
    get :index do
    @posts = Post.all(:order => 'created_at desc')
    render 'posts/index'
    end
    get :show, :with => :id do
    @post = Post.find_by_id(params[:id])
    render 'posts/show'
    end
    generate :controller, "posts get:index get:show"
    POST_INDEX_ROUTE = <<-POST
    @posts = Post.all(:order => 'created_at desc')
    render 'posts/index'
    POST
    inject_into_file 'app/controllers/posts.rb', POST_CONTROLLER, :after => ":posts do\n"

    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"

  4. @achiurizo achiurizo created this gist Apr 6, 2010.
    139 changes: 139 additions & 0 deletions blog_template.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,139 @@
    project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord, :dev => true

    #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"
    POST_CONTROLLER = <<-POST
    get :index do
    @posts = Post.all(:order => 'created_at desc')
    render 'posts/index'
    end
    get :show, :with => :id do
    @post = Post.find_by_id(params[:id])
    render 'posts/show'
    end
    POST
    inject_into_file 'app/controllers/posts.rb', POST_CONTROLLER, :after => ":posts do\n"

    # 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'