docs 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
File without changes
data/bin/docs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'docs'
3
- Docs::Docs.start
3
+ Docs::Project.start
data/lib/docs.rb CHANGED
@@ -5,17 +5,3 @@ require "docs/version"
5
5
  require "docs/project"
6
6
  require "docs/config"
7
7
  require "docs/erb_environment"
8
-
9
- module Docs
10
- class Docs < Thor
11
-
12
- desc "build [DIRECTORY]", "Builds the current directory (or DIRECTORY) as a docs project into './output'"
13
- def build(directory = '.')
14
- previous_directory = Dir.pwd
15
- Dir.chdir(directory)
16
- Project.new.build
17
- Dir.chdir(previous_directory)
18
- end
19
-
20
- end
21
- end
data/lib/docs/config.rb CHANGED
@@ -20,7 +20,7 @@ module Docs
20
20
  if @config.has_key?(name)
21
21
  @config[name]
22
22
  else
23
- super
23
+ super(name, *args, &block)
24
24
  end
25
25
  end
26
26
  end
@@ -14,7 +14,11 @@ module Docs
14
14
  end
15
15
 
16
16
  def pretty_print_json(json)
17
- JSON.pretty_generate(JSON.parse(json))
17
+ begin
18
+ JSON.pretty_generate(JSON.parse(json))
19
+ rescue JSON::ParserError => e
20
+ e.inspect
21
+ end
18
22
  end
19
23
 
20
24
  def syntax_highlight(str, language)
data/lib/docs/project.rb CHANGED
@@ -5,28 +5,36 @@ require 'erb'
5
5
  require 'redcarpet'
6
6
 
7
7
  module Docs
8
- class Project
8
+ class Project < Thor
9
+
10
+ include Thor::Actions
9
11
 
10
12
  EXTENSIONS_TO_COMMANDS = {
11
13
  '.sh' => 'bash',
12
14
  '.rb' => 'ruby'
13
15
  }
14
16
 
15
- def initialize
17
+ desc "setup [DIRECTORY]", "Creates a new Docs Project"
18
+ def setup(directory = '.')
19
+ nil
20
+ end
21
+
22
+ desc "build", "Builds the current directory as a docs project into './output'"
23
+ def build
16
24
  @examples = {:source => {}, :output => {}}
17
25
  @erb_environment = ERBEnvironment.new
18
-
19
26
  @markdown = markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
20
- @erb_environment.config = @config = Config.new('config.yaml') if File.exists?('config.yaml')
21
- end
22
27
 
23
- def build
24
- create_tmp_directory
25
- truncate_or_create_output_directory
28
+ @erb_environment.config = @config = Config.new('config.yaml')
29
+ ['temp', 'output'].each do |dir|
30
+ dir = @config.directories[dir]
31
+ remove_file dir if File.exists? dir
32
+ empty_directory dir
33
+ end
26
34
 
27
35
  load_examples
28
36
  build_docs
29
- copy_public
37
+ copy_assets
30
38
  end
31
39
 
32
40
  private
@@ -37,15 +45,15 @@ module Docs
37
45
 
38
46
  example_file = example_name
39
47
  if File.fnmatch?('*.erb.*', example_name)
40
- File.open(example_file = "tmp/#{Digest::MD5.hexdigest(example_name)}#{File.extname(example_name)}", 'w+') do |f|
41
- f.write(render_erb_string File.read(example_name))
42
- end
48
+ create_file (example_file = "tmp/#{Digest::MD5.hexdigest(example_name)}#{File.extname(example_name)}"), render_erb_string(File.read(example_name))
43
49
  end
44
50
 
45
51
  @examples[:source][example_name] = File.read(example_file)
46
52
 
47
- i = IO.popen("#{EXTENSIONS_TO_COMMANDS[File.extname(example_file)]} #{example_file}")
48
- @examples[:output][example_name] = i.read
53
+ unless EXTENSIONS_TO_COMMANDS[File.extname(example_file)].nil?
54
+ i = IO.popen("#{EXTENSIONS_TO_COMMANDS[File.extname(example_file)]} #{example_file}")
55
+ @examples[:output][example_name] = i.read
56
+ end
49
57
  end
50
58
 
51
59
  @erb_environment.examples = @examples
@@ -64,9 +72,7 @@ module Docs
64
72
  rendered = render_erb_string File.read(@config.template)
65
73
  end
66
74
 
67
- File.open(output_name, 'w+') do |f|
68
- f.write rendered
69
- end
75
+ create_file output_name, rendered
70
76
  end
71
77
  end
72
78
 
@@ -80,14 +86,18 @@ module Docs
80
86
  def render_erb_string(str)
81
87
  ERB.new(str).result(@erb_environment.get_binding)
82
88
  end
83
-
84
- def truncate_or_create_output_directory
85
- FileUtils.rm_rf('output') if Dir.exists?('output')
86
- Dir.mkdir('output')
89
+
90
+ def in_directory(directory, &block)
91
+ previous_directory = Dir.pwd
92
+ Dir.chdir(directory)
93
+ yield
94
+ Dir.chdir(previous_directory)
87
95
  end
88
96
 
89
- def create_tmp_directory
90
- Dir.mkdir('tmp') unless Dir.exists?('tmp')
97
+ def copy_assets
98
+ Dir.glob(@config.directories['assets'] + '/**/*').each do |f|
99
+ create_file "#{@config.directories['output']}/#{f.sub('public/', '')}", File.read(f)
100
+ end
91
101
  end
92
102
 
93
103
  end
data/lib/docs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Docs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70167636469260 !ruby/object:Gem::Requirement
16
+ requirement: &70177518374340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.14.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70167636469260
24
+ version_requirements: *70177518374340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &70167636468760 !ruby/object:Gem::Requirement
27
+ requirement: &70177518373840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70167636468760
35
+ version_requirements: *70177518373840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: coderay
38
- requirement: &70167636468300 !ruby/object:Gem::Requirement
38
+ requirement: &70177518373380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.0.5
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70167636468300
46
+ version_requirements: *70177518373380
47
47
  description: Documentation generator with support for including code examples and
48
48
  compiling them at compile time
49
49
  email:
@@ -55,6 +55,7 @@ extra_rdoc_files: []
55
55
  files:
56
56
  - .gitignore
57
57
  - Gemfile
58
+ - README
58
59
  - Rakefile
59
60
  - bin/docs
60
61
  - docs.gemspec