Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Limpando as Views

Limpando as Views

Palestra apresentada no GURU-SP em 09/03/2013.

Nando Vieira

March 09, 2013
Tweet

More Decks by Nando Vieira

Other Decks in Programming

Transcript

  1. O IMPORTANTE É O QUE O USUÁRIO VÊ E NÃO

    O QUE ESTÁ POR BAIXO DOS PANOS. PROBLEMA
  2. <!-- div#container_main é aberta no application layout --> <h2 class="question-title">Pergunta</h2>

    <%#<p id="next-question"><a href="#" title="Próxima pergunta: título da pergunta">próxima pergunta</a></p>%> <div class="question-box" id="question"> <%= avatar_link_to :medium, @question.user %> <div class="question-data-wrapper"> <% special_info = special_flag(@question) %> <div class="question-data <%= special_info.first+"_question- data" if special_info %>"> <% if @question.expired? || @question.closed? %> <p class="question-status closed"><strong>Pergunta fechada</strong></p> <% else %> <p class="question-status open"><strong>Pergunta aberta</strong></p> <% end %> <% if special_info %> <div class="special_flag <%= special_info.first %>_flag"> <img src="/images/specials/<%= special_info.first %>/flag_question.png" alt="<%= special_info.first %>" class="pngfix"/> <a href="<%= special_info.last %>" title="<%=
  3. 323 LINHAS DE VIEW 70 ITERAÇÕES * 25 LINHAS 251

    LINHAS DE PARTIALS 225 LINHAS DE LAYOUT ESTATÍSTICAS
  4. INFELIZMENTE, ÀS VEZES O PRODUCT OWNER ACHA QUE TUDO TEM

    A MESMA RELEVÂNCIA. TRUE STORY, BRO.
  5. class PageTitle ACTION_ALIASES = { "create" => :new, "update" =>

    :edit, "destroy" => :remove } attr_reader :controller def initialize(controller, action) @controller, @action = controller, action end def action ACTION_ALIASES.fetch(@action, @action) end def title I18n.t(action, :scope => [:titles, controller]) end end
  6. require "spec_helper_lite" require "./app/presenters/page_title" describe PageTitle do before do I18n.locale

    = :en I18n.backend.store_translations(:en, {:titles => { :mycontroller => { :home => "Home", :new => "New", :edit => "Edit", :remove => "Remove" } }}) end it "returns title" do title = PageTitle.new("mycontroller", "home").title expect(title).to eql("Home") end end
  7. $ time rspec spec/presenters/ page_title_spec.rb .... Finished in 0.09289 seconds

    4 examples, 0 failures real! 0m1.112s user! 0m0.828s sys! 0m0.120s
  8. <nav> <ul> <% if logged_in? %> <li> <%= link_to t("menu.logout"),

    logout_path %> </li> <% else %> <li> <%= link_to t("menu.signup"), signup_path %> </li> <li> <%= link_to t("menu.login"), login_path %> </li> <% end %> </ul> </nav>
  9. <nav> <ul> <% if logged_in? %> <%= render "shared/menu_logged" %>

    <% else %> <%= render "shared/menu_unlogged" %> <% end %> </ul> </nav>
  10. class MainMenu def initialize(context) @context = context end def to_partial_path

    if @context.logged_in? "shared/menu_logged" else "shared/menu_unlogged" end end end
  11. describe MainMenu do let(:context) { mock(:context) } subject(:menu) { MainMenu.new(context)

    } context "when logged in" do before { context.stub :logged_in? => true } it { expect(menu.to_partial_path).to eq("shared/menu_logged") } end context "when unlogged" do before { context.stub :logged_in? => false } it { expect(menu.to_partial_path).to eq("shared/menu_unlogged") } end end
  12. <%= user.name %> <%= user.email %> <%= l(user.created_at, :format =>

    :short) %> <%= user.avatar # doesn’t exist yet %>
  13. class UserPresenter < SimpleDelegator def avatar(avatar = Gravatar) avatar.url(email) end

    def created_at I18n.l(__getobj__.created_at, :format => :short) end end
  14. class UserPresenter < Presenter subject :user expose :name, :email, :username

    def created_at l(user.created_at, :format => :short) end def avatar(avatar = Gravatar) avatar.url(user.email) end end