Changeset 1343 for mrblog/trunk

Show
Ignore:
Timestamp:
02/04/08 07:36:54 (10 months ago)
Author:
jon.egil.stra..@gmail.com
Message:

Shaving and tightening - still a long way to go

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mrblog/trunk/app/controllers/account.rb

    r1203 r1343  
    66 
    77  def login 
     8    redirect '/account/signup' if User.count == 0 
    89    render if @method != :post 
    910    self.current_user = User.authenticate(params[:login], params[:password]) 
    1011    if current_user 
    11       redirect_back_or_default('/') 
     12      redirect('/admin') 
    1213    end 
    1314    render 
  • mrblog/trunk/app/controllers/admin.rb

    r1203 r1343  
    44     
    55  def index 
    6     posts_or_pages :posts 
    7   end 
    8    
    9   def pages 
    10     posts_or_pages :pages 
    11   end 
    12    
    13   def posts_or_pages type = :posts 
    14     @type = type.to_s.capitalize 
    15     @pager = ::Paginator.new(Post.count(:conditions=>"page = '#{type==:pages}'"), MrBlog::PER_PAGE) do |offset, per_page| 
    16             Post.get(:all, type, :limit => per_page, :offset => offset, :order => 'created_at DESC') 
     6    @pager = ::Paginator.new(Post.count, MrBlog::PER_PAGE) do |offset, per_page| 
     7            Post.get(:all, :limit => per_page, :offset => offset, :order => 'created_at DESC') 
    178          end 
    189          @page = @pager.page(params[:page]) 
     
    2112   
    2213  def create 
    23     @post = Post.create(params[:post].merge(:page => params[:type] == "pages")) 
     14    @post = Post.create(params[:post].merge(:user => current_user)) 
    2415    redirect "/admin/show/#{@post.id}" 
    2516  end 
     
    3627  def show 
    3728    @post = Post.find params[:id] 
     29    @comments = @post.comments 
    3830    render 
    3931  end 
     
    4537   
    4638  def edit 
    47     @post = Post.find params[:id] 
     39    @post = Post.find(params[:id]) 
    4840    render 
    4941  end 
    5042 
    5143  def delete 
    52     Post.find(params[:id]).destroy 
     44    p = Post.find(params[:id]) 
     45    p.comments.each{|c| c.destroy} 
     46    p.destroy 
    5347    redirect "/admin" 
    5448  end   
    5549 
     50  def delete_comment 
     51    Comment.find(params[:id]).destroy  
     52    redirect "/admin" 
     53  end 
    5654end  
  • mrblog/trunk/app/controllers/blog.rb

    r1315 r1343  
    1212 
    1313  def index 
    14     posts_or_pages :posts 
    15   end 
    16    
    17   def pages 
    18     posts_or_pages :pages 
    19   end 
    20    
    21   def posts_or_pages(type = :posts) 
    22     @pager = ::Paginator.new(Post.count(:conditions=>"page = '#{type==:pages}'"), MrBlog::PER_PAGE) do |offset, per_page| 
     14    @pager = ::Paginator.new(Post.count, MrBlog::PER_PAGE) do |offset, per_page| 
    2315      Post.find(:all, :limit => per_page, :offset => offset) 
    2416          end 
     
    2820   
    2921  def add_comment 
    30     puts params.inspect 
    3122    @post = Post.find params[:post_id] 
    3223    @post.comments.create(:name => params[:comment_name], 
    33                           :body => params[:comment_body]) 
     24                          :text => params[:comment_text]) 
    3425    @comments = @post.comments.reload 
    3526    render_js 'comments' 
  • mrblog/trunk/app/models/post.rb

    r1203 r1343  
    11class Post < ActiveRecord::Base   
     2  belongs_to :user 
    23  has_many :comments 
    34 
    4   def self.get how_many = :all, post_or_page = :posts, options = {} 
    5     find(how_many, options.merge({:conditions => ["page = ?", !!(post_or_page.to_s =~ /page/)]})
     5  def self.get(how_many = :all, options = {}) 
     6    find(how_many, options
    67  end 
    78   
    89  def self.count_posts 
    9     self.count(:conditions => ["page = ?", false]) 
    10   end 
    11    
    12   def self.count_pages 
    13     self.count(:conditions => ["page = ?", true]) 
     10    self.count 
    1411  end 
    1512   
  • mrblog/trunk/app/models/user.rb

    r1306 r1343  
    11require 'digest/sha1' 
    22class User < ActiveRecord::Base 
     3  has_many :posts 
    34 
    45  # Virtual attribute for the unencrypted password 
  • mrblog/trunk/app/views/admin/_form.html.erb

    r1203 r1343  
    11<p> 
    2   <label for="post_title">Title</label> 
    3   <%= control_for @post, :title, :text, :id => 'foo', :size => 53 %> 
     2  <p> 
     3    <%= text_control :title, :label => 'Title', :cols => 50 %> 
     4  </p> 
     5  <p> 
     6    <%= text_area_control :text,  :label => 'Text', :rows => 20, :cols => 50 %> 
     7  </p> 
     8  <p class='button'> 
     9    <%= link_to(image_tag('cancel.gif'),  
     10                if params[:action] == 'edit'  
     11                  "/admin/show/#{@post.id}"  
     12                else  
     13                  "/admin"  
     14                end,  
     15                :class => "button") %> 
     16    <%= submit_button(image_tag('save.gif')) %>     
     17  </p> 
    418</p> 
    5  
    6 <p> 
    7   <label for="post_intro">Intro</label> 
    8   <%= control_for @post, :intro, :textarea, :class => 'post_intro',  
    9                                                 :rows => 10, :cols => 50 %> 
    10 </p> 
    11  
    12 <p> 
    13   <label for="post_body">Body</label> 
    14   <%= control_for @post, :body, :textarea, :class => 'post_body',  
    15                                                :rows => 20, :cols => 50 %> 
    16 </p> 
    17  
    18 <p class="buttons"> 
    19   <%= link_to image_tag('cancel.gif'), (params[:action] == 'edit') ? "/admin/show/#{@post.id}" : "/admin", :class => "button" %> 
    20   <button type="submit" name="Submit" value="Submit"><img src="/images/save.gif" /></button> 
    21 </p> 
  • mrblog/trunk/app/views/admin/edit.html.erb

    r1203 r1343  
    1 <h2>Editing Article</h2> 
     1<h2>Edit post</h2> 
    22 
    3 <form action="/admin/update" method="post"> 
    4 <%= partial :form %> 
    5   <input type='hidden' name="post[id]" value="<%= @post.id %>"> 
    6 </form> 
     3<% form_for :post, :action => url(:controller => "admin",  
     4                                  :action => "update",  
     5                                  :id => @post.id) do %> 
     6  <%= partial :form %> 
     7<% end %> 
  • mrblog/trunk/app/views/admin/index.html.erb

    r1203 r1343  
    1 <h3><%= @type %></h3> 
     1<h3>Post</h3> 
    22<hr /> 
    33<div> 
     
    1010  <span></span> 
    1111  <% end %> 
    12   <%= "<h2>No #{@type} yet</h2>" if @page.items.blank? %> 
     12  <%= "<h2>No posts yet</h2>" if @page.items.blank? %> 
    1313</div> 
    1414<br /> 
    1515<p><%= link_to("Prev", "?page=#{@page.prev.number}") if @page.prev? %> 
    1616<%= link_to("Next", "?page=#{@page.next.number}") if @page.next? %></p> 
    17 <%= link_to image_tag('new.gif'), "/admin/new?type=#{@type.downcase}", :class => "button" %>  
     17<%= link_to image_tag('new.gif'), "/admin/new", :class => "button" %>  
  • mrblog/trunk/app/views/admin/new.html.erb

    r1203 r1343  
    1 <h2>Create new <%= params[:type].singularize %></h2> 
     1<h2>Create new post</h2> 
    22 
    3 <form action="/admin/create?type=<%= params[:type].downcase %>" method="post"
    4 <%= partial :form %> 
    5 </form
     3<% form_for :post, :action => url(:controller => "admin", :action => "create") do %
     4  <%= partial :form %> 
     5<% end %
  • mrblog/trunk/app/views/admin/show.html.erb

    r1203 r1343  
    33<h2><%= @post.title %></h2> 
    44<div class="maintext"> 
    5 <%= @post.intro %> 
    6 <%= @post.body %>        
     5<%= @post.text%>         
    76</div> 
     7<% @comments.each do |c| %> 
     8  <div> 
     9    <p> 
     10      <b><%= c.name %></b>, on <%= c.created_at.strftime("%B %d, %Y") %> said: <br /> 
     11      <%= c.text %> <br /> 
     12      <%= link_to(image_tag('cross.png'),  
     13                  "/admin/delete_comment/#{c.id}",  
     14                  :class => "button") %> 
     15    </p> 
     16  </div> 
     17<% end %> 
     18 
    819 
    920<%= link_to image_tag('edit.gif'), "/admin/edit/#{@post.id}", :class => "button" %> 
  • mrblog/trunk/app/views/blog/_comments.html.erb

    r1305 r1343  
    11<% @comments.each do |c| %> 
    2   <div id="<%= c.id %>"
    3     <p><%= c.name %>: <%= c.body %></p> 
     2  <div id='<%= c.id %>'
     3    <p><%= c.name %>: <%= c.text %></p> 
    44  </div> 
    55<% end %> 
  • mrblog/trunk/app/views/blog/index.html.erb

    r1203 r1343  
    55  <% @page.items.each do |p| %> 
    66  <h2><%= link_to p.title, "/blog/show/#{p.id}" %></h2> 
    7   <span><%= truncate p.body, 300 %></span> 
     7  <span><%= truncate p.text, 300 %></span> 
    88  <% end %> 
    99  <%= "<h2>No articles yet</h2>" if @page.items.blank? %>   
  • mrblog/trunk/app/views/blog/show.html.erb

    r1203 r1343  
    11<h1><%= @post.title %></h1> 
    2 <div><%= @post.body %></div> 
     2<div><%= @post.text%></div> 
    33<hr />   
    44<p>Comments:<%= " None yet" if @comments.empty? %></p> 
     
    2020    </p> 
    2121    <p> 
    22       <label for="comment_body">Comment</label> 
    23       <textarea cols="20" id="post_body" name="comment_body" rows="8"></textarea> 
     22      <label for="comment_text">Comment</label> 
     23      <textarea cols="20" id="comment_text" name="comment_text" rows="8"></textarea> 
    2424    </p> 
    2525 
  • mrblog/trunk/app/views/layout/admin.html.erb

    r1294 r1343  
    1111 
    1212    <div id="blogtitle"> 
    13          <div id="small">Welcome to Merbivore | 
    14            <a href="http://svn.devjavu.com/merb">SVN</a> | 
    15            <a href="http://svn.devjavu.com/merb/trunk/README">README</a> | 
    16            <a href="http://merb.devjavu.com/">Trac</a> | 
     13         <div id="small">Welcome to Merb | 
     14       <a href="http://www.merbivore.com">merbivore.com</a> | 
     15             <a href="http://merb.devjavu.com">Trac</a> | 
     16             <a href="http://svn.devjavu.com/merb/trunk/README">README</a> | 
     17           <%= link_to "Blog", "/" %> | 
    1718           <%= link_to "Login", "/account/login" if !logged_in? %> 
    18            <%= link_to "Logout #{current_user.login}", "/account/login" if logged_in? %> | 
    19            <%= link_to "Blog", "/" %> 
     19           <%= link_to "Logout #{current_user.login}", "/account/login" if logged_in? %>  
    2020          </div> 
    2121    </div> 
     
    2626            <div id="topmenu"> 
    2727            <ul> 
    28               <li><a href="/admin"><span>Articles</span></a></li> 
    29               <li><a href="/admin/pages"><span>Pages</span></a></li> 
    30               <li><a href="/admin/files"><span>Manage Files</span></a></li> 
    31                 <li><a href="/admin/settings"><span>Settings</span></a></li> 
     28              <li><a href="/admin"><span>Posts</span></a></li> 
     29              <li><a href="/files"><span>Files</span></a></li> 
    3230                <li><a href="/admin/users"><span>Users</span></a></li> 
    3331              </ul> 
  • mrblog/trunk/app/views/layout/application.html.erb

    r1294 r1343  
    1313 
    1414  <div id="blogtitle"> 
    15          <div id="small">Welcome to Merbivore | 
    16            <a href="http://svn.devjavu.com/merb">SVN</a> | 
    17            <a href="http://svn.devjavu.com/merb/trunk/README">README</a> | 
    18            <a href="http://merb.devjavu.com/">Trac</a> 
     15         <div id="small">Welcome to Merb | 
     16     <a href="http://www.merbivore.com">merbivore.com</a> | 
     17           <a href="http://merb.devjavu.com">Trac</a> | 
     18           <a href="http://svn.devjavu.com/merb/trunk/README">README</a>  
     19           <%= " | #{link_to "Blog", "/"}" if !logged_in? && controller.class != Blog || params[:action] != "index" %>      
     20           <%= " | #{link_to "Admin", "/admin"}" if current_user && current_user.admin? %> 
    1921           <%= " | #{link_to "Login", "/account/login"}" if !logged_in? %> 
    20            <%= " | #{link_to "Blog", "/"}" if !logged_in? && controller.class != Blog || params[:action] != "index" %>      
    2122           <%= " | #{link_to "Logout #{current_user.login}", "/account/login"}" if logged_in? %> 
    22            <%= " | #{link_to "Admin", "/admin"}" if current_user && current_user.admin? %> 
    2323   </div> 
    2424  </div> 
    2525 
    26 <div id="border"> 
    27   <div id="container"> 
    28     <div id="content"> 
    29       <div id="introduction"> 
    30         <h3>Merb Mascot</h3> 
    31         <ul> 
    32           <li><%= link_to image_tag('louiecon.gif', :alt => 'Big Louie, the Merb mascot'), "/" %></li> 
    33         </ul> 
    34         <%= catch_content :sidebar %> 
    35       </div> <!-- /#introduction --> 
    36       <%= catch_content :layout %> 
    37     </div> <!-- /#content --> 
    38   </div> <!-- /#container --> 
    39   <div id="footer">Merb: Mongrel + Erb</div> 
    40 </div> <!-- /#border --> 
     26  <div id="border"> 
     27    <div id="container"> 
     28      <div id="content"> 
     29        <div id="introduction"> 
     30          <h3>Merb Mascot</h3> 
     31          <ul> 
     32            <li><%= link_to image_tag('louiecon.gif', :alt => 'Big Louie, the Merb mascot'), "/" %></li> 
     33          </ul> 
     34          <%= catch_content :sidebar %> 
     35        </div> <!-- /#introduction --> 
     36        <%= catch_content :layout %> 
     37      </div> <!-- /#content --> 
     38    </div> <!-- /#container --> 
     39    <div id="footer">Merb: Mongrel + Erb</div> 
     40  </div> <!-- /#border --> 
    4141</body> 
    4242</html> 
  • mrblog/trunk/config/dependencies.rb

    r1315 r1343  
    4242#require 'merbful_authentication' #merbful_authentication is The Merb Way, update to it 
    4343 
     44dependency "merb_helpers" 
     45 
    4446Merb::BootLoader.after_app_loads do 
    4547  ### Add dependencies here that must load after the application loads: 
  • mrblog/trunk/config/merb.yml

    r1203 r1343  
    1515 
    1616# Uncomment if you have more than one ORM or if you need to be specific about 
    17 # which memory store to use. Built-in options are: memory, cookie, or mem_cache 
    18 :session_store: active_record 
     17# which memory store tb use. Built-in options are: memory, cookie, or mem_cache 
     18:session_store: activerecord 
    1919 
    2020#:memory_session_ttl: 3600 # one hour 
  • mrblog/trunk/schema/migrations/001_add_sessions_table.rb

    r1203 r1343  
    22  def self.up 
    33    create_table :sessions, :force => true do |t| 
    4       t.column :session_id,      :string, :limit => 32 
    5       t.column :created_at,  :datetime 
    6       t.column :data,       :text 
     4      t.string   :session_id, :limit => 32 
     5      t.datetime :created_at 
     6      t.text     :data 
    77    end 
     8    add_index(:sessions, :session_id) 
    89  end 
    910 
  • mrblog/trunk/schema/schema.rb

    r1203 r1343  
    1010# It's strongly recommended to check this file into your version control system. 
    1111 
    12 ActiveRecord::Schema.define(:version => 6) do 
     12ActiveRecord::Schema.define(:version => 100) do 
    1313 
    1414  create_table "comments", :force => true do |t| 
    1515    t.integer  "post_id" 
    1616    t.string   "name" 
    17     t.text     "body
     17    t.text     "text
    1818    t.datetime "created_at" 
    1919    t.datetime "updated_at" 
     
    2121 
    2222  create_table "posts", :force => true do |t| 
    23     t.string   "title" 
    24     t.text     "body" 
     23    t.integer  "user_id" 
     24    t.string   "title",      :null => false 
     25    t.text     "text" 
    2526    t.datetime "created_at" 
    2627    t.datetime "updated_at" 
    27     t.string   "intro" 
    28     t.boolean  "page" 
    2928  end 
    3029 
     
    3534  end 
    3635 
    37   add_index "sessions", ["session_id"], :name => "sessions_session_id_index
     36  add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id
    3837 
    3938  create_table "users", :force => true do |t| 
     39    t.string   "first_name" 
     40    t.string   "last_name" 
    4041    t.string   "login",            :limit => 40 
    4142    t.string   "email",            :limit => 100 
     
    4445    t.datetime "created_at" 
    4546    t.datetime "updated_at" 
    46     t.string   "first_name" 
    47     t.string   "last_name" 
    4847  end 
    4948