Class: Bookpress::Utility

Inherits:
Object
  • Object
show all
Defined in:
lib/bookpress.rb

Class Method Summary collapse

Class Method Details

.articlize(tree, parent = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/bookpress.rb', line 100

def self.articlize(tree, parent = nil)
  unless tree.is_a?(String)
    article = ""
    tree.each do |key, value|
      html = ""
      if Utility.idify(key) == Utility.idify(parent)
        if value.is_a?(String)
          html << value
        else
          html << Utility.articlize(tree[key], key)
        end
      else
        html = "<article id='#{Utility.idify(key)}'>"
        html << ("<header><h1>#{Utility.titleize(key)}</h1></header>")
        if value.is_a?(String)
          html << value
        else
          html << Utility.articlize(tree[key], key)
        end
        html << "</article>"
      end
      article << html
    end
    article
  else
    tree
  end
end

.idify(title) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/bookpress.rb', line 80

def self.idify(title)
  if title
    new_title           = title.sub(/(\d*_)/, '')
    really_new_title    = new_title.sub(/(\.\w*)/, '')
    extremely_new_title = really_new_title.sub(/ /, '_')
    extremely_new_title.downcase!
    extremely_new_title
  else
    ''
  end
end

.markdown_rendererObject



129
130
131
132
133
134
135
136
# File 'lib/bookpress.rb', line 129

def self.markdown_renderer
   Redcarpet::Markdown.new(Bookpress::HTMLRenderer, {
    autolink:                     true,
    disable_indented_code_blocks: true,
    fenced_code_blocks:           true,
    space_after_headers:          true
  })
end

.orderify(title) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/bookpress.rb', line 92

def self.orderify(title)
  if title
    /(\d*)_/.match(title)[1]
  else
    ''
  end
end

.titleize(title) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bookpress.rb', line 62

def self.titleize(title)
  if title
    new_title        = title.sub(/(\d*_)/, '')
    really_new_title = new_title.sub(/(\.\w*)/, '')
    words            = really_new_title.to_s.split('_')
    words.each do |word|
      if word.length <3
        word.downcase!
      elsif word.length >3
        word.capitalize!
      end
    end
    words.join ' '
  else
    ''
  end
end