mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Generate and inherit from ApplicationDecorator
This commit is contained in:
parent
19fc9fcbbf
commit
d7f154c978
2 changed files with 15 additions and 11 deletions
|
@ -2,8 +2,9 @@ module Draper
|
|||
class ModelGenerator < Rails::Generators::NamedBase
|
||||
source_root File.expand_path('../templates', __FILE__)
|
||||
|
||||
def build_model
|
||||
def build_model_and_application_decorators
|
||||
empty_directory "app/decorators"
|
||||
template 'application_decorator.rb', 'app/decorators/application_decorator.rb'
|
||||
template 'model.rb', "app/decorators/#{singular_name}_decorator.rb"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
class <%= singular_name.camelize %>Decorator < Draper::Base
|
||||
class <%= singular_name.camelize %>Decorator < ApplicationDecorator
|
||||
decorates :<%= singular_name.to_sym %>
|
||||
|
||||
# Helpers from Rails an Your Application
|
||||
# You can access any helper via a proxy to ApplicationController
|
||||
# Accessing Helpers
|
||||
# You can access any helper via a proxy
|
||||
#
|
||||
# Normal Usage: helpers.number_to_currency(2)
|
||||
# Abbreviated : h.number_to_currency(2)
|
||||
#
|
||||
# You can optionally enable "lazy helpers" by including this module:
|
||||
# Or, optionally enable "lazy helpers" by including this module:
|
||||
# include Draper::LazyHelpers
|
||||
# Then use the helpers with no prefix:
|
||||
# Then use the helpers with no proxy:
|
||||
# number_to_currency(2)
|
||||
|
||||
# Wrapper Methods
|
||||
# Defining an Interface
|
||||
# Control access to the wrapped subject's methods using one of the following:
|
||||
#
|
||||
# To allow only the listed methods (whitelist):
|
||||
|
@ -22,8 +22,11 @@ class <%= singular_name.camelize %>Decorator < Draper::Base
|
|||
# denies :method1, :method2
|
||||
|
||||
# Presentation Methods
|
||||
# Define your own instance methods. Ex:
|
||||
# def formatted_created_at
|
||||
# content_tag :span, created_at.strftime("%A")
|
||||
# Define your own instance methods, even overriding accessors
|
||||
# generated by ActiveRecord:
|
||||
#
|
||||
# def created_at
|
||||
# content_tag :span, time.strftime("%a %m/%d/%y"),
|
||||
# :class => 'timestamp'
|
||||
# end
|
||||
end
|
Loading…
Reference in a new issue