cabbage_doc 0.1.2 → 0.1.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cabbage_doc.rb +7 -1
  3. data/lib/cabbage_doc/configuration.rb +5 -2
  4. data/lib/cabbage_doc/controller.rb +22 -11
  5. data/lib/cabbage_doc/highlighter.rb +23 -0
  6. data/lib/cabbage_doc/markdown.rb +28 -0
  7. data/lib/cabbage_doc/parser.rb +7 -3
  8. data/lib/cabbage_doc/response.rb +16 -8
  9. data/lib/cabbage_doc/task.rb +4 -3
  10. data/lib/cabbage_doc/version.rb +1 -1
  11. data/lib/cabbage_doc/web.rb +3 -2
  12. data/lib/cabbage_doc/web_helper.rb +11 -9
  13. data/web/public/css/highlight/github.css +185 -75
  14. data/web/public/css/highlight/molokai.css +208 -0
  15. data/web/public/css/highlight/monokai.css +202 -62
  16. data/web/public/css/highlight/thankful_eyes.css +173 -0
  17. data/web/public/css/{application.css → styles.css} +54 -3
  18. data/web/public/js/application.js +0 -9
  19. data/web/views/example.haml +1 -3
  20. data/web/views/layout.haml +3 -4
  21. data/web/views/page_layout.haml +4 -2
  22. data/web/views/response.haml +5 -10
  23. metadata +34 -51
  24. data/web/public/css/base.css +0 -23
  25. data/web/public/css/highlight/agate.css +0 -108
  26. data/web/public/css/highlight/androidstudio.css +0 -66
  27. data/web/public/css/highlight/arduino-light.css +0 -88
  28. data/web/public/css/highlight/arta.css +0 -73
  29. data/web/public/css/highlight/ascetic.css +0 -45
  30. data/web/public/css/highlight/codepen-embed.css +0 -60
  31. data/web/public/css/highlight/darkula.css +0 -74
  32. data/web/public/css/highlight/default.css +0 -99
  33. data/web/public/css/highlight/docco.css +0 -97
  34. data/web/public/css/highlight/dracula.css +0 -76
  35. data/web/public/css/highlight/foundation.css +0 -88
  36. data/web/public/css/highlight/github-gist.css +0 -71
  37. data/web/public/css/highlight/googlecode.css +0 -89
  38. data/web/public/css/highlight/grayscale.css +0 -101
  39. data/web/public/css/highlight/hybrid.css +0 -102
  40. data/web/public/css/highlight/idea.css +0 -97
  41. data/web/public/css/highlight/ir-black.css +0 -73
  42. data/web/public/css/highlight/magula.css +0 -70
  43. data/web/public/css/highlight/mono-blue.css +0 -59
  44. data/web/public/css/highlight/monokai-sublime.css +0 -83
  45. data/web/public/css/highlight/obsidian.css +0 -88
  46. data/web/public/css/highlight/purebasic.css +0 -96
  47. data/web/public/css/highlight/qtcreator_dark.css +0 -83
  48. data/web/public/css/highlight/qtcreator_light.css +0 -83
  49. data/web/public/css/highlight/railscasts.css +0 -106
  50. data/web/public/css/highlight/rainbow.css +0 -85
  51. data/web/public/css/highlight/school-book.css +0 -72
  52. data/web/public/css/highlight/solarized-dark.css +0 -84
  53. data/web/public/css/highlight/solarized-light.css +0 -84
  54. data/web/public/css/highlight/sunburst.css +0 -102
  55. data/web/public/css/highlight/vs.css +0 -68
  56. data/web/public/css/highlight/xcode.css +0 -93
  57. data/web/public/css/highlight/zenburn.css +0 -80
  58. data/web/public/js/highlight.min.js +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 055cffe940d79679c10fcea332f7c1bc6bad9d06
4
- data.tar.gz: 8721f7a7df58917bc532cf5540d1d96d0a50f47b
3
+ metadata.gz: 8687ddb9c4feafb097fd54ea3b603ac6138d4e25
4
+ data.tar.gz: 4e549353204ac6b35a41878eb62e353d5ddf33f8
5
5
  SHA512:
