Module: Docify

Extended by:
Format, Markup
Defined in:
lib/docify.rb,
lib/docify/style.rb,
lib/docify/format.rb,
lib/docify/markup.rb,
lib/docify/version.rb,
lib/docify/document.rb,
lib/docify/template.rb

Defined Under Namespace

Modules: Format, Markup Classes: Document, Template

Constant Summary collapse

TEMPLATE =
<<END_TEMPLATE
<!DOCTYPE html> 
<html>
  <head>
    <title>{{title}}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    {{css}}
  </head>
  <body>
    <div id="content">{{content}}</div>
  </body>
</html>
END_TEMPLATE
CSS =
<<END_CSS
<style>
  body {
    background: #f8f8f8;
    font: 13.34px helvetica,arial,freesans,clean,sans-serif;
  }
  
  body * { line-height: 1.4em; }
  
  a { color: #4183C4; text-decoration: none; }
  a:hover { text-decoration: underline; }
  
  #content {
    width: 800px; margin: 0px auto;
  }
  
  p {
    margin: 1em 0!important;
    line-height: 1.5em!important;
  }
  
  h1, h2, h3, h4, h5, h6 { border: 0 !important; }
  
  h1 {
    font-size: 170%!important;
    border-top: 4px solid #AAA!important;
    padding-top: .5em!important;
    margin-top: 1.5em!important;
  }
  
  h1:first-child { border-top: none !important; }
  
  h2 { 
    font-size: 150% !important;
    margin-top: 1.5em !important;
    border-top: 4px solid #E0E0E0 !important;
    padding-top: .5em !important;
  }
  
  h3 { margin-top: 1em !important; }
  
  pre, code {
    font: 12px 'Bitstream Vera Sans Mono','Courier',monospace;
  }
  
  pre {
    margin: 1em 0;
    font-size: 12px;
    background-color: #eee;
    border: 1px solid #ddd;
    padding: 5px;
    line-height: 1.5em;
    color: #444;
    overflow: auto;
    -webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
  }
  
  code {
    font-size: 12px !important;
    background-color: ghostWhite !important;
    color: #444 !important;
    padding: 0 .2em !important;
    border: 1px solid #DEDEDE !important;
  }
  
  pre code {
    padding: 0!important;
    font-size: 12px!important;
    background-color: #EEE!important;
    border: none!important;
  }
</style>
END_CSS
FORMATS =
[:markdown, :textile, :rdoc]
VERSION =
'1.0.7'.freeze

Class Method Summary collapse

Methods included from Markup

markdown, rdoc, textile

Methods included from Format

detect_format, valid_format?

Class Method Details

.new(path, format = :markdown) ⇒ Docify::Document

Alias for Docify::Document.new

Returns:



17
18
19
# File 'lib/docify.rb', line 17

def new(path, format=:markdown)
  Docify::Document.new(path, format)
end

.render(text, format = :markdown) ⇒ Object

Simply renders content for the markup



23
24
25
26
27
28
29
# File 'lib/docify.rb', line 23

def render(text, format=:markdown)
  if Docify::FORMATS.include?(format.to_sym)
    Docify::Markup.send(format.to_sym, text)
  else
    raise ArgumentError, "Invalid markup: #{format}."
  end
end

.render_auto(text, filename) ⇒ Object

Simple render content with auto-detection from filename It returns the original text if markup language was not detected or not supported



35
36
37
38
39
40
41
42
43
# File 'lib/docify.rb', line 35

def render_auto(text, filename)
  format = detect_format(filename)
  
  if Docify.valid_format?(format)
    Docify::Markup.send(format, text)
  else
    text
  end
end

.valid_format?(f) ⇒ Boolean

Returns true if given format is supported

Returns:

  • (Boolean)


25
26
27
# File 'lib/docify/format.rb', line 25

def self.valid_format?(f)
  f.nil? ? false : FORMATS.include?(f.to_sym)
end