Permalink
Browse files

Merge pull request #12 from jhbabon/9-mustache

Finished the base mustache integration [closes #9]

Some views need to be ported to the new system, but the base is already done.
  • Loading branch information...
jhbabon committed May 13, 2012
2 parents 605a321 + e493881 commit ea14c3de630e558194365134b46c1797e736d8db
Showing with 572 additions and 186 deletions.
  1. +0 −1 app/assets/javascripts/backend.js
  2. +11 −0 app/presenters/image_presenter.rb
  3. +34 −2 app/presenters/post_presenter.rb
  4. +29 −0 app/templates/backend/posts/_form.html.mustache
  5. +4 −0 app/templates/backend/posts/edit.html.mustache
  6. +35 −0 app/templates/backend/posts/index.html.mustache
  7. +3 −0 app/templates/backend/posts/new.html.mustache
  8. +52 −0 app/templates/backend/posts/show.html.mustache
  9. +0 −37 app/views/backend/posts/_form.html.erb
  10. +21 −0 app/views/backend/posts/blueprint.rb
  11. +0 −6 app/views/backend/posts/edit.html.erb
  12. +13 −0 app/views/backend/posts/edit.rb
  13. +51 −0 app/views/backend/posts/form.rb
  14. +0 −40 app/views/backend/posts/index.html.erb
  15. +22 −0 app/views/backend/posts/index.rb
  16. +0 −5 app/views/backend/posts/new.html.erb
  17. +13 −0 app/views/backend/posts/new.rb
  18. +0 −49 app/views/backend/posts/show.html.erb
  19. +14 −0 app/views/backend/posts/show.rb
  20. +1 −3 app/views/backend/shared/_page_title.html.erb
  21. +1 −1 app/views/layouts/backend.rb
  22. +2 −2 app/views/posts/show.html.erb
  23. +1 −0 lib/canvas.rb
  24. +43 −0 lib/canvas/form_builder.rb
  25. +5 −1 lib/canvas/layout.rb
  26. +22 −3 lib/canvas/view.rb
  27. +69 −0 test/factories/canvas.rb
  28. +1 −1 test/functional/backend/backend_test_case.rb
  29. +1 −1 test/functional/backend/places_controller_test.rb
  30. +1 −1 test/functional/backend/posts_controller_test.rb
  31. +1 −1 test/functional/posts_controller_test.rb
  32. +1 −0 test/test_helper.rb
  33. +46 −0 test/unit/canvas/assets_test.rb
  34. +20 −0 test/unit/canvas/form_builder_test.rb
  35. +25 −0 test/unit/canvas/layout_test.rb
  36. +7 −28 test/unit/canvas/view_test.rb
  37. +3 −3 test/unit/category_test.rb
  38. +1 −1 test/unit/post_test.rb
  39. +19 −0 test/unit/views/layouts/backend_test.rb
@@ -16,6 +16,5 @@
//= require_self
$(document).ready(function() {
- alert('loaded');
$('.datepicker').datepicker();
});
@@ -0,0 +1,11 @@
+# -*- encoding: utf-8 -*-
+
+# TODO: tests!
+class ImagePresenter < BasePresenter
+ presents :image
+ delegate :title, to: :image
+
+ def thumbnail
+ h.image_tag image.resource_url(:thumb).to_s
+ end
+end
@@ -3,10 +3,14 @@
# TODO: tests!
class PostPresenter < BasePresenter
presents :post
- delegate :title, :published_at, :body, :images, :event, to: :post
+ delegate :title, :published, :body, :images, :event, to: :post
def linked_title
- h.link_to post.title, post;
+ h.link_to post.title, post
+ end
+
+ def clean_excerpt
+ post.excerpt
end
def excerpt
@@ -20,4 +24,32 @@ def category
h.render partial: 'posts/category', locals: { category: post.category }
end
end
+
+ def published_at
+ h.l(post.published_at, format: :long) if post.published_at.present?
+ end
+
+ def images
+ post.images.map { |image| self.class.build(image, h) }
+ end
+
+ # TODO: chose a better name
+ def link_to_display
+ h.link_to 'Display', post
+ end
+
+ def link_to_view
+ h.link_to 'View', h.backend_post_path(post)
+ end
+
+ def link_to_edit
+ h.link_to 'Edit', h.edit_backend_post_path(post)
+ end
+
+ def link_to_destroy
+ h.link_to 'Destroy',
+ h.backend_post_path(post),
+ confirm: 'Are you sure?',
+ method: :delete
+ end
end
@@ -0,0 +1,29 @@
+<div class="row">
+ <div class="span12">
+ {{# form }}
+ {{ input_title }}
+ {{ input_body }}
+ {{ input_excerpt }}
+
+ {{ association_category }}
+
+ {{ input_published_at }}
+
+ {{# images }}
+ {{ input_title }}
+ {{ input_resource }}
+ {{/ images }}
+
+ {{# events }}
+ <fieldset>
+ <legend>Datos del evento</legend>
+ {{ input_title }}
+ {{ input_start_date }}
+ {{ association_place }}
+ </fieldset>
+ {{/ events }}
+
+ {{ submit }}
+ {{/ form }}
+ </div>
+</div>
@@ -0,0 +1,4 @@
+{{> form }}
+
+{{& link_to_view }}
+{{& link_to_back }}
@@ -0,0 +1,35 @@
+<div class="row">
+ <div class="span12">
+ <table class="table">
+ <tr>
+ <th>Title</th>
+ <th>Published at</th>
+ <th>Published</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+ {{# each_post }}
+ <tr>
+ <td>{{& linked_title }}</td>
+ <td>{{ published_at }}</td>
+ <td>{{ published }}</td>
+ <td>{{& link_to_display }}</td>
+ <td>{{& link_to_view }}</td>
+ <td>{{& link_to_edit }}</td>
+ <td>{{& link_to_destroy }}</td>
+ </tr>
+ {{/ each_post }}
+ </table>
+ <!-- TODO: add pagination with kaminari -->
+
+ <br />
+
+ <ul>
+ <li>{{& link_to_new_post }}</li>
+ <li>{{& link_to_new_evented_post }}</li>
+ </ul>
+ </div>
+</div>
@@ -0,0 +1,3 @@
+{{> form }}
+
+{{& link_to_back }}
@@ -0,0 +1,52 @@
+<div class="row">
+ <div class="span12">
+
+ {{# notice? }}
+ <p id="notice">{{ notice }}</p>
+ {{/ notice? }}
+
+ {{# show_post }}
+ <p>
+ <b>Title:</b>
+ {{ title }}
+ </p>
+
+ <p>
+ <b>Body:</b>
+ {{ body }}
+ </p>
+
+ <p>
+ <b>Excerpt:</b>
+ {{ clean_excerpt }}
+ </p>
+
+ <p>
+ <b>Published at:</b>
+ {{ published_at }}
+ </p>
+
+ <p>
+ <b>Published:</b>
+ {{ published }}
+ </p>
+
+ <p>
+ <strong>Images</strong>
+ </p>
+ <ul class="thumbnails">
+ {{# images }}
+ <li class="span3">
+ <div class="thumbnail">
+ {{& thumbnail }}
+ <h5>{{ title }}</h5>
+ </div>
+ </li>
+ {{/ images }}
+ </ul>
+
+ {{& link_to_edit }} |
+ {{/ show_post}}
+ {{& link_to_back }}
+ </div>
+</div>
@@ -1,37 +0,0 @@
-<div class="row">
- <div class="span12">
- <%= simple_form_for([:backend, @post],
- html: { class: 'form-vertical',
- multipart: true }) do |f| %>
- <%= f.input :title %>
- <%= f.input :body %>
- <%= f.input :excerpt, :as => :text %>
-
- <%= f.association :category %>
-
- <%= f.input :published_at %>
-
- <%= f.simple_fields_for(:images) do |fi| %>
- <%= fi.input :title %>
- <%= fi.input :resource %>
- <% end -%>
-
- <% if @post.event.present? %>
- <%= f.simple_fields_for :event do |fe| %>
- <fieldset>
- <legend>Datos del evento</legend>
-
- <%= fe.input :title %>
- <%= fe.input :start_date %>
-
- <%= fe.association :place %>
-
- </fieldset>
- <% end %>
- <% end %>
-
-
- <%= f.button :submit %>
- <% end %>
- </div>
-</div>
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+
+module Backend
+ module Posts
+ module Blueprint
+ def self.included(base)
+ base.class_eval do
+ delegate :link_to_view, to: :presenter
+ end
+ end
+
+ def presenter
+ @_presenter ||= h.present @post
+ end
+
+ def link_to_back
+ h.link_to 'Back', h.backend_posts_path
+ end
+ end
+ end
+end
@@ -1,6 +0,0 @@
-<%- title "Edit post: #{@post.title}" -%>
-
-<%= render 'form' %>
-
-<%= link_to t('Show'), backend_post_path(@post) %> |
-<%= link_to t('Back'), backend_posts_path %>
@@ -0,0 +1,13 @@
+# -*- encoding: utf-8 -*-
+
+module Backend
+ module Posts
+ class Edit < ::Canvas::View
+ include ::Backend::Posts::Blueprint
+ include ::Backend::Posts::Form
+
+ title { "Edit post: #{@post.title}" }
+ end
+ end
+end
+
@@ -0,0 +1,51 @@
+# -*- encoding: utf-8 -*-
+
+module Backend
+ module Posts
+ module Form
+ include ::Canvas::FormBuilder
+
+ def form
+ path = [:backend, @post]
+ options = { html: { class: 'form-vertical', multipart: true } }
+
+ formable(path, options) do |f|
+ {
+ input_title: f.input(:title),
+ input_body: f.input(:body),
+ input_excerpt: f.input(:excerpt, as: :text),
+ association_category: f.association(:category),
+ input_published_at: f.input(:published_at),
+ images: fields_for_images(f),
+ events: fields_for_events(f),
+ submit: f.submit,
+ }
+ end
+ end
+
+ def fields_for_images(f)
+ nested_formable(f, :images) do |fi|
+ {
+ input_title: fi.input(:title),
+ input_resource: fi.input(:resource),
+ }
+ end
+ end
+ protected :fields_for_images
+
+ def fields_for_events(f)
+ if @post.event
+ nested_formable(f, :events) do |fe|
+ {
+ input_title: fe.input(:title),
+ input_start_date: fe.input(:start_date),
+ association_place: fe.association(:place),
+ }
+ end
+ end
+ end
+ protected :fields_for_events
+ end
+ end
+end
+
@@ -1,40 +0,0 @@
-<%- title 'All posts' -%>
-
-<div class="row">
- <div class="span12">
- <table class="table">
- <tr>
- <th>Title</th>
- <th>Body</th>
- <th>Excerpt</th>
- <th>Published at</th>
- <th>Published</th>
- <th></th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
- <% @posts.each do |post| %>
- <tr>
- <td><%= post.title %></td>
- <td><%= post.body %></td>
- <td><%= post.excerpt %></td>
- <td><%= l post.published_at, format: :short if post.published_at? %></td>
- <td><%= post.published %></td>
- <td><%= link_to 'Display', post %></td>
- <td><%= link_to 'View', backend_post_path(post) %></td>
- <td><%= link_to 'Edit', edit_backend_post_path(post) %></td>
- <td><%= link_to 'Destroy', backend_post_path(post), confirm: 'Are you sure?', method: :delete %></td>
- </tr>
- <% end %>
- </table>
-
- <%# TODO: add pagination with kaminari %>
-
- <br />
-
- <%= link_to 'New Post', new_backend_post_path %>
- <%= link_to 'New event post', new_backend_post_path(with_events: 1) %>
- </div>
-</div>
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+
+module Backend
+ module Posts
+ class Index < ::Canvas::View
+ title 'All posts'
+
+ def each_post
+ @posts.map { |post| h.present post }
+ end
+
+ def link_to_new_post
+ h.link_to 'New Post', h.new_backend_post_path
+ end
+
+ def link_to_new_evented_post
+ h.link_to 'New event post', h.new_backend_post_path(with_events: 1)
+ end
+ end
+ end
+end
+
@@ -1,5 +0,0 @@
-<%- title 'New post' -%>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', backend_posts_path %>
Oops, something went wrong.

0 comments on commit ea14c3d

Please sign in to comment.