Module: Story::Utils

Included in:
Base
Defined in:
lib/story/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.lib_dirObject

Raises:

  • (LoadError)


10
11
12
13
14
# File 'lib/story/utils.rb', line 10

def self.lib_dir
  ["#{File.dirname(File.expand_path($0))}/../lib/#{Meta::NAME}", "#{Gem.dir}/gems/#{Meta::NAME}-#{Meta::VERSION}/lib/#{Meta::NAME}"]
  .each {|lib| return i if File.readable? lib }
  raise LoadError
end

Instance Method Details

#get_last_session_urlObject



26
27
28
# File 'lib/story/utils.rb', line 26

def get_last_session_url
  @last_session = request.cookies["session_url"] != "" ? request.cookies["session_url"] : '/'
end

#load_additional_stylesObject



3
4
5
6
7
8
# File 'lib/story/utils.rb', line 3

def load_additional_styles
  begin
    settings.additional_stylesheets
  rescue NoMethodError
  end
end

#parse_file(filename, extension = '', root = true) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/story/utils.rb', line 34

def parse_file filename, extension = '', root = true
  file_path = "#{'.' if root}#{filename}.#{extension}"
  raise not_found if not File.exists? file_path
  content_type case extension
  when "xml" then "text/#{extension}"
  when "mp3", "mp4", "ogg", "mpeg" then "audio/#{extension}"
  when "json", "pdf", "zip" then "application/#{extension}"
  when "png", "gif", "jpg", "jpeg", "svg", "tiff" then "image/#{extension}"
  else "text/plain"
  end
  File.read file_path
end

#set_session_urlObject



30
31
32
# File 'lib/story/utils.rb', line 30

def set_session_url
  response.set_cookie "session_url", request.path_info if !(request.path_info.match /^e_/).is_a? NilClass and @last_session != request.path_info
end

#title(*sections) ⇒ Object



16
17
18
19
20
# File 'lib/story/utils.rb', line 16

def title *sections
  sections.each do |section|
    @title += "#{settings.title_separator}#{section.to_s}"
  end
end

#title_type(type_given = false) ⇒ Object



22
23
24
# File 'lib/story/utils.rb', line 22

def title_type type_given = false
  @title = "(#{type_given}) #{@title}" if type_given
end