Class: Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Page

Returns a new instance of Page.



18
19
20
21
22
23
24
# File 'lib/docme/page.rb', line 18

def initialize(file)
    @name = clean_filename(file)
    @source_file = File.open(file).read
    @page_erb = '../templates/page.erb'
    @blocks  = []
    @is_empty = true
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



13
14
15
# File 'lib/docme/page.rb', line 13

def blocks
  @blocks
end

#is_emptyObject (readonly)

Returns the value of attribute is_empty.



14
15
16
# File 'lib/docme/page.rb', line 14

def is_empty
  @is_empty
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/docme/page.rb', line 12

def name
  @name
end

Instance Method Details

#parse_blocksObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/docme/page.rb', line 26

def parse_blocks
    block = []

    @source_file.each_line  do |line|
        strip_line = line.lstrip

        # if this is the begining of a comment block then start a new function doc
        next if strip_line.rindex('/*', 1) == 0

        # if this is the end of a comment block then there is nothing to do
        if strip_line.rindex('*/', 1) == 0
            # pass the block off to be processed, the returned object will be stored in the blocks array
            temp_block = Block.new(block)
            @blocks.push(temp_block) unless temp_block.is_empty == true
            block = []
            next
        end

        block.push(line)
    end

    @is_empty = @blocks.empty?
end

#render_site(index, page_erb = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/docme/page.rb', line 50

def render_site(index, page_erb = nil)
    @index = []

    index.each do |page|
        @index.push(page.name)
    end

    if page_erb.nil?
        renderer = ERB.new(File.read(File.join(File.dirname(__FILE__), @page_erb)))
    else
        renderer = ERB.new(File.read(File.join(Dir.pwd, page_erb)))
    end

    page = @name + '.html'

    File.open(page, 'w+') do |f|
        f.write(renderer.result(binding))
    end

    FileUtils.mv(page, 'docme_site/' + page)
end