docme 1.1.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83eee48aa7acdbaf189f9df3b5c78df89a543d88
4
- data.tar.gz: cd2c845d5fb70b9f6c28600764bfdea5c106053f
3
+ metadata.gz: a1404bb774b46f9954b5f775667b7ceb30eec584
4
+ data.tar.gz: ed1fa0f5a8c31d2e3686477dc8b8fa0290feb652
5
5
  SHA512:
6
- metadata.gz: 98f6b0d9b6048296ef03bc810c8d015b37ef24fe5ae9703129ac97be2c8fc53480287d6a80b330200fcd027be6ee281046b8be00ae95dd4f70f668072e2ea046
7
- data.tar.gz: 76fad443ec0745288ba63843d573f3e1932e087fa7a9cd94d1209a7ba7c32070e54c9c69a59cc058cbf34663ef5424afb1eca1e45305317eeb4807bd0f3730e1
6
+ metadata.gz: 069ab9e0ff1480b64c98f90190538fbfaceed1839c9a742414663b951f1113ac7d536bf39d20802e7705b35fcc00a1628195db08d6813027eb68d03956bfa78b
7
+ data.tar.gz: 7000581d1e03954e0d398964513f3ef758debb0d819baf91b1b4027c728394dabd7752d44426d50ad861e9447336ec8eef00da95b0b73221152ac10bbed370c2
data/bin/docme CHANGED
@@ -1,23 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- require 'docme'
5
- require 'docme/utils'
6
- require 'fileutils'
4
+ require 'docme/DocmeCLI'
5
+ require 'thor'
7
6
 
8
- if ARGV[0].nil?
9
- path = Dir.pwd
10
- puts path
11
- else
12
- path = ARGV[0]
13
- end
14
-
15
- puts "\n ***Begining docme magix***"
16
-
17
- docmeer = Docme.new(path)
18
- docmeer.scan_docs
19
- docmeer.render_docs
20
- docmeer.render_index
21
-
22
- puts "\n ***Finished docme magic!***"
23
- puts "\n You can find your docs inside the `docme_site` folder. \n Hint: look for index.html\n\n"
7
+ DocmeCLI.start(ARGV)
data/lib/docme.rb CHANGED
@@ -7,45 +7,71 @@ require 'fileutils'
7
7
 
8
8
  class Docme
9
9
 
10
- def initialize(path)
10
+ def initialize(path, is_verbose = nil, style = nil, index = nil, page_erb = nil)
11
11
  @path = path
12
12
  @pages = []
13
+ @is_verbose = is_verbose
14
+ @style = style
15
+ @index = index
16
+ @page_erb = page_erb
13
17
 
18
+ puts '+ docme will parse: ' + @path if @is_verbose
19
+
20
+ make_home
21
+ end
22
+
23
+ def engage
14
24
  make_home
25
+ scan_docs
26
+ render_docs
27
+ render_index
28
+ render_css
15
29
  end
16
30
 
17
31
  def make_home
18
32
  # create the directory where the site will be stored
19
- return true if File.directory?('docme_site')
20
- puts "+ Setting up docme's living arrangements."
21
- Dir.mkdir('docme_site')
22
- puts ' - Woohoo! docme has a home!'
33
+ if Dir.exist?('docme_site')
34
+ clean_directory('docme_site', @is_verbose)
35
+ else
36
+ puts "+ Setting up docme's living arrangements." if @is_verbose
37
+ Dir.mkdir('docme_site')
38
+ puts ' - Woohoo! docme has a home!' if @is_verbose
39
+ end
23
40
  end
24
41
 
25
42
  def scan_docs
43
+
44
+ puts '+ docme scanning: ' + @path if @is_verbose
45
+
26
46
  # if a directory was provided
27
47
  if File.directory?(@path)
28
48
 
29
- @pages.concat parse_directory(@path)
49
+ @pages.concat parse_directory(@path, @is_verbose)
30
50
 
31
51
  else # if a single file was provided
32
52
 
33
- @pages.push(parse_file(@path))
53
+ @pages.push(parse_file(@path, @is_verbose))
34
54
 
35
55
  end
36
56
  end
37
57
 
38
58
  def render_docs
39
- puts '+ docme generated the following pages: '
59
+ puts '+ docme generated the following pages: ' if @is_verbose
40
60
  @pages.each do |page_object|
41
- page_object.render_site(@pages)
42
- puts ' - ' + page_object.name
61
+ page_object.render_site(@pages, @page_erb)
62
+ puts ' - ' + page_object.name if @is_verbose
43
63
  end
44
64
  end
45
65
 
46
66
  def render_index
47
67
 
