sc-docs 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,37 +8,38 @@ A tool to generate documentation for the SproutCore framework and SproutCore pro
8
8
  Usage
9
9
  -----
10
10
 
11
+ gem install sc-docs
12
+
13
+ *NOTE: If you are not using the latest version of SproutCore, the
14
+ built-in sc-docs command may conflict. This has been fixed in the newest
15
+ versions of SC.*
16
+
11
17
  ### Basic
12
18
 
13
- sc-docs --input_dir INPUT_DIRECTORY_PATH
19
+ sc-docs preview --input_dir INPUT_DIRECTORY_PATH \
20
+ --output_dir OUTPUT_DIRECTORY_PATH
14
21
 
15
22
  This documents the specified directory and then runs a preview sc-server instance.
16
23
 
17
24
  ### Deploy
18
25
 
19
- sc-docs --input_dir INPUT_DIRECTORY_PATH --deploy --project PROJECT_NAME \
26
+ sc-docs generate --input_dir INPUT_DIRECTORY_PATH \
20
27
  --output_dir = OUTPUT_DIRECTORY_PATH
21
28
 
22
- The deploy flag runs sc-build and deploys to the specified directory. If no output_dir is specified then it is deployed to `/Library/WebServer/Documents/`.
29
+ The generate command runs sc-build and deploys to the specified directory.
23
30
 
24
31
  ### HTML Templates
25
32
 
26
- sc-docs --input_dir INPUT_DIRECTORY_PATH --template TEMPLATE_PATH --html
33
+ sc-docs generate --input_dir INPUT_DIRECTORY_PATH \
34
+ --output_dir = OUTPUT_DIRECTORY_PATH \
35
+ --template TEMPLATE_PATH
36
+
27
37
 
28
- By default sc-docs assumes that you want to generate docs for the SproutCore based Doc Viewer. However, you can also generate standard HTML templates.
38
+ By default sc-docs assumes that you want to generate docs for the SproutCore based Doc Viewer. However, if you pass a template it will generate a standard HTML output.
29
39
 
30
40
  Dependencies
31
41
  ------------
32
42
 
33
- ### Gems
34
-
35
- * thor
36
- * child_labor
37
- * rack
38
- * thin *(optional, but recommended)*
39
-
40
- ### Other
41
-
42
43
  * **node.js**: We use a special (much faster) version of jsdoc-toolkit that requires node.js.
43
44
 
44
45
  Templates
@@ -0,0 +1 @@
1
+ require 'sc_docs'
@@ -5,43 +5,49 @@ require 'sc_docs/generator'
5
5
  module ScDocs
6
6
  class CLI < Thor
7
7
 
8
- class_option :input_dir, :aliases => ['-i'], :type => :string,
9
- :banner => "Directory to generate docs for"
10
- class_option :output_dir, :aliases => ['-o'], :type => :string,
11
- :banner => "Directory to output docs to"
12
8
  class_option :update, :aliases => ['-u'], :type => :boolean, :default => false,
13
9
  :banner => "If input is a git repo, pull and rebase"
14
10
  class_option :template, :aliases => ['-t'], :type => :string,
15
11
  :banner => "Path to jsdoc template (forces HTML output)"
16
12
  class_option :verbose, :aliases => ['-v'], :type => :boolean, :default => false
17
13
 
18
- desc "generate", "Generate docs"
14
+ desc "generate DIRECTORY", "Generate docs"
15
+ method_option :output_dir, :aliases => ['-o'], :type => :string, :required => true,
16
+ :banner => "Directory to output docs to"
19
17
  method_option :project, :aliases => ['-p'], :type => :string,
20
18
  :banner => "SproutCore Project Name"
21
- def generate
19
+ def generate(directory)
20
+
22
21
  puts "Generating Documentation...\n\n"
23
- run_generator
22
+ update_repo
23
+ generator(directory).generate
24
24
  end
25
25
 
26
- desc "preview", "Preview docs output"
27
- def preview
26
+ desc "preview DIRECTORY", "Preview docs output"
27
+ method_option :output_dir, :aliases => ['-o'], :type => :string, :required => false,
28
+ :banner => "Directory to output docs to (defaults to a tempfile)"
29
+ def preview(directory)
28
30
  puts "Building Documentation Preview...\n\n"
29
- run_generator(true)
31
+ update_repo
32
+ with_temp_output{ generator(directory).preview }
30
33
  end
31
34
 
32
35
  private
33
36
 
34
- def run_generator(preview=false)
35
- update_repo if options[:update]
37
+ def output_dir
38
+ @output_dir || options[:output_dir]
39
+ end
36
40
 
37
- puts options[:template]
38
- generator = (options[:template] ? HtmlGenerator : ScGenerator).new(options)
39
- preview ? generator.preview : generator.generate
41
+ def generator(directory)
42
+ opts = options.merge(:output_dir => output_dir)
43
+ (opts[:template] ? HtmlGenerator : ScGenerator).new(directory, opts)
40
44
  end
41
45
 
42
46
  def update_repo
47
+ return unless options[:update]
48
+
43
49
  puts "Updating repository...\n\n" if options[:verbose]
44
-
50
+
45
51
  if File.directory? input_dir and File.directory? "#{input_dir}/.git"
