Module: Skyline::ContentHelper

Defined in:
app/helpers/skyline/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_url(path) ⇒ Object



144
145
146
# File 'app/helpers/skyline/content_helper.rb', line 144

def asset_url(path)
  File.join(@implementation.assets_url.to_s, path.to_s)
end

#boolean_field(tag_name, record, field, options = {}) ⇒ Object



128
129
130
131
132
133
134
# File 'app/helpers/skyline/content_helper.rb', line 128

def boolean_field(tag_name, record, field, options = {})
  hidden_field_tag(tag_name, "0") + 
  record_with_errors(
    check_box_tag(tag_name, "1" , field.value(record), options),
    record,
    field)
end

#content_breadcrumb(stack) ⇒ Object

We need some preconditions to make automatic breadcrumbs work

  1. The last part is never clickable

  2. The part before last will be params if it’s available

  3. Only lists will appear in the breadcrumb as links (unless there is return_to)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/skyline/content_helper.rb', line 7

def content_breadcrumb(stack)
  links = []
  return nil if stack.blank?
  types = stack.types.dup
  
  if types.last.last.nil?
    last = types.pop
  end
  
  types.each_with_index do |type,i|
    links << link_to(label_for(type), :action => "list", :types => stack.url_types(:up => (stack.types.size - i -1), :collection => true))
    links << "<span>#{stack.object_for_type(type).human_id}</span>"
  end
  
  links << "<span>#{label_for(last)}</span>" if last
  
  ("div","#{t(:breadcrumb_prefix, :scope => :content)} " + links.join(" &raquo; "),:id => "breadcrumb")    
end

#content_field(fieldset, record_name, field, record) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'app/helpers/skyline/content_helper.rb', line 106

def content_field(fieldset,record_name,field, record)
  e = Skyline::Editors::Editor.create(field,[record_name],record,@template)
  if e.postpone?
    postponed_editors << e
    ""
  else
    e.output
  end
end

#content_fields(fieldset, record_name, record) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/skyline/content_helper.rb', line 89

def content_fields(fieldset,record_name, record)
  out = ""

  fieldset.each_field do |field|
    next if (field.hidden_in(:edit) && !record.new_record?) || 
            (field.hidden_in(:create) && record.new_record?)

    case field
      when Skyline::Content::MetaData::Field
        out << content_field(fieldset, record_name, field, record) + "\n"
      when Skyline::Content::MetaData::FieldGroup
        out <<  render(:partial => "skyline/content/group", :locals => {:title => field.singular_title, :content => content_fields(field, record_name, record)})
    end
  end
  out
end

#content_form(record_name, options = {}, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/skyline/content_helper.rb', line 59

def content_form(record_name, options = {},&block)
  record = instance_variable_get("@#{record_name}")
  
  options = options.symbolize_keys
  url_options = url_options_for_record(record, {:action => options[:action]})
  
  contents = ''
  contents << content_fields(record.class,record_name, record)
  
  contents << capture(&block) if block_given?
            
  if record.class.publishable? || record.class.writable_fields.any?
    contents << hidden_field_tag(:authenticity_token, form_authenticity_token)
#      contents << hidden_field(record_name, :id) unless record.new_record?
    contents << hidden_field_tag(:version,record.current_version)
    
    output = ('form', contents, :id => "contentform", :action => object_url(record,url_options), :method => 'post', :enctype => options[:multipart] ? 'multipart/form-data': nil)
             
  else
    output = ('div', contents, :id => "contentform")
  end
  

  # Postponed editors are editors like inline_list that should not be in the form but provide their own form/list
  # functionality.
  output << postponed_editors.map(&:output).join("\n") if postponed_editors.any?
  
  concat output
end

#content_save_form(record_name, options = {}, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/skyline/content_helper.rb', line 31

def content_save_form(record_name,options={},&block)
  record = instance_variable_get("@#{record_name}")
  
  options.symbolize_keys!
  options.reverse_merge! :action => record.new_record? ? "create" : "edit"
  
  if record.class.publishable? || record.class.writable_fields.any?
  else
    
  end
  
end

#input_id(*parts) ⇒ Object



155
156
157
# File 'app/helpers/skyline/content_helper.rb', line 155

def input_id(*parts)
  parts.flatten.compact.collect{|p| p.to_s}.join("_")
end

#input_name(*parts) ⇒ Object



148
149
150
151
152
153
# File 'app/helpers/skyline/content_helper.rb', line 148

def input_name(*parts)
  parts = parts.flatten.compact.collect{|p| p.to_s}
  name = parts.shift.dup
  name << "[" + parts.join("][") + "]" unless parts.empty?
  name
end

#label_for(type) ⇒ Object



26
27
28
29
# File 'app/helpers/skyline/content_helper.rb', line 26

def label_for(type)
  obj = stack.object_for_type(type)
  obj.class.plural_name
end

#postponed_editorsObject

Postponed editors are editors like inline_list that should not be in the form but provide their own form/list functionality.



124
125
126
# File 'app/helpers/skyline/content_helper.rb', line 124

def postponed_editors
  @_postponed_editors ||= []
end

#presenter_for(records, fieldset) ⇒ Object

Outputs an object list with the right presenter defaults to Table currently.



118
119
120
# File 'app/helpers/skyline/content_helper.rb', line 118

def presenter_for(records,fieldset)
  Skyline::Presenters::Presenter.create(fieldset.settings.presenter,records,fieldset,@template).output
end

#record_with_errors(content, record, field) ⇒ Object



136
137
138
139
140
141
142
# File 'app/helpers/skyline/content_helper.rb', line 136

def record_with_errors(content, record, field)
  if record.errors.on(field.attribute_name) 
    ("div", content, :class => "fieldWithErrors")
  else
    content
  end
end

#url_options_for_record(record, options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/skyline/content_helper.rb', line 44

def url_options_for_record(record,options={})
  options.symbolize_keys!
  defaults = {}
  defaults[:action] = (record.new_record? ? "create" : "edit")
      
  # Return to after save determination
  if record.class.settings.return_to_self_after_save
    defaults[:return_to] = "self"
  elsif params[:return_to]
    defaults[:return_to] = params[:return_to]
  end
  
  options.reverse_merge defaults
end