Class: Admin::PostBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/ecrire/app/forms/admin/post_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(object_name, object, template, options) ⇒ PostBuilder

Returns a new instance of PostBuilder.



4
5
6
7
8
9
# File 'lib/ecrire/app/forms/admin/post_builder.rb', line 4

def initialize(object_name, object, template, options)
  if object.draft?
    options[:html][:class] << 'autosave'
  end
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



43
44
45
# File 'lib/ecrire/app/forms/admin/post_builder.rb', line 43

def method_missing(method, *args, &block)
  @template.send(method, *args, &block)
end

Instance Method Details

#actionObject



31
32
33
34
35
36
37
# File 'lib/ecrire/app/forms/admin/post_builder.rb', line 31

def action
  if object.published?
    button 'Save', value: 'save', form: "postEditor"
  else
    button 'Publish', value: 'publish', form: "postEditor"
  end
end

#editorObject



21
22
23
24
25
26
27
28
29
# File 'lib/ecrire/app/forms/admin/post_builder.rb', line 21

def editor
   :section, class: %w(textareas) do
    [
      text_area(:content, placeholder: t('.content'), class: %w(content active), target: 'content'),
      text_area(:stylesheet, placeholder: t('.stylesheet'), class: %w(stylesheet), target: 'stylesheet'),
      text_area(:javascript, placeholder: t('.javascript'), class: %w(javascript), target: 'javascript')
    ].join.html_safe
  end
end

#errorsObject



11
12
13
14
15
16
17
18
19
# File 'lib/ecrire/app/forms/admin/post_builder.rb', line 11

def errors
  return unless object.errors.any?
   :div, class: %w(container errors) do
    [
      (:span, h(object.errors.full_messages.to_sentence)),
      link_to("x", "javascript:void(0)", class: %w(dismiss button))
    ].join.html_safe
  end
end

#t(*args) ⇒ Object



39
40
41
# File 'lib/ecrire/app/forms/admin/post_builder.rb', line 39

def t(*args)
  I18n.t args[0], scope: %w(admin form post)
end