48
- template = File.read(File.join(File.dirname(__FILE__), 'templates/index.erb'))
68
+ puts '+ docme is creating the index' if @is_verbose
69
+
70
+ if @index.nil?
71
+ template = File.read(File.join(File.dirname(__FILE__), 'templates/index.erb'))
72
+ else
73
+ template = File.read(File.join(Dir.pwd, @index))
74
+ end
49
75
 
50
76
  renderer = ERB.new(template)
51
77
 
@@ -55,6 +81,30 @@ class Docme
55
81
 
56
82
  # add page to docme dir
57
83
  FileUtils.mv('index.html', 'docme_site/index.html')
84
+
85
+ puts '+ index created' if @is_verbose
86
+ end
87
+
88
+ def render_css
89
+ puts '+ docme is styling' if @is_verbose
90
+
91
+ if @style.nil?
92
+ template = File.read(File.join(File.dirname(__FILE__), 'templates/style.erb'))
93
+ else
94
+ template = File.read(File.join(Dir.pwd, @style))
95
+ end
96
+
97
+ renderer = ERB.new(template)
98
+
99
+ File.open('style.css', 'w+') do |f|
100
+ f.write(renderer.result(binding))
101
+ end
102
+
103
+ # add page to docme dir
104
+ FileUtils.mv('style.css', 'docme_site/style.css')
105
+
106
+ puts '+ styling completed' if @is_verbose
107
+
58
108
  end
59
109
 
60
110
  end
@@ -0,0 +1,76 @@
1
+ # encoding: UTF-8
2
+ # Class DocmeCLI
3
+
4
+ require 'docme'
5
+ require 'docme/utils'
6
+ require 'fileutils'
7
+ require 'thor'
8
+
9
+ class DocmeCLI < Thor
10
+ class_option :v, type: :boolean
11
+
12
+ desc 'default', '`docme` When no commands are provided docme will begin the current directory and parse through all eligible folders and files.'
13
+ option :style, type: :string
14
+ option :index, type: :string
15
+ option :page, type: :string
16
+ def default
17
+ path = Dir.pwd
18
+ puts "\n ***Begining docme magix***"
19
+
20
+ docmeer = Docme.new(path, options[:v], options[:style], options[:index], options[:page])
21
+ docmeer.engage
22
+
23
+ puts "\n ***Finished docme magic!***"
24
+ puts "\n You can find your docs inside the `docme_site` folder. \n Hint: look for index.html\n\n"
25
+
26
+ end
27
+
28
+ desc 'clean', '`docme clean <path>` Attemtps to empty and remove the docme_site directory. Path is optional and should point to a directory containing a `docme_site` folder. If an error is returned then you will have to delete the folder manually.'
29
+ def clean(path = nil)
30
+ path = Dir.pwd if path.nil?
31
+
32
+ fail 'Please provide a valid path to a directory that contains a `docme_site` folder.' unless Dir.exist?(path + '/docme_site')
33
+
34
+ puts '+ docme will clean ' + path if options[:v]
35
+ puts '+ docme cleaning' if options[:v]
36
+
37
+ clean_directory(path + '/docme_site', options[:v])
38
+ Dir.rmdir(path + '/docme_site') if Dir.exist?(path + '/docme_site')
39
+
40
+ puts '+ docme_site removed' if options[:v]
41
+ puts '+ docme is now homeless' if options[:v]
42
+
43
+ end
44
+
45
+ desc 'parse', '`docme parse <path>` -- Either provide a path to a file or a path to a directory and docme will parse all valid files found.'
46
+ long_desc <<-LONGDESC
47
+ `docme parse <path/to/file>` will parse a single file specified
48
+
49
+ `docme parse <path/to/folder>` will parse all eligible files in the specified directory
50
+
51
+ `docme parse <path/to/folder> --style <path/to/css.erb>` will use your own custom styling options. This file must contain valid css and be saved as `.erb` file.
52
+
53
+ `docme parse <path/to/folder> --index <path/to/index.erb>` will use your own custom html to build the index page of the site.
54
+
55
+ `docme parse <path/to/folder> --page <path/to/yourPage.erb>` will use your own custom html to build the pages of the site.
56
+
57
+ Use the `-v` flag on any command to recieve verbose output.
58
+ LONGDESC
59
+ option :style, type: :string
60
+ option :index, type: :string
61
+ option :page, type: :string
62
+ def parse(path)
63
+
64
+ puts "\n ***Begining docme magix***"
65
+
66
+ docmeer = Docme.new(path, options[:v], options[:style], options[:index], options[:page])
67
+ docmeer.engage
68
+
69
+ puts "\n ***Finished docme magic!***"
70
+ puts "\n You can find your docs inside the `docme_site` folder. \n Hint: look for index.html\n\n"
71
+
72
+ end
73
+
74
+ default_task :default
75
+
76
+ end
data/lib/docme/block.rb CHANGED
@@ -31,7 +31,12 @@ class Block
31
31
  if strip_line.rindex('+', 0) == 0
