Skip to content

Commit

Permalink
Implement Items#show
Browse files Browse the repository at this point in the history
  • Loading branch information
rosylilly committed Jan 26, 2013
1 parent a2555e4 commit ad3abd1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/auction/Gemfile
Expand Up @@ -9,6 +9,7 @@ gem 'bcrypt-ruby', '~> 3.0.0', require: 'bcrypt'
gem 'slim-rails'

gem 'draper'
gem 'github-markdown'

group :assets do
gem 'sass-rails', '~> 3.2.3'
Expand Down
6 changes: 6 additions & 0 deletions examples/auction/app/assets/stylesheets/application.css.scss
Expand Up @@ -15,6 +15,12 @@
@import 'compass/css3';
@import 'compass_twitter_bootstrap';

.emoji {
width: 1em;
height: 1em;
vertical-align: baseline;
}

.input-block-level {
@include box-sizing(border-box);
width: 100%;
Expand Down
8 changes: 8 additions & 0 deletions examples/auction/app/controllers/items_controller.rb
Expand Up @@ -8,4 +8,12 @@ def show
def new
@item = Item.new
end

def create
@item = current_user.items.create!(params[:item])

redirect_to item_path(@item)
rescue Activrecord::RecordInvalid
render :new
end
end
10 changes: 10 additions & 0 deletions examples/auction/app/decorators/item_decorator.rb
@@ -1,3 +1,13 @@
class ItemDecorator < Draper::Base
include Draper::LazyHelpers

decorates :item

def created_at
distance_of_time_in_words(Time.now, source.created_at)
end

def description
emojify(markdown(source.description))
end
end
14 changes: 14 additions & 0 deletions examples/auction/app/helpers/application_helper.rb
@@ -1,2 +1,16 @@
module ApplicationHelper
def emojify(content)
h(content).to_str.gsub(/:(?<emoji>[a-z0-9\+\-_]+):/) do |match|
emoji = $~[:emoji]
if Emoji.names.include?(emoji)
image_tag("emoji/#{emoji}.png", alt: emoji, class: 'emoji')
else
match
end
end.html_safe if content.present?
end

def markdown(content)
GitHub::Markdown.render_gfm(content).html_safe
end
end
2 changes: 2 additions & 0 deletions examples/auction/app/views/items/_form.html.slim
Expand Up @@ -17,3 +17,5 @@ h1 #{item.new_record? ? 'New' : 'Edit'} Item
label.control-label for='item_description' Description
.controls
= f.text_area :description, class: 'input-block-level'
.form-actions
= submit_tag item.new_record? ? 'create' : 'update', class: 'btn btn-primary'
6 changes: 6 additions & 0 deletions examples/auction/app/views/items/show.html.slim
@@ -0,0 +1,6 @@
h1= @item.title
p create at #{@item.created_at}

p Bottom Price: #{@item.bottom_price}

.description= @item.description

0 comments on commit ad3abd1

Please sign in to comment.