Module: TypeStation::ViewHelpers

Defined in:
lib/type_station/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#present(object, klass = nil, &block) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/type_station/view_helpers.rb', line 4

def present(object, klass = nil, &block)
  if object.present?
    klass ||= "#{object.class.to_s}Presenter".constantize
    block.call(klass.new(object, self))
  else
    nil
  end
end

#ts_admin_toolbar(model, options = {}) ⇒ Object



24
25
26
# File 'lib/type_station/view_helpers.rb', line 24

def ts_admin_toolbar(model, options = {})
  type_station_toolbar('ts-admin-bar', model, 'admin_bar', options) if type_station_authorise
end

#ts_initObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/type_station/view_helpers.rb', line 13

def ts_init
  result = ''.html_safe
  if type_station_authorise
    result << stylesheet_link_tag("//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css")
    result << stylesheet_link_tag("type_station/application", media: "all")
    result << javascript_include_tag("type_station/application")
    result << cloudinary_js_config
  end
  result
end

#type_station_authoriseObject



32
33
34
# File 'lib/type_station/view_helpers.rb', line 32

def type_station_authorise
  instance_eval &TypeStation.config.authorise_with
end

#type_station_current_userObject



28
29
30
# File 'lib/type_station/view_helpers.rb', line 28

def type_station_current_user
  instance_eval &TypeStation.config.current_user
end

#type_station_template(id, content, type = 'text/x-type-station-template') ⇒ Object



40
41
42
# File 'lib/type_station/view_helpers.rb', line 40

def type_station_template(id, content, type = 'text/x-type-station-template')
   :script, content, id: id, type: type
end

#type_station_toolbar(id, model, partial_name, options = {}) ⇒ Object



36
37
38
# File 'lib/type_station/view_helpers.rb', line 36

def type_station_toolbar(id, model, partial_name, options = {})
  type_station_template([id, 'template'].join('-'), render(partial: "type_station/toolbars/#{partial_name}", locals: {model: model, options: options}).html_safe)
end