32
32
 
33
33
  is_docme = 1
34
- parts = strip_line.split(':')
34
+ parts = strip_line.split(':', 2)
35
+
36
+ if parts[0].nil? || parts[1].nil?
37
+ is_docme = 0
38
+ next
39
+ end
35
40
 
36
41
  # parts[0] == the attribute name
37
42
  attribute = clean_attribute(parts[0])
data/lib/docme/page.rb CHANGED
@@ -18,6 +18,7 @@ class Page
18
18
  def initialize(file)
19
19
  @name = clean_filename(file)
20
20
  @source_file = File.open(file).read
21
+ @page_erb = '../templates/page.erb'
21
22
  @blocks = []
22
23
  @is_empty = true
23
24
  end
@@ -46,16 +47,18 @@ class Page
46
47
  @is_empty = @blocks.empty?
47
48
  end
48
49
 
49
- def render_site(index)
50
+ def render_site(index, page_erb = nil)
50
51
  @index = []
51
52
 
52
53
  index.each do |page|
53
54
  @index.push(page.name)
54
55
  end
55
56
 
56
- # puts content
57
- renderer = ERB.new(File.read(File.join(File.dirname(__FILE__), '../templates/page.erb'))
58
- )
57
+ if page_erb.nil?
58
+ renderer = ERB.new(File.read(File.join(File.dirname(__FILE__), @page_erb)))
59
+ else
60
+ renderer = ERB.new(File.read(File.join(Dir.pwd, page_erb)))
61
+ end
59
62
 
60
63
  page = @name + '.html'
61
64
 
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake'
4
+ require 'rake/tasklib'
5
+ require 'docme/DocmeCLI'
6
+
7
+ module DocmeTask
8
+ # Provides a custom rake task.
9
+ #
10
+ # require 'docme/rake-task'
11
+ # Docme::RakeTask.new
12
+ class RakeTask < ::Rake::TaskLib
13
+
14
+ attr_accessor :name
15
+ attr_accessor :parse
16
+ attr_accessor :index
17
+ attr_accessor :page
18
+ attr_accessor :style
19
+ attr_accessor :verbose
20
+
21
+ def initialize(*args, &task_block)
22
+ @name = args.shift || :docme
23
+ @parse = nil
24
+ @index = nil
25
+ @page = nil
26
+ @style = nil
27
+ @verbose = nil
28
+
29
+ define(args, &task_block)
30
+
31
+ end
32
+
33
+ def engage_docme
34
+
35
+ input = build_input
36
+
37
+ DocmeCLI.start(input)
38
+
39
+ end
40
+
41
+ def build_input
42
+ temp = []
43
+
44
+ temp.push('parse', @parse) unless @parse.nil?
45
+ temp.push('--index', @index) unless @index.nil?
46
+ temp.push('--page', @page) unless @page.nil?
47
+ temp.push('--style', @style) unless @style.nil?
48
+ temp.push('-v') unless @verbose.nil?
49
+
50
+ temp
51
+ end
52
+
53
+ def define(args, &task_block)
54
+ desc 'Run docme' unless ::Rake.application.last_comment
55
+
56
+ task name, *args do |_, task_args|
57
+ RakeFileUtils.__send__(:verbose, verbose) do
58
+ task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
59
+ engage_docme
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ end
data/lib/docme/utils.rb CHANGED
@@ -36,7 +36,7 @@ end
36
36
  def unsupported_extension(file)
37
37
  parse = true
38
38
 
39
- unsupported_extensions = ['.gem', '.jar', '.gemspec', '.zip', '.tar', '.gz', '.tar.gz', '.jpeg', '.jpg', '.png', '.exe']
39
+ unsupported_extensions = ['.gem', '.jar', '.gemspec', '.zip', '.tar', '.gz', '.tar.gz', '.jpeg', '.jpg', '.png', '.exe', '.md', '.lock']
40
40
 
41
41
  parse = false unless unsupported_extensions.include?(File.extname(file)) || (File.executable?(file) && !Dir.exist?(file)) || (File.executable_real?(file) && !Dir.exist?(file))
42
42
 
@@ -51,7 +51,7 @@ def unsupported_encoding(file)
51
51
  parse
52
52
  end
53
53
 
54
- def parse_directory(path)
54
+ def parse_directory(path, is_verbose = nil)
55
55
 
56
56
  files_array = []
57
57
 
