Top Level Namespace

Defined Under Namespace

Modules: DocmeTask Classes: Block, Docme, DocmeCLI, Page

Instance Method Summary collapse

Instance Method Details

#clean_attribute(attr) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/docme/utils.rb', line 6

def clean_attribute(attr)
    attr = attr.delete('+[')
    attr = attr.delete(']')
    attr = attr.delete('-')
    attr = attr.upcase
    attr
end

#clean_code(line) ⇒ Object



14
15
16
17
18
19
# File 'lib/docme/utils.rb', line 14

def clean_code(line)
    line.gsub!('<', '&lt;')
    line.gsub!('>', '&gt;')

    line
end

#clean_content(line) ⇒ Object



21
22
23
24
25
26
# File 'lib/docme/utils.rb', line 21

def clean_content(line)
    line = line.lstrip
    line = line.rstrip

    line
end

#clean_directory(path, is_verbose = nil) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/docme/utils.rb', line 99

def clean_directory(path, is_verbose = nil)
    # for each file in the directory
    Dir.foreach(path) do |f|

        next if f == '.' || f == '..'

        # if another directory then go inside
        if File.directory?(path + '/' + f)

            clean_directory(path + '/' + f)

        else # else delete file

            puts ' - docme removing file: ' + f if is_verbose

            File.delete(path + '/' + f)

        end
    end
end

#clean_filename(file) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/docme/utils.rb', line 28

def clean_filename(file)
    file = File.basename(file)
    file = file.split('.')
    file = file[0]

    file
end

#parse_directory(path, is_verbose = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/docme/utils.rb', line 54

def parse_directory(path, is_verbose = nil)

    files_array = []

    # for each file in the sub directory
    Dir.foreach(path) do |f|

        next if f == '.' || f == '..' || f.rindex('.', 0) || unsupported_encoding(f) ||  unsupported_extension(f)

        # if another directory then go inside
        if File.directory?(path + '/' + f)

            puts ' - docme parsing path: ' + f if is_verbose

            files_array.concat parse_directory(path + '/' + f)

        else # else parse normally

            temp_page = parse_file(path + '/' + f, is_verbose)
            files_array.push(temp_page) unless temp_page.nil? || temp_page.is_empty == true

        end
    end

    files_array

end

#parse_file(file, is_verbose = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/docme/utils.rb', line 82

def parse_file(file, is_verbose = nil)

    if File.file?(file) && File.exist?(file) && !file.rindex('.', 0) && !unsupported_encoding(file) && !unsupported_extension(file)

        puts ' - docme parsing page: ' + file if is_verbose

        page = Page.new(file)
        page.parse_blocks

        page

    else
        nil
    end

end

#unsupported_encoding(file) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/docme/utils.rb', line 46

def unsupported_encoding(file)
    parse = true

    parse = false unless file.encoding.name != 'UTF-8'

    parse
end

#unsupported_extension(file) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/docme/utils.rb', line 36

def unsupported_extension(file)
    parse = true

    unsupported_extensions = ['.gem', '.jar', '.gemspec', '.zip', '.tar', '.gz', '.tar.gz', '.jpeg', '.jpg', '.png', '.exe', '.md', '.lock']

    parse = false unless unsupported_extensions.include?(File.extname(file)) || (File.executable?(file) && !Dir.exist?(file)) || (File.executable_real?(file) && !Dir.exist?(file))

    parse
end