Class: Lcms::Engine::ContentPresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
app/presenters/lcms/engine/content_presenter.rb

Direct Known Subclasses

DocumentPresenter, MaterialPresenter

Constant Summary collapse

CONFIG_PATH =
Rails.root.join('config', 'pdf.yml')
DEFAULT_CONFIG =
:default
MATERIALS_CONFIG_PATH =
Rails.root.join('config', 'materials_rules.yml')
PDF_EXT =
'.pdf'
THUMB_EXT =
'.jpg'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasePresenter

#t

Constructor Details

#initialize(obj, opts = {}) ⇒ ContentPresenter

Returns a new instance of ContentPresenter.



45
46
47
48
49
50
# File 'app/presenters/lcms/engine/content_presenter.rb', line 45

def initialize(obj, opts = {})
  super(obj)
  opts.each_pair do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Class Method Details

.base_configObject



12
13
14
# File 'app/presenters/lcms/engine/content_presenter.rb', line 12

def self.base_config
  @base_config ||= YAML.load_file(CONFIG_PATH).deep_symbolize_keys
end

.materials_configObject



16
17
18
# File 'app/presenters/lcms/engine/content_presenter.rb', line 16

def self.materials_config
  @materials_config ||= YAML.load_file(MATERIALS_CONFIG_PATH).deep_symbolize_keys
end

Instance Method Details

#base_filenameObject



20
21
22
23
# File 'app/presenters/lcms/engine/content_presenter.rb', line 20

def base_filename
  name = short_breadcrumb(join_with: '_', with_short_lesson: true)
  "#{name}_v#{version.presence || 1}"
end

#configObject



25
26
27
# File 'app/presenters/lcms/engine/content_presenter.rb', line 25

def config
  @config ||= self.class.base_config[DEFAULT_CONFIG].deep_merge(self.class.base_config[content_type.to_sym] || {})
end

#content_typeObject



29
30
31
# File 'app/presenters/lcms/engine/content_presenter.rb', line 29

def content_type
  @content_type.presence || 'none'
end


33
34
35
# File 'app/presenters/lcms/engine/content_presenter.rb', line 33

def footer_margin_styles
  padding_styles(align_type: 'margin')
end

#gdoc_folderObject



37
38
39
# File 'app/presenters/lcms/engine/content_presenter.rb', line 37

def gdoc_folder
  "#{id}_v#{version}"
end

#gdoc_keyObject



41
42
43
# File 'app/presenters/lcms/engine/content_presenter.rb', line 41

def gdoc_key
  DocumentExporter::Gdoc::Base.gdoc_key(content_type)
end

#materials_config_for(type) ⇒ Object



52
53
54
55
56
# File 'app/presenters/lcms/engine/content_presenter.rb', line 52

def materials_config_for(type)
  self.class.materials_config[type.to_sym].flat_map do |k, v|
    v.map { |x| { k => x } }
  end
end

#orientationObject



58
59
60
# File 'app/presenters/lcms/engine/content_presenter.rb', line 58

def orientation
  config[:orientation]
end

#padding_styles(align_type: 'padding') ⇒ Object



62
63
64
# File 'app/presenters/lcms/engine/content_presenter.rb', line 62

def padding_styles(align_type: 'padding')
  config[:padding].map { |k, v| "#{align_type}-#{k}:#{v};" }.join
end