docify 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,48 @@
1
+ = Docify
2
+
3
+ This gem allows you to render your documentation files (Rdoc/Markup/Textile) into nice-looking html files.
4
+
5
+ Produced result looks similar to GitHub's README and other doc files.
6
+
7
+ == Dependencies
8
+
9
+ * github/markup
10
+ * rdiscount
11
+ * RedCloth
12
+
13
+ == Installation
14
+
15
+ gem install docify
16
+
17
+ == Usage
18
+
19
+ Usage: docify [options] FILE
20
+ -l, --list List of all formats
21
+ -f, --format FORMAT Render as format
22
+ --no-css Disable css styling
23
+ -o, --output=PATH Output file path
24
+ -h, --help Show this information
25
+
26
+ By default docify will write result to terminal:
27
+
28
+ docify YOUR_FILE.rdoc
29
+
30
+ >> ...... rendered content
31
+
32
+ To save results just pass --output with filename
33
+
34
+ docify YOUR_FILE.rdoc --output ~/Desktop/file.html
35
+
36
+ Or use regular piping:
37
+
38
+ docify YOUR_FILE.rdoc > ~/Desktop/file.html
39
+
40
+ Format will be automatically detected from filename. But if you need to force your format just type:
41
+
42
+ docify YOUR_FILE.rdoc --format textile
43
+
44
+ Default format: Rdoc
45
+
46
+ == Authors
47
+
48
+ * Dan Sosedoff - http://github.com/sosedoff
@@ -0,0 +1,5 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:test) do |spec|
4
+ spec.pattern = 'spec/*_spec.rb'
5
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'rubygems'
7
+ require 'optparse'
8
+ require 'docify'
9
+
10
+ # ------------------------------------------------------------------------------
11
+ # Default options
12
+ # ------------------------------------------------------------------------------
13
+
14
+ options = {
15
+ :format => nil, # Render format
16
+ :output => nil, # Output filename
17
+ :use_css => true # Embedded CSS support
18
+ }
19
+
20
+ # ------------------------------------------------------------------------------
21
+ # Setup OptParser
22
+ # ------------------------------------------------------------------------------
23
+
24
+ optparse = OptionParser.new do |opts|
25
+ opts.banner = "Usage: docify [options] FILE"
26
+ opts.on('-l', '--list', 'List of all formats') do
27
+ puts "Formats:"
28
+ Docify::FORMATS.each { |f| puts "- #{f}" }
29
+ exit
30
+ end
31
+ opts.on('-f', '--format FORMAT', 'Render as format') do |f|
32
+ unless Docify.valid_format?(f)
33
+ puts "Invalid format!" ; exit
34
+ end
35
+ options[:format] = f
36
+ end
37
+ opts.on('--no-css', 'Disable css styling') { options[:use_css] = false }
38
+ opts.on('-o', '--output=PATH', 'Output file path') do |path|
39
+ options[:output] = path
40
+ end
41
+ opts.on('-h', '--help', "Show this information") { puts opts.to_s ; exit }
42
+ end
43
+
44
+ # ------------------------------------------------------------------------------
45
+ # Execute
46
+ # ------------------------------------------------------------------------------
47
+
48
+ begin
49
+ optparse.parse!
50
+ file = ARGV.shift.to_s.strip
51
+ unless file.empty?
52
+ begin
53
+ options[:format] = Docify.detect_format(file)
54
+ doc = Docify::Document.new(file)
55
+ doc.render(options[:format], options[:use_css])
56
+ if options[:output].nil?
57
+ puts doc.content
58
+ else
59
+ doc.save_to(options[:output])
60
+ end
61
+ rescue ArgumentError => e
62
+ puts "Error: #{e.message}"
63
+ exit
64
+ end
65
+ else
66
+ puts optparse.to_s
67
+ exit
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ require 'github/markup'
2
+
3
+ require 'docify/version'
4
+ require 'docify/format'
5
+ require 'docify/style'
6
+ require 'docify/document'
@@ -0,0 +1,48 @@
1
+ module Docify
2
+ class Document
3
+ attr_reader :path
4
+ attr_reader :content
5
+
6
+ # Initialize a new Document object with file path
7
+ def initialize(path)
8
+ raise ArgumentError, "File [#{path}] does not exist!" unless File.exists?(path)
9
+ raise ArgumentError, "File required!" unless File.file?(path)
10
+ @path = path
11
+ @content = ""
12
+ end
13
+
14
+ # Render document by specified format
15
+ def render(format, embed_css=true)
16
+ raise ArgumentError, 'Invalid format!' unless FORMATS.include?(format)
17
+ result = GitHub::Markup.render("doc.#{format}", File.read(@path))
18
+ if embed_css
19
+ params = {:title => File.basename(@path), :content => result}
20
+ params[:css] = Docify::CSS if embed_css
21
+ @content = template(params)
22
+ else
23
+ @content = result
24
+ end
25
+ @content
26
+ end
27
+
28
+ # Save rendered content into file
29
+ def save_to(path)
30
+ unless File.exists?(File.dirname(path))
31
+ raise ArgumentError, "Output path does not exist!"
32
+ end
33
+ if File.directory?(path)
34
+ raise ArgumentError, "Output path should be a file!"
35
+ end
36
+ File.open(path, 'w') { |f| f.write(@content) }
37
+ end
38
+
39
+ private
40
+
41
+ # Render template with provided data
42
+ def template(params={})
43
+ TEMPLATE.gsub(REGEX) do |m|
44
+ m = params[m.scan(REGEX).flatten.last.to_sym]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ module Docify
2
+ # All supported formats
3
+ FORMATS = ['rdoc', 'markdown', 'textile']
4
+
5
+ # Aliases for file extensions
6
+ ALIASES = {
7
+ '.rdoc' => 'rdoc',
8
+ '.textile' => 'textile',
9
+ '.markdown' => 'markdown',
10
+ '.md' => 'markdown'
11
+ }
12
+
13
+ # Returns true if provided format is supported
14
+ def self.valid_format?(f)
15
+ FORMATS.include?(f)
16
+ end
17
+
18
+ # Automatically detect format from extension
19
+ def self.detect_format(file)
20
+ ext = File.extname(file).downcase
21
+ ALIASES.key?(ext) ? ALIASES[ext] : FORMATS.first
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ module Docify
2
+ REGEX = /(\{\{([a-z\-\_]{1,})\}\})/i
3
+
4
+ TEMPLATE = <<END_TEMPLATE
5
+ <html>
6
+ <head>
7
+ <title>{{title}}</title>
8
+ {{css}}
9
+ </head>
10
+ <body>
11
+ <div id="content">{{content}}</div>
12
+ <!-- Generated with Docify -->
13
+ </body>
14
+ </html>
15
+ END_TEMPLATE
16
+
17
+ CSS = <<END_CSS
18
+ <style>
19
+ body {
20
+ background: #fff;
21
+ font: 13.34px helvetica,arial,freesans,clean,sans-serif;
22
+ }
23
+ #content { width: 80%; margin: 0px auto; }
24
+ pre {
25
+ margin: 1em 0;
26
+ font-size: 12px;
27
+ background-color: #eee;
28
+ border: 1px solid #ddd;
29
+ padding: 5px;
30
+ line-height: 1.5em;
31
+ color: #444;
32
+ overflow: auto;
33
+ -webkit-box-shadow:rgba(0,0,0,0.07) 0 1px 2px inset;
34
+ -webkit-border-radius:3px;
35
+ -moz-border-radius:3px;
36
+ border-radius:3px;
37
+ }
38
+ </style>
39
+ END_CSS
40
+ end
@@ -0,0 +1,3 @@
1
+ module Docify
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docify
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Dan Sosedoff
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-17 00:00:00 -05:00
19
+ default_executable: docify
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: github-markup
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 0
32
+ - 5
33
+ - 3
34
+ version: 0.5.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rdiscount
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 31
46
+ segments:
47
+ - 1
48
+ - 6
49
+ - 8
50
+ version: 1.6.8
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: RedCloth
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 4
64
+ - 2
65
+ - 3
66
+ version: 4.2.3
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: Docify provides a command line tool to render documentation files (RDoc, Markdown, Textile) into nice-looking html.
70
+ email: dan.sosedoff@gmail.com
71
+ executables:
72
+ - docify
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - Rakefile
79
+ - bin/docify
80
+ - lib/docify/document.rb
81
+ - lib/docify/format.rb
82
+ - lib/docify/style.rb
83
+ - lib/docify/version.rb
84
+ - lib/docify.rb
85
+ - README.rdoc
86
+ has_rdoc: true
87
+ homepage: http://github.com/sosedoff/docify
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.5.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Docify - Render documentation with favorite markup into html.
120
+ test_files: []
121
+