Module: Broadway::Readable::InstanceMethods

Defined in:
lib/broadway/mixins/readable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/broadway/mixins/readable.rb', line 9

def file
  @file
end

Instance Method Details

#categoriesObject



27
28
29
# File 'lib/broadway/mixins/readable.rb', line 27

def categories
  file.categories
end

#descriptionObject



35
36
37
# File 'lib/broadway/mixins/readable.rb', line 35

def description
  data && data["description"]
end

#directoryObject



15
16
17
# File 'lib/broadway/mixins/readable.rb', line 15

def directory
  file.directory
end

#extensionObject



11
12
13
# File 'lib/broadway/mixins/readable.rb', line 11

def extension
  file.extension
end

#file_nameObject



23
24
25
# File 'lib/broadway/mixins/readable.rb', line 23

def file_name
  file.name
end

#file_pathObject



19
20
21
# File 'lib/broadway/mixins/readable.rb', line 19

def file_path
  file.path
end

#read(attribute = nil) ⇒ Object



31
32
33
# File 'lib/broadway/mixins/readable.rb', line 31

def read(attribute = nil)
  file.read(attribute)
end

#read_description(max_length = nil, format = self.extension, strip = true) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/broadway/mixins/readable.rb', line 43

def read_description(max_length = nil, format = self.extension, strip = true)
  result = read("description")
  result = read if result.nil? || result.empty?
  if format == "markdown"
    require 'rdiscount'
    result = RDiscount.new(result).to_html
  elsif format == "textile"
    require 'redcloth'
    result = RedCloth.new(result).to_html
  end
  if strip
    result = result.
      gsub(/<\/?[^>]*>/, "").
      gsub(/\n\n\t/, " ").
      gsub(/\n\t/, ", ").
      gsub(/\n+/, ". ").
      gsub(/\.+/, ".").
      gsub(/\s+/, " ").
      gsub(/(,\s)+/, ", ").
      gsub(/^,\s/, "").
      gsub(/\.,/, ".").
      gsub(/^[,\.?]\s+/, "")
  end
  max_length ||= result.length
  result = result[0..max_length] + "..."
  result = "" if result == "..."
  result
end

#render(attribute = nil, extension = self.extension) ⇒ Object



39
40
41
# File 'lib/broadway/mixins/readable.rb', line 39

def render(attribute = nil, extension = self.extension)
  file.render(attribute, extension)
end