atech_docs 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/adp ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ unless File.directory?(ARGV.last)
3
+ $stderr.puts "Docs repo doesn't exist at #{ARGV.last}"
4
+ Process.exit(1)
5
+ end
6
+
7
+ require 'atech_docs/server'
8
+ AtechDocs::Server.run!
@@ -0,0 +1,49 @@
1
+ require 'rdiscount'
2
+ require 'coderay'
3
+
4
+ module AtechDocs
5
+ class Page
6
+
7
+ attr_reader :options
8
+
9
+ def initialize(path, raw)
10
+ @path = path
11
+ @content = raw
12
+ @options = Hash.new
13
+ set_options
14
+ end
15
+
16
+ ## Return the processed HTML content for this page.
17
+ def body
18
+ content = @content.strip
19
+
20
+ content.gsub!(/^\[([A-Z]+)\](.*)/) do
21
+ "<p class='#{$1.downcase}'>#{$2.strip}</p>"
22
+ end
23
+
24
+ markdown = RDiscount.new(content)
25
+ html = markdown.to_html
26
+ html.gsub!(/<pre><code>\[([\w\s\|]+)\]\n(.*?)<\/code><\/pre>/m) do
27
+ properties, code = $1, $2
28
+ syntax, title = properties.split('|', 2)
29
+ output = CodeRay.scan(code, syntax.to_sym).div(:css => :class)
30
+ output.gsub!('<div class="CodeRay">', "<div class='CodeRay'><p class='label'>#{title}</p>")
31
+ output
32
+ end
33
+
34
+ html
35
+ end
36
+
37
+ private
38
+
39
+ ## Return any options provided from within the document. This is any line which is
40
+ ## prefixed with two colons
41
+ def set_options
42
+ @content.gsub!(/^\:\:(\w+)\s+(.*)$/) do |f|
43
+ @options[$1.to_sym] = $2
44
+ ''
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'sinatra'
4
+ require File.expand_path('../page', __FILE__)
5
+
6
+ module AtechDocs
7
+ class Server < Sinatra::Base
8
+
9
+ set :public, File.expand_path('../../../public', __FILE__)
10
+ set :static, true
11
+
12
+ not_found { "Page not found"}
13
+
14
+ get '/doc.css' do
15
+ path = File.join(ARGV.last, 'style.css')
16
+ if File.exist?(path)
17
+ content_type 'text/css'
18
+ File.read(path)
19
+ end
20
+ end
21
+
22
+ get '/:application' do
23
+ redirect "/#{params[:application]}/"
24
+ end
25
+
26
+ get '/:application/*' do
27
+ if page = find(params[:application], params[:splat].join('/'))
28
+ String.new.tap do |s|
29
+ s << "<!DOCTYPE html>"
30
+ s << "<html><head><title>#{page.options[:title] || 'Untitled Page'}</title><link href='/style.css' media='screen' rel='stylesheet' type='text/css' /><link href='/doc.css' media='screen' rel='stylesheet' type='text/css' /></head>"
31
+ s << "<body>\n\n"
32
+ s << page.body
33
+ s << "</body></html>"
34
+ end
35
+ else
36
+ asset_path = File.join(ARGV.last, params[:application], params[:splat].join('/'))
37
+ if File.exist?(asset_path)
38
+ content_type 'image/png'
39
+ File.read(asset_path)
40
+ else
41
+ 404
42
+ end
43
+ end
44
+ end
45
+
46
+ def find(application, path)
47
+ request_path = [application, path].join('/')
48
+ path_to_file = File.join(ARGV.last, application, path)
49
+ if File.file?(path_to_file + '.doc')
50
+ Page.new(request_path, File.read(path_to_file + '.doc'))
51
+ elsif File.directory?(path_to_file) && File.join(path_to_file, 'index.doc')
52
+ Page.new(request_path, File.read(File.join(path_to_file, 'index.doc')))
53
+ else
54
+ nil
55
+ end
56
+ end
57
+
58
+ end
59
+ end
data/public/style.css ADDED
@@ -0,0 +1,4 @@
1
+ html { font-family:"Helvetica Neue", Arial;background:#efefef; font-size:12px;}
2
+ body { width:85%; background:#fff; border:10px solid #ccc; margin:20px auto;padding:10px 20px; -webkit-font-smoothing: antialiased;}
3
+
4
+ * { font-size:12px;}
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atech_docs
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 2
10
+ version: 1.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Adam Cooke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-02 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: sinatra
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rdiscount
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: coderay
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description:
64
+ email: adam@atechmedia.com
65
+ executables:
66
+ - adp
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - bin/adp
73
+ - lib/atech_docs/page.rb
74
+ - lib/atech_docs/server.rb
75
+ - public/style.css
76
+ has_rdoc: true
77
+ homepage: http://atechmedia.com
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.7
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Webserver and library for rendering and previewing documentation for the aTech Support SIte
110
+ test_files: []
111
+