6
- metadata.gz: 32c88f44aeca133c811f1ae80b7592eea6ed682ba80f4378355d0ce9a5e84714b30a351ac7acebbb4a42400d8bfe24f2204ebb8dabf9844acc82e030cc798852
7
- data.tar.gz: ece56a88a5b0e29fd5125be604f301961e0471b52da71b1db455eaacdb48ca1b97fcf70cc684d28d476366128952ac3a7214a46b853079069beebcf5a7293c8f
6
+ metadata.gz: 55aebe211b945f70ffcecf9f6e9539c68168d465cee6cdcdc4f3c2e1b76775f102663df6b02ed6b402d0cbbe60ba3587040d06925ae04dd050b136b34565ab5b
7
+ data.tar.gz: 949cac1f4e673ec0ed97ca6acc05ee8c01c6bfd76c717370f59f5c4d9b4bf0794442efca37fca500b91872afe8c1e46a188bf13d4595d6a84cd939c9fa4d6cc2
data/lib/cabbage_doc.rb CHANGED
@@ -26,6 +26,8 @@ module CabbageDoc
26
26
  autoload :Task, 'cabbage_doc/task'
27
27
  autoload :Worker, 'cabbage_doc/worker'
28
28
  autoload :Cache, 'cabbage_doc/cache'
29
+ autoload :Markdown, 'cabbage_doc/markdown'
30
+ autoload :Highlighter, 'cabbage_doc/highlighter'
29
31
 
30
32
  class << self
31
33
  def configure
@@ -36,7 +38,11 @@ module CabbageDoc
36
38
  end
37
39
 
38
40
  def glob(*args)
39
- proc { Dir.glob(File.join(*args)).sort.reverse }
41
+ proc do
42
+ arr = args.first
43
+ arr = [args] unless arr.is_a?(Array)
44
+ arr.map { |segs| Dir.glob(File.join(*segs)) }.flatten.sort.reverse
45
+ end
40
46
  end
41
47
  end
42
48
  end
@@ -40,6 +40,9 @@ module CabbageDoc
40
40
  visibility: [VISIBILITY.first],
41
41
  cache: Cache.new,
42
42
  request: proc { |request| request.perform },
43
+ authentication: proc { |auth, request| },
44
+ confirm: proc { |tag| true },
45
+ templates: {},
43
46
  theme: 'github',
44
47
  examples: false,
45
48
  format_example: method(:format_example),
@@ -53,10 +56,10 @@ module CabbageDoc
53
56
 
54
57
  OPTIONAL_ATTRIBUTES = %i(welcome path scheme title verbose authentication dev request cache
55
58
  theme visibility examples format_example page_root page_ext
56
- asset_path auto_generate generators tags json).freeze
59
+ asset_path auto_generate generators tags json templates confirm).freeze
57
60
  REQUIRED_ATTRIBUTES = %i(domain controllers root).freeze
58
61
  ATTRIBUTES = (OPTIONAL_ATTRIBUTES + REQUIRED_ATTRIBUTES).freeze
59
- CALLABLE_ATTRIBUTES = %i(controllers authentication request format_example).freeze
62
+ CALLABLE_ATTRIBUTES = %i(controllers authentication request format_example confirm).freeze
60
63
 
61
64
  attr_accessor *ATTRIBUTES
62
65
 
@@ -35,20 +35,25 @@ module CabbageDoc
35
35
  def eval(text, tag)
36
36
  return [self] unless template?
37
37
 
38
- templates = []
38
+ templates = {}
39
39
 
40
- templates += parse_templates(@path)
41
- templates += parse_templates(@label)
40
+ templates.merge!(parse_templates(path, tag))
41
+ templates.merge!(parse_templates(label, tag))
42
+
43
+ yield_actions(text) do |action|
44
+ templates.merge!(parse_templates(action, tag))
45
+ end
42
46
 
43
47
  return [] unless templates.any?
44
48
 
45
- count = templates.first[:values].count
49
+ count = templates.values.first.count
50
+ return [] if templates.values.any? { |v| v.count != count }
46
51
 
47
- (1..count).map do |i|
52
+ count.times.map do |i|
48
53
  template_text = text.dup
49
54
 
50
- templates.each do |template|
51
- template_text.gsub!(template[:text], template[:values].shift.to_s)
55
+ templates.each do |text, values|
56
+ template_text.gsub!(text, values.shift.to_s)
52
57
  end
53
58
 
54
59
  self.class.parse(template_text, tag)
@@ -95,9 +100,9 @@ module CabbageDoc
95
100
  def parse_actions(text)
96
101
  actions = []
97
102
 
98
- text.scan(/(#\s*(#{VISIBILITY_REGEXP}):\s*.*?(#{Action::METHODS_REGEXP}):.*?def\s+.*?\s*#\s*#{MARKER})/m) do
99
- actions << Action.parse(parse_action($1))
100
- end
103
+ yield_actions(text) do |action|
104
+ actions << Action.parse(parse_action(action))
105
+ end
101
106
 
102
107
  actions.compact
103
108
  end
@@ -144,12 +149,18 @@ module CabbageDoc
144
149
  end
145
150
  end
146
151
 
152
+ def yield_actions(text)
153
+ text.scan(/(#\s*(#{VISIBILITY_REGEXP}):\s*.*?(#{Action::METHODS_REGEXP}):.*?def\s+.*?\s*#\s*#{MARKER})/m) do
154
+ yield $1
155
+ end
156
+ end
157
+
147
158
  def actions?
148
159
  @actions.any?
149
160
  end
150
161
 
151
162
  def template?
152
- @path =~ /\/{.*?,.*?}/
163
+ @path =~ /\/\{.*?\}/ || @label =~ /\{.*?\}/
153
164
  end
154
165
  end
155
166
  end
@@ -0,0 +1,23 @@
1
+ require 'rouge'
2
+
3
+ module CabbageDoc
4
+ class Highlighter
5
+ attr_accessor :formatter, :lexers
6
+
7
+ def initialize(options = {})
8
+ self.formatter = Rouge::Formatters::HTMLLegacy.new({ css_class: 'highlight' }.merge(options))
9
+ self.lexers = {}
10
+ end
11
+
12
+ def format(text, type = 'txt')
13
+ formatter.format(find_lexer(text, type).lex(text))
14
+ end
15
+
16
+ private
17
+
18
+ def find_lexer(text, type)
19
+ self.lexers[type.to_sym] ||= Rouge::Lexer.guess(source: text,
20
+ filename: "highlight.#{type}").new
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'redcarpet'
2
+ require 'rouge'
3
+ require 'rouge/plugins/redcarpet'
4
+
5
+ module CabbageDoc
6
+ module Markdown
7
+ class HighlightedHTML < Redcarpet::Render::HTML
8
+ include Rouge::Plugins::Redcarpet
9
+ end
10
+
11
+ class << self
12
+ def new
13
+ Redcarpet::Markdown.new(
14
+ HighlightedHTML.new,
15
+ tables: true,
16
+ fenced_code_blocks: true,
17
+ disable_indented_code_blocks: true,
18
+ autolink: true,
19
+ no_intra_emphasis: true,
20
+ strikethrough: true,
21
+ space_after_headers: true,
22
+ with_toc_data: true,
23
+ hard_wrap: true
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
@@ -34,11 +34,15 @@ module CabbageDoc
34
34
  end
35
35
  end
36
36
 
37
- def parse_templates(text)
38
- templates = []
37
+ def parse_templates(text, tag = TAG)
38
+ templates = {}
39
+
40
+ mappings = Configuration.instance.templates.fetch(tag.to_sym, {})
39
41
 
40
42
  text.scan(/(\{(.*?)\})/) do
41
- templates << { text: $1, values: $2.split(/,/).map(&:strip) }
43
+ text = $1.dup
44
+ values = Array(mappings.fetch(text, $2.split(/,/).map(&:strip)).dup)
45
+ templates[text] = values
42
46
  end
43
47
 
44
48
  templates
@@ -24,20 +24,28 @@ module CabbageDoc
24
24
 
25
25
  def to_json
26
26
  {
27
- url: url,
28
- query: params.to_query,
29
- code: code,
30
- headers: prettify(headers),
31
- body: prettify(body)
27
+ url: highlight(url.join),
28
+ query: highlight(params.to_query),
29
+ code: highlight(code.to_s),
30
+ headers: highlight(prettify(headers), :json),
31
+ body: highlight(prettify(body), :json)
32
32
  }.to_json
33
33
  end
34
34
 
35
35
  private
36
36
 
37
- def prettify(data)
38
- JSON.pretty_generate(data)
37
+ def highlight(text, type = :sh)
38
+ highlighter.format(text, type)
39
+ end
40
+
41
+ def highlighter
42
+ @_highlighter ||= Highlighter.new
43
+ end
44
+
45
+ def prettify(text)
46
+ JSON.pretty_generate(text)
39
47
  rescue
40
- data.to_s
48
+ text.to_s
41
49
  end
42
50
 
43
51
  def convert_headers(response)
@@ -3,7 +3,7 @@ require 'rake/tasklib'
3
3
 
4
4
  module CabbageDoc
5
5
  class Task < Rake::TaskLib
6
- attr_accessor :generators, :tags, :name, :customize
6
+ attr_accessor :generators, :tags, :name, :customize, :confirm
7
7
 
8
8
  def self.define
9
9
  new.tap do |instance|
@@ -19,6 +19,7 @@ module CabbageDoc
19
19
  self.tags = config.tags.dup
20
20
  self.name = :cabbagedoc
21
21
  self.customize = true
22
+ self.confirm = config.confirm
22
23
  end
23
24
 
24
25
  def config
@@ -58,7 +59,7 @@ module CabbageDoc
58
59
  generators.each do |type|
59
60
  desc "Generate #{type}"
60
61
  task type => :environment do
61
- Generator.perform(type)
62
+ Generator.perform(type) if confirm.call(:all)
62
63
  end
63
64
 
64
65
  define_generators_by_tag!(type)
@@ -74,7 +75,7 @@ module CabbageDoc
74
75
  tags.each do |tag|
75
76
  desc "Generate #{type} for #{tag}"
76
77
  task tag => :environment do
77
- Generator.perform(type, tag)
78
+ Generator.perform(type, tag) if confirm.call(tag)
78
79
  end
79
80
  end
80
81
  end
@@ -1,3 +1,3 @@
1
1
  module CabbageDoc
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
@@ -11,6 +11,8 @@ module CabbageDoc
11
11
  ROOT = File.expand_path("../../../web", __FILE__).freeze
12
12
 
13
13
  set :root, proc {
14
+ Configuration.instance.validate!
15
+
14
16
  dir = File.join(Configuration.instance.root, 'web')
15
17
  if Dir.exists?(dir)
16
18
  dir
@@ -44,8 +46,7 @@ module CabbageDoc
44
46
  response = config.request.call(post_request) if post_request.valid?
45
47
 
46
48
  if response.is_a?(Response)
47
- content_type :json
48
- response.to_json
49
+ format_json_response(response)
49
50
  elsif post_request.valid?
50
51
  response_by_id(post_request.id)
51
52
  else
@@ -1,5 +1,4 @@
1
1
  require 'erb'
2
- require 'redcarpet'
3
2
 
4
3
  module CabbageDoc
5
4
  module WebHelper
@@ -26,13 +25,12 @@ module CabbageDoc
26
25
  end
27
26
  end
28
27
 
28
+ def highlighter
29
+ @_highlighter ||= Highlighter.new
30
+ end
31
+
29
32
  def markdown
30
- @_markdown ||= Redcarpet::Markdown.new(
31
- Redcarpet::Render::HTML.new,
32
- tables: true,
33
- fenced_code_blocks: true,
34
- autolink: true
35
- )
33
+ @_markdown ||= Markdown.new
36
34
  end
37
35
 
38
36
  def eval_with_erb(text)
@@ -63,6 +61,11 @@ module CabbageDoc
63
61
  tag.to_s.capitalize
64
62
  end
65
63
 
64
+ def format_json_response(response)
65
+ content_type :json
66
+ response.to_json
67
+ end
68
+
66
69
  def post_request
67
70
  @_post_request ||= Request.new(request, collection)
68
71
  end
@@ -71,8 +74,7 @@ module CabbageDoc
71
74
  response = Worker.get(id)
72
75
 
73
76
  if response.is_a?(Response)
74
- content_type :json
75
- response.to_json
77
+ format_json_response(response)
76
78
  else
77
79
  status 503
78
80
  content_type :json
@@ -1,99 +1,209 @@
1
- /*
2
-
3
- github.com style (c) Vasily Polovnyov <vast@whiteants.net>
4
-
5
- */
6
-
7
- .hljs {
8
- display: block;
9
- overflow-x: auto;
10
- padding: 0.5em;
11
- color: #333;
12
- background: #f8f8f8;
13
- }
14
-
15
- .hljs-comment,
16
- .hljs-quote {
17
- color: #998;
1
+ .highlight table td { padding: 5px; }
2
+ .highlight table pre { margin: 0; }
3
+ .highlight .cm {
4
+ color: #999988;
18
5
  font-style: italic;
19
6
  }
20
-
21
- .hljs-keyword,
22
- .hljs-selector-tag,
23
- .hljs-subst {
24
- color: #333;
7
+ .highlight .cp {
8
+ color: #999999;
25
9
  font-weight: bold;
26
10
  }
27
-
28
- .hljs-number,
29
- .hljs-literal,
30
- .hljs-variable,
31
- .hljs-template-variable,
32
- .hljs-tag .hljs-attr {
33
- color: #008080;
11
+ .highlight .c1 {
12
+ color: #999988;
13
+ font-style: italic;
34
14
  }
35
-
36
- .hljs-string,
37
- .hljs-doctag {
38
- color: #d14;
15
+ .highlight .cs {
16
+ color: #999999;
17
+ font-weight: bold;
18
+ font-style: italic;
19
+ }
20
+ .highlight .c, .highlight .cd {
21
+ color: #999988;
22
+ font-style: italic;
23
+ }
24
+ .highlight .err {
25
+ color: #a61717;
26
+ background-color: #e3d2d2;
27
+ }
28
+ .highlight .gd {
29
+ color: #000000;
30
+ background-color: #ffdddd;
31
+ }
32
+ .highlight .ge {
33
+ color: #000000;
34
+ font-style: italic;
39
35
  }
40
-
41
- .hljs-title,
42
- .hljs-section,
43
- .hljs-selector-id {
44
- color: #900;
36
+ .highlight .gr {
37
+ color: #aa0000;
38
+ }
39
+ .highlight .gh {
40
+ color: #999999;
41
+ }
42
+ .highlight .gi {
43
+ color: #000000;
44
+ background-color: #ddffdd;
45
+ }
46
+ .highlight .go {
47
+ color: #888888;
48
+ }
49
+ .highlight .gp {
50
+ color: #555555;
51
+ }
52
+ .highlight .gs {
45
53
  font-weight: bold;
46
54
  }
47
-
48
- .hljs-subst {
49
- font-weight: normal;
55
+ .highlight .gu {
56
+ color: #aaaaaa;
50
57
  }
51
-
52
- .hljs-type,
53
- .hljs-class .hljs-title {
54
- color: #458;
58
+ .highlight .gt {
59
+ color: #aa0000;
60
+ }
61
+ .highlight .kc {
62
+ color: #000000;
55
63
  font-weight: bold;
56
64
  }
57
-
58
- .hljs-tag,
59
- .hljs-name,
60
- .hljs-attribute {
61
- color: #000080;
62
- font-weight: normal;
65
+ .highlight .kd {
66
+ color: #000000;
67
+ font-weight: bold;
68
+ }
69
+ .highlight .kn {
70
+ color: #000000;
71
+ font-weight: bold;
72
+ }
73
+ .highlight .kp {
74
+ color: #000000;
75
+ font-weight: bold;
76
+ }
77
+ .highlight .kr {
78
+ color: #000000;
79
+ font-weight: bold;
80
+ }
81
+ .highlight .kt {
82
+ color: #445588;
83
+ font-weight: bold;
84
+ }
85
+ .highlight .k, .highlight .kv {
86
+ color: #000000;
87
+ font-weight: bold;
88
+ }
89
+ .highlight .mf {
90
+ color: #009999;
91
+ }
92
+ .highlight .mh {
93
+ color: #009999;
94
+ }
95
+ .highlight .il {
96
+ color: #009999;
97
+ }
98
+ .highlight .mi {
99
+ color: #009999;
100
+ }
101
+ .highlight .mo {
102
+ color: #009999;
103
+ }
104
+ .highlight .m, .highlight .mb, .highlight .mx {
105
+ color: #009999;
106
+ }
107
+ .highlight .sb {
108
+ color: #d14;
109
+ }
110
+ .highlight .sc {
111
+ color: #d14;
112
+ }
113
+ .highlight .sd {
114
+ color: #d14;
63
115
  }
64
-
65
- .hljs-regexp,
66
- .hljs-link {
116
+ .highlight .s2 {
117
+ color: #d14;
118
+ }
119
+ .highlight .se {
120
+ color: #d14;
121
+ }
122
+ .highlight .sh {
123
+ color: #d14;
124
+ }
125
+ .highlight .si {
126
+ color: #d14;
127
+ }
128
+ .highlight .sx {
129
+ color: #d14;
130
+ }
131
+ .highlight .sr {
67
132
  color: #009926;
68
133
  }
69
-
70
- .hljs-symbol,
71
- .hljs-bullet {
134
+ .highlight .s1 {
135
+ color: #d14;
136
+ }
137
+ .highlight .ss {
72
138
  color: #990073;
73
139
  }
74
-
75
- .hljs-built_in,
76
- .hljs-builtin-name {
77
- color: #0086b3;
140
+ .highlight .s {
141
+ color: #d14;
142
+ }
143
+ .highlight .na {
144
+ color: #008080;
145
+ }
146
+ .highlight .bp {
147
+ color: #999999;
78
148
  }
79
-
80
- .hljs-meta {
81
- color: #999;
149
+ .highlight .nb {
150
+ color: #0086B3;
151
+ }
152
+ .highlight .nc {
153
+ color: #445588;
82
154
  font-weight: bold;
83
155
  }
84
-
85
- .hljs-deletion {
86
- background: #fdd;
156
+ .highlight .no {
157
+ color: #008080;
87
158
  }
88
-
89
- .hljs-addition {
90
- background: #dfd;
159
+ .highlight .nd {
160
+ color: #3c5d5d;
161
+ font-weight: bold;
91
162
  }
92
-
93
- .hljs-emphasis {
94
- font-style: italic;
163
+ .highlight .ni {
164
+ color: #800080;
95
165
  }
96
-
97
- .hljs-strong {
166
+ .highlight .ne {
167
+ color: #990000;
98
168
  font-weight: bold;
99
169
  }
170
+ .highlight .nf {
171
+ color: #990000;
172
+ font-weight: bold;
173
+ }
174
+ .highlight .nl {
175
+ color: #990000;
176
+ font-weight: bold;
177
+ }
178
+ .highlight .nn {
179
+ color: #555555;
180
+ }
181
+ .highlight .nt {
182
+ color: #000080;
183
+ }
184
+ .highlight .vc {
185
+ color: #008080;
186
+ }
187
+ .highlight .vg {
188
+ color: #008080;
189
+ }
190
+ .highlight .vi {
191
+ color: #008080;
192
+ }
193
+ .highlight .nv {
194
+ color: #008080;
195
+ }
196
+ .highlight .ow {
197
+ color: #000000;
198
+ font-weight: bold;
199
+ }
200
+ .highlight .o {
201
+ color: #000000;
202
+ font-weight: bold;
203
+ }
204
+ .highlight .w {
205
+ color: #bbbbbb;
206
+ }
207
+ .highlight {
208
+ background-color: #f8f8f8;
209
+ }