Class: Genit::HtmlDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/genit/documents/html_document.rb

Overview

Open an html file in various format.

Class Method Summary collapse

Class Method Details

.build_page_content(file, working_dir) ⇒ Object

Public: Open a file as a string, taking care of fragment tags. All fragment tags are replaced by a new content.

file - Full path String name of a (html|markdown|haml) file.

Returns a String.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/genit/documents/html_document.rb', line 55

def self.build_page_content(file, working_dir)
  # TODO éviter le working_dir
  str = IO.read(file)
  if file.markdown_ext?
    BlueCloth.new(str).to_html
  elsif file.haml_ext?
    Haml::Engine.new(str, :format => :xhtml).render
  else
    Fragment.new(file, working_dir).to_html
  end
end

.genit_tags_from(file) ⇒ Object

Public: Get the list of <genit> tag in a document.

file - Nokogiri::HTML or Nokogiri::XML document.

Returns Nokogiri::XML::NodeSet.



72
73
74
# File 'lib/genit/documents/html_document.rb', line 72

def self.genit_tags_from file
  file.css "genit"
end

.open(file) ⇒ Object

Public: Open an entire html document. If the file does not contain a <bogy> tag, a doctype, etc, they will be automatically added.

file - Full path String filename.

Returns a Nokogiri::HTML document.



19
20
21
# File 'lib/genit/documents/html_document.rb', line 19

def self.open file
  Nokogiri::HTML(File.open(file))
end

.open_as_string(file) ⇒ Object

Public: Open a file as a string.

file - Full path String name of a html or markdown file.

Returns a String.



38
39
40
41
42
43
44
45
46
47
# File 'lib/genit/documents/html_document.rb', line 38

def self.open_as_string file
  string = IO.read file
  if file.markdown_ext?
    BlueCloth.new(string).to_html 
  elsif file.haml_ext?
    Haml::Engine.new(string, :format => :xhtml).render
  else
    string
  end
end

.open_fragment(file) ⇒ Object

Public: Open a fragment of html document.

file - Full path String filename.

Returns a Nokogiri::HTML document.



28
29
30
31
# File 'lib/genit/documents/html_document.rb', line 28

def self.open_fragment file
  string = IO.read file
  Nokogiri::HTML.fragment string
end