46
52
  Dir.chdir input_dir do
47
53
  run("git fetch", print_output)
@@ -50,5 +56,21 @@ module ScDocs
50
56
  end
51
57
  end
52
58
 
59
+ def with_temp_output
60
+ using_temp_dir = output_dir.nil? || output_dir.empty?
61
+
62
+ if using_temp_dir
63
+ require 'tempfile' # For Dir.tmpdir
64
+ @output_dir = File.join(Dir.tmpdir, "docs#{rand(100000)}")
65
+ end
66
+
67
+ yield
68
+ ensure
69
+ if using_temp_dir
70
+ FileUtils.rm_rf output_dir
71
+ @output_dir = nil # Probably not necessary
72
+ end
73
+ end
74
+
53
75
  end
54
76
  end
@@ -13,8 +13,8 @@ module ScDocs
13
13
 
14
14
  attr_reader :verbose
15
15
 
16
- def initialize(options={})
17
- @input_dir = File.expand_path(options[:input_dir])
16
+ def initialize(directory, options={})
17
+ @input_dir = File.expand_path(directory)
18
18
  @output_dir = File.expand_path(options[:output_dir])
19
19
  @verbose = options[:verbose]
20
20
  end
@@ -58,10 +58,11 @@ module ScDocs
58
58
  path = File.join(template, "output")
59
59
  if File.directory?(path)
60
60
  puts "Copying additional files" if verbose
61
+ # This is stupid, but necessary to copy only the contents
61
62
  Dir["#{path}/*"].each{|p| FileUtils.cp_r(p, output_dir) }
62
63
  end
63
64
  end
64
-
65
+
65
66
  def run_server
66
67
  Server.new(output_dir).start
67
68
  end
@@ -70,7 +71,7 @@ module ScDocs
70
71
 
71
72
  class HtmlGenerator < Generator
72
73
 
73
- def initialize(options={})
74
+ def initialize(directory, options={})
74
75
  super
75
76
  @template = File.expand_path(options[:template])
76
77
  end
@@ -80,10 +81,10 @@ module ScDocs
80
81
  class ScGenerator < Generator
81
82
 
82
83
  attr_reader :app_dir
83
-
84
+
84
85
  attr_reader :project_name
85
86
 
86
- def initialize(options={})
87
+ def initialize(directory, options={})
87
88
  super
88
89
  @template = File.expand_path("../templates/sc_fixture", __FILE__)
89
90
  @app_dir = File.expand_path(options[:output_dir])
@@ -100,10 +101,10 @@ module ScDocs
100
101
  private
101
102
 
102
103
  def prep
103
- target_dir = File.dirname(app_dir)
104
104
  FileUtils.rm_rf app_dir
105
- FileUtils.mkdir_p target_dir
106
- FileUtils.cp_r File.expand_path("../docs", __FILE__), target_dir
105
+ FileUtils.mkdir_p app_dir
106
+ # This is stupid, but necessary to copy only the contents
107
+ Dir[File.expand_path("../docs/*", __FILE__)].each{|f| FileUtils.cp_r f, app_dir }
107
108
  end
108
109
 
109
110
  def run_server
@@ -118,11 +119,11 @@ module ScDocs
118
119
  tmp_path = File.join(Dir.tmpdir, "docs#{rand(100000)}")
119
120
 
120
121
  FileUtils.mv app_dir, tmp_path
121
-
122
+
122
123
  Dir.chdir tmp_path
123
124
 
124
125
  build_cmd = "sc-build -r --languages=en --build-targets=docs --build=#{project_name}"
125
-
126
+
126
127
  puts "Deploying...\n\n"
127
128
 
128
129
  puts "#{build_cmd}\n\n" if verbose
@@ -131,15 +132,14 @@ module ScDocs
131
132
  FileUtils.rm_rf app_dir
132
133
  FileUtils.mkdir_p app_dir
133
134
 
134
- docs_dir = File.join(app_dir, "sc_docs")
135
- FileUtils.cp_r File.join(tmp_path, "tmp", "build", "sc_docs"), docs_dir
136
- FileUtils.cp File.join(docs_dir, "docs", "en", project_name, "index.html"), docs_dir
135
+ FileUtils.cp_r File.join(tmp_path, "tmp", "build", "sc_docs"), app_dir
136
+ FileUtils.cp File.join(app_dir, "sc_docs", "docs", "en", project_name, "index.html"), app_dir
137
137
 
138
138
  puts "Deployed"
139
139
 
140
140
  ensure
141
141
  FileUtils.rm_rf tmp_path
142
142
  end
143
-
143
+
144
144
  end
145
145
  end
@@ -1,4 +1,4 @@
1
1
  module ScDocs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
4
4
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sc-docs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Majd Taby
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-18 00:00:00 -07:00
14
+ date: 2011-05-19 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -54,6 +54,7 @@ files:
54
54
  - LICENSE
55
55
  - README.md
56
56
  - bin/sc-docs
57
+ - lib/sc-docs.rb
57
58
  - lib/sc_docs.rb
58
59
  - lib/sc_docs/cli.rb
59
60
  - lib/sc_docs/docs/Buildfile