frappuccino 0.0.1

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.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'frappuccino'
4
+
5
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
6
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
7
+
8
+ Frappuccino.new(ARGV[0], ARGV[1])
@@ -0,0 +1,140 @@
1
+ require "erb"
2
+ require "fileutils"
3
+ class Frappuccino
4
+ attr_writer :files, :documentations, :doctree, :title
5
+ def initialize title, files
6
+ if File.directory? files
7
+ docfiles = []
8
+ Dir.glob("#{files}/*").each do |file|
9
+ docfiles.push(file) unless File.directory? file
10
+ end
11
+ files = docfiles
12
+ end
13
+ @files = files
14
+ @documentations = []
15
+ @doctree = {:namespaces => {}}
16
+ @title = title
17
+ iterate_files
18
+ documentations_to_doctree
19
+ # sort alphabetically
20
+ @doctree[:namespaces] = @doctree[:namespaces].sort_by {|k,v| k}
21
+ generate_html
22
+ end
23
+
24
+ def iterate_files
25
+ for file in @files
26
+ File.open(file) do |opened_file|
27
+ puts "* Parsing documentation from #{file}"
28
+ collect_documentation opened_file
29
+ end
30
+ end
31
+ end
32
+
33
+ # parses documentation bodies
34
+ def collect_documentation opened_file
35
+ doc_start = false
36
+ current_documentation = []
37
+ opened_file.each_line do |line|
38
+ # documentation starts here
39
+ if line.include?("###") and !doc_start
40
+ doc_start = true
41
+ # documentation ends here
42
+ elsif line.include?("###") and doc_start
43
+ @documentations.push current_documentation
44
+ current_documentation = []
45
+ doc_start = false
46
+ # in the middle of documentation
47
+ elsif doc_start
48
+ current_documentation.push line
49
+ end
50
+ end
51
+ end
52
+
53
+ def documentations_to_doctree
54
+ @documentations.each do |docbody|
55
+ doctree_format docbody
56
+ end
57
+ end
58
+
59
+ # transforms array of strings to doctree hash
60
+ def doctree_format docbody
61
+ doctree = {}
62
+ value_regexp = /^.*:\s(.*)/
63
+ namespace_arr = []
64
+ namespace_tree = {}
65
+ function_name = nil
66
+ object_name = nil
67
+ description = ""
68
+ rest_is_description = false
69
+
70
+ docbody.each do |line|
71
+ if line.match(/^\s*function/)
72
+ function_name = line.match(value_regexp)[1]
73
+ elsif line.match(/^\s*object/)
74
+ object_name = line.match(value_regexp)[1]
75
+ elsif line.match(/^\s*description/)
76
+ rest_is_description = true
77
+ elsif line.match(/^\s*namespace/)
78
+ namespace_arr = line.match(value_regexp)[1].split(".")
79
+ elsif rest_is_description
80
+ description += line
81
+ end
82
+ end
83
+
84
+ full_namespace = namespace_arr.join(".")
85
+
86
+
87
+ if !function_name.nil?
88
+ docdata = {:full_namespace => full_namespace, :functions => [{:function_name => function_name, :description => description}]}
89
+ elsif !object_name.nil?
90
+ docdata = {:full_namespace => full_namespace, :objects => [{:object_name => object_name, :description => description}]}
91
+ else
92
+ if rest_is_description
93
+ docdata = {:full_namespace => full_namespace, :description => description}
94
+ else
95
+ docdata = {:full_namespace => full_namespace}
96
+ end
97
+ end
98
+
99
+ namespace_is_added = false
100
+ @doctree[:namespaces].each do |key, value|
101
+ namespace_is_added = true if key == full_namespace
102
+ end
103
+
104
+ if namespace_is_added
105
+ @doctree[:namespaces][full_namespace] = deep_safe_merge(@doctree[:namespaces][full_namespace], docdata)
106
+ else
107
+ @doctree[:namespaces][full_namespace] = docdata
108
+ end
109
+
110
+ end
111
+
112
+
113
+ def generate_html
114
+ template = ERB.new File.new("#{File.dirname(__FILE__)}/../template/index.erb").read
115
+ rendered_template = template.result(binding)
116
+ FileUtils.mkdir "docs" unless File.directory? "docs"
117
+ File.open("docs/index.html", "w") do |f|
118
+ f.write rendered_template
119
+ end
120
+ FileUtils.cp("#{File.dirname(__FILE__)}/../template/bg.png", "docs/bg.png")
121
+ puts "* Documentation file generated (docs/index.html)"
122
+ end
123
+
124
+ # helpers:
125
+
126
+ def deep_safe_merge(source_hash, new_hash)
127
+ source_hash.merge(new_hash) do |key, old, new|
128
+ if new.respond_to?(:blank) && new.blank?
129
+ old
130
+ elsif (old.kind_of?(Hash) and new.kind_of?(Hash))
131
+ deep_merge(old, new)
132
+ elsif (old.kind_of?(Array) and new.kind_of?(Array))
133
+ old.concat(new).uniq
134
+ else
135
+ new
136
+ end
137
+ end
138
+ end
139
+
140
+ end
Binary file
@@ -0,0 +1,191 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset=utf-8>
5
+ <title>
6
+ <%= @title %>
7
+ </title>
8
+ <style>
9
+ html, body {
10
+ height: 100%;
11
+ width: 100%;
12
+ background-image: ('bg.png');
13
+ margin: 0px;
14
+ padding: 0px;
15
+ font-family: Tahoma, Geneva, sans-serif;
16
+ color: #181818;
17
+ background-image: url(bg.png);
18
+ background-repeat: repeat-x;
19
+ background-color: #eee;
20
+ }
21
+
22
+ a {
23
+ text-decoration: none;
24
+ color: #181818;
25
+ }
26
+
27
+ aside {
28
+ position: fixed;
29
+ text-align: left;
30
+ width: 10%;
31
+ height: 100%;
32
+ float: left;
33
+ }
34
+
35
+ aside div {
36
+ text-align: left;
37
+ font-size: 30px;
38
+ font-weight: bold;
39
+ color: #00adee;
40
+ border-bottom: 1px solid #7db9e8;
41
+ margin-bottom: 20px;
42
+ }
43
+
44
+ aside ul {
45
+ list-style: none;
46
+ padding: 0px;
47
+ margin: 0px;
48
+ width: 100%;
49
+ }
50
+
51
+ aside ul li {
52
+ width: 100%;
53
+ margin-left: 6px;
54
+ font-size: 14px;
55
+ }
56
+
57
+ aside ul li a {
58
+ color: black;
59
+ }
60
+
61
+ aside ul li a:hover {
62
+ color: black;
63
+ }
64
+
65
+ section {
66
+ float: right;
67
+ width: 90%;
68
+ }
69
+
70
+ .master_box {
71
+ -webkit-border-radius: 15px;
72
+ padding: 25px;
73
+ margin: 50px;
74
+ background: white;
75
+ /* drop shadow follows (moar info: http://www.css3.info/preview/box-shadow/) */
76
+ -moz-border-radius: 15px;
77
+ border-radius: 15px;
78
+ -moz-box-shadow: 3px 3px 3px rgba(0,0,0,0.2);
79
+ -webkit-box-shadow: 3px 3px 3px rgba(0,0,0,0.2);
80
+ box-shadow: 3px 3px 3px rgba(0,0,0,0.2);
81
+ }
82
+
83
+ .box {
84
+ -webkit-border-radius: 15px;
85
+ padding: 25px;
86
+ margin: 50px;
87
+ margin-left: 100px;
88
+ background: white;
89
+ /* drop shadow follows (moar info: http://www.css3.info/preview/box-shadow/) */
90
+ -moz-border-radius: 15px;
91
+ border-radius: 15px;
92
+ -moz-box-shadow: 3px 3px 3px rgba(0,0,0,0.2);
93
+ -webkit-box-shadow: 3px 3px 3px rgba(0,0,0,0.2);
94
+ box-shadow: 3px 3px 3px rgba(0,0,0,0.2);
95
+
96
+ }
97
+
98
+ .title {
99
+ padding-left: 10px;
100
+ font-size: 18px;
101
+ font-weight: bold;
102
+ border-bottom: 1px solid #7db9e8;
103
+ color: #00adee;
104
+ }
105
+
106
+ .description {
107
+ font-size: 14px;
108
+ padding: 10px;
109
+ }
110
+
111
+ .master_title {
112
+ padding-left: 10px;
113
+ font-size: 22px;
114
+ font-weight: bold;
115
+ border-bottom: 1px solid #7db9e8;
116
+ color: #00adee;
117
+ }
118
+
119
+ .master_description {
120
+ font-size: 15px;
121
+ padding: 10px;
122
+ }
123
+
124
+ footer {
125
+ width: 100%;
126
+ font-size: 10px;
127
+ text-align: center;
128
+ }
129
+ </style>
130
+ <!--[if IE]>
131
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
132
+ <![endif]-->
133
+ </head>
134
+ <body>
135
+ <!-- descriptions -->
136
+ <section>
137
+ <% @doctree[:namespaces].each do |key, ns| %>
138
+ <a name="<%= ns[:full_namespace] %>"></a>
139
+ <div class="master_box">
140
+ <div class="master_title">
141
+ <%= ns[:full_namespace] %>
142
+ <div style="float:right;color:silver;font-size: 14px;font-weight:normal;font-style:italic;">namespace</div>
143
+ </div>
144
+ <div class="master_description">
145
+ <%= ns[:description].gsub!(" ", "&nbsp").gsub!("\n", "<br />") %>
146
+ </div>
147
+ </div>
148
+ <% if ns[:objects] %>
149
+ <% ns[:objects].each do |obj| %>
150
+ <div class="box">
151
+ <div class="title">
152
+ <%= "#{ns[:full_namespace]}.#{obj[:object_name]}" %>
153
+ <div style="float:right;color:silver;font-size: 12px;font-weight:normal;font-style:italic;">object</div>
154
+ </div>
155
+ <div class="description">
156
+ <%= obj[:description].gsub!(" ", "&nbsp").gsub!("\n", "<br />") %>
157
+ </div>
158
+ </div>
159
+ <% end %>
160
+ <% end %>
161
+ <% if ns[:functions] %>
162
+ <% ns[:functions].sort_by{|fn| fn[:function_name]}.each do |fn| %>
163
+ <div class="box">
164
+ <div class="title">
165
+ <%= "#{ns[:full_namespace]}.#{fn[:function_name]}" %>
166
+ <div style="float:right;color:silver;font-size: 12px;font-weight:normal;font-style:italic;">function</div>
167
+ </div>
168
+ <div class="description">
169
+ <%= fn[:description].gsub!(" ", "&nbsp").gsub!("\n", "<br />") %>
170
+ </div>
171
+ </div>
172
+ <% end %>
173
+ <% end %>
174
+ <div style="margin-bottom: 250px;"></div>
175
+ <% end %>
176
+ </section>
177
+ <!-- complete namespace tree w/ links -->
178
+ <aside>
179
+ <div><%= @title %></div>
180
+ <ul>
181
+ <% @doctree[:namespaces].each do |key, value| %>
182
+ <li><a href="#<%= key %>">-<%= key %></a></li>
183
+ <% end %>
184
+ </ul>
185
+ </aside>
186
+ <div style="clear:both;"></div>
187
+ <footer>
188
+ documentation was generated by frappuccino
189
+ </footer>
190
+ </body>
191
+ </html>
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frappuccino
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jesse Ikonen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-31 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Superdumb coffeescript documentation generator
18
+ email: jesse.ikonen@gmail.com
19
+ executables:
20
+ - frappuccino
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/frappuccino.rb
27
+ - template/bg.png
28
+ - template/index.erb
29
+ - bin/frappuccino
30
+ has_rdoc: true
31
+ homepage: ""
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ requirements: []
52
+
53
+ rubyforge_project: frappuccino
54
+ rubygems_version: 1.6.2
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Superdumb coffeescript documentation generator
58
+ test_files: []
59
+