class RenderingEngine::Content

Attributes

custom_helper[R]
data[R]
file_path[R]
file_repo[R]

Public Class Methods

new(file_repo, file_path, opts = {}) click to toggle source
# File lib/rendering_engine/content.rb, line 7
def initialize(file_repo, file_path, opts = {})
  @file_repo        = file_repo
  @file_path        = file_path
  @base_folder_path = opts[:base_folder_path]
  @data             = opts[:data]
  @custom_helper    = opts[:custom_helper]
end

Public Instance Methods

base_folder_path() click to toggle source
# File lib/rendering_engine/content.rb, line 52
def base_folder_path
  @base_folder_path ||= file_repo.file_dirname(file_path)
end
kind() click to toggle source
# File lib/rendering_engine/content.rb, line 28
def kind
  @kind ||= (
    if orginal_file_present?
      :orginal
    elsif file_as_erb_present?
      :template
    else
      :unknown
    end
  )
end
orginal?() click to toggle source
# File lib/rendering_engine/content.rb, line 44
def orginal?
  kind == :orginal
end
source() click to toggle source
# File lib/rendering_engine/content.rb, line 15
def source
  @source ||= (
    case kind
    when :orginal  then file_repo.read(file_path)
    when :template
      ERB.new(file_repo.read(file_path_as_erb)).result(
        helper(base_folder_path, data).instance_eval { binding }
      )
    else ''
    end
  )
end
template?() click to toggle source
# File lib/rendering_engine/content.rb, line 40
def template?
  kind == :template
end
unknown?() click to toggle source
# File lib/rendering_engine/content.rb, line 48
def unknown?
  kind == :unknown
end

Private Instance Methods

file_as_erb_present?() click to toggle source
# File lib/rendering_engine/content.rb, line 70
def file_as_erb_present?
  file_repo.exist?(file_path_as_erb)
end
file_path_as_erb() click to toggle source
# File lib/rendering_engine/content.rb, line 74
def file_path_as_erb
  @file_as_erb ||= "#{file_path}.erb"
end
helper(path, content_data) click to toggle source
# File lib/rendering_engine/content.rb, line 60
def helper(path, content_data)
  (custom_helper || ContentHelpers).new(file_repo,
                                        base_path: path,
                                        data: content_data)
end
orginal_file_present?() click to toggle source
# File lib/rendering_engine/content.rb, line 66
def orginal_file_present?
  file_repo.exist?(file_path)
end