@@ -63,11 +63,13 @@ def parse_directory(path)
63
63
  # if another directory then go inside
64
64
  if File.directory?(path + '/' + f)
65
65
 
66
+ puts ' - docme parsing path: ' + f if is_verbose
67
+
66
68
  files_array.concat parse_directory(path + '/' + f)
67
69
 
68
70
  else # else parse normally
69
71
 
70
- temp_page = parse_file(path + '/' + f)
72
+ temp_page = parse_file(path + '/' + f, is_verbose)
71
73
  files_array.push(temp_page) unless temp_page.nil? || temp_page.is_empty == true
72
74
 
73
75
  end
@@ -77,10 +79,12 @@ def parse_directory(path)
77
79
 
78
80
  end
79
81
 
80
- def parse_file(file)
82
+ def parse_file(file, is_verbose = nil)
81
83
 
82
84
  if File.file?(file) && File.exist?(file) && !file.rindex('.', 0) && !unsupported_encoding(file) && !unsupported_extension(file)
83
85
 
86
+ puts ' - docme parsing page: ' + file if is_verbose
87
+
84
88
  page = Page.new(file)
85
89
  page.parse_blocks
86
90
 
@@ -91,3 +95,24 @@ def parse_file(file)
91
95
  end
92
96
 
93
97
  end
98
+
99
+ def clean_directory(path, is_verbose = nil)
100
+ # for each file in the directory
101
+ Dir.foreach(path) do |f|
102
+
103
+ next if f == '.' || f == '..'
104
+
105
+ # if another directory then go inside
106
+ if File.directory?(path + '/' + f)
107
+
108
+ clean_directory(path + '/' + f)
109
+
110
+ else # else delete file
111
+
112
+ puts ' - docme removing file: ' + f if is_verbose
113
+
114
+ File.delete(path + '/' + f)
115
+
116
+ end
117
+ end
118
+ end
@@ -1,13 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
 
4
- <style type="text/css">
5
- #wrapper{
6
- width: 70%;
7
- padding-left: 30%;
8
- font-size:2em;
9
- }
10
- </style>
4
+ <link href="style.css" rel="stylesheet">
11
5
 
12
6
  <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
13
7
 
@@ -4,35 +4,8 @@
4
4
  <head>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
 
7
- <style type="text/css">
8
- body{
9
- }
10
- #panels-wrapper{
11
- width: 80%;
12
- float: left;
13
- padding-left: 10%;
14
- }
15
- #side-panel{
16
- width: 15%;
17
- float: left;
18
- padding-left: 10px;
19
- }
20
- pre-scrollable{
21
- overflow-x: scroll;
22
- white-space: nowrap;
23
- }
7
+ <link href="style.css" rel="stylesheet">
24
8
 
25
- p.code{
26
- border:1px solid #000000;
27
- overflow-x:scroll;
28
- white-space: pre;
29
- font-family:monospace,monospace;
30
- font-size:1em;
31
- background-color:#f5f5f5;
32
- padding:2em;
33
- }
34
-
35
- </style>
36
9
  </head>
37
10
 
38
11
  <link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
@@ -0,0 +1,29 @@
1
+ #wrapper{
2
+ width: 70%;
3
+ padding-left: 30%;
4
+ font-size:2em;
5
+ }
6
+ #panels-wrapper{
7
+ width: 80%;
8
+ float: left;
9
+ padding-left: 10%;
10
+ }
11
+ #side-panel{
12
+ width: 15%;
13
+ float: left;
14
+ padding-left: 10px;
15
+ }
16
+ pre-scrollable{
17
+ overflow-x: scroll;
18
+ white-space: nowrap;
19
+ }
20
+
21
+ p.code{
22
+ border:1px solid #000000;
23
+ overflow-x:scroll;
24
+ white-space: pre;
25
+ font-family:monospace,monospace;
26
+ font-size:1em;
27
+ background-color:#f5f5f5;
28
+ padding:2em;
29
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bailey Belvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem to support easy documentation for any file that recognizes `/*
14
14
  */` as a code block. This gem lets you easily parse multiple files in a directory
@@ -22,11 +22,14 @@ extra_rdoc_files: []
22
22
  files:
23
23
  - bin/docme
24
24
  - lib/docme.rb
25
+ - lib/docme/DocmeCLI.rb
25
26
  - lib/docme/block.rb
26
27
  - lib/docme/page.rb
28
+ - lib/docme/rake_task.rb
27
29
  - lib/docme/utils.rb
28
30
  - lib/templates/index.erb
29
31
  - lib/templates/page.erb
32
+ - lib/templates/style.erb
30
33
  homepage: https://github.com/philosowaffle/docme
31
34
  licenses:
32
35
  - Mozilla Public License