cabbage_doc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cabbage_doc.rb +2 -0
  3. data/lib/cabbage_doc/action.rb +14 -3
  4. data/lib/cabbage_doc/authentication.rb +8 -2
  5. data/lib/cabbage_doc/configuration.rb +10 -1
  6. data/lib/cabbage_doc/controller.rb +41 -9
  7. data/lib/cabbage_doc/version.rb +1 -1
  8. data/lib/cabbage_doc/web_helper.rb +8 -0
  9. data/web/public/css/application.css +16 -1
  10. data/web/views/action.haml +1 -0
  11. data/web/views/controller.haml +4 -1
  12. data/web/views/documentation.haml +2 -1
  13. metadata +2 -41
  14. data/web/public/css/highlight/atelier-cave-dark.css +0 -83
  15. data/web/public/css/highlight/atelier-cave-light.css +0 -85
  16. data/web/public/css/highlight/atelier-dune-dark.css +0 -69
  17. data/web/public/css/highlight/atelier-dune-light.css +0 -69
  18. data/web/public/css/highlight/atelier-estuary-dark.css +0 -84
  19. data/web/public/css/highlight/atelier-estuary-light.css +0 -84
  20. data/web/public/css/highlight/atelier-forest-dark.css +0 -69
  21. data/web/public/css/highlight/atelier-forest-light.css +0 -69
  22. data/web/public/css/highlight/atelier-heath-dark.css +0 -69
  23. data/web/public/css/highlight/atelier-heath-light.css +0 -69
  24. data/web/public/css/highlight/atelier-lakeside-dark.css +0 -69
  25. data/web/public/css/highlight/atelier-lakeside-light.css +0 -69
  26. data/web/public/css/highlight/atelier-plateau-dark.css +0 -84
  27. data/web/public/css/highlight/atelier-plateau-light.css +0 -84
  28. data/web/public/css/highlight/atelier-savanna-dark.css +0 -84
  29. data/web/public/css/highlight/atelier-savanna-light.css +0 -84
  30. data/web/public/css/highlight/atelier-seaside-dark.css +0 -69
  31. data/web/public/css/highlight/atelier-seaside-light.css +0 -69
  32. data/web/public/css/highlight/atelier-sulphurpool-dark.css +0 -69
  33. data/web/public/css/highlight/atelier-sulphurpool-light.css +0 -69
  34. data/web/public/css/highlight/brown-paper.css +0 -64
  35. data/web/public/css/highlight/color-brewer.css +0 -71
  36. data/web/public/css/highlight/dark.css +0 -63
  37. data/web/public/css/highlight/far.css +0 -71
  38. data/web/public/css/highlight/gruvbox-dark.css +0 -108
  39. data/web/public/css/highlight/gruvbox-light.css +0 -108
  40. data/web/public/css/highlight/hopscotch.css +0 -83
  41. data/web/public/css/highlight/kimbie.dark.css +0 -74
  42. data/web/public/css/highlight/kimbie.light.css +0 -74
  43. data/web/public/css/highlight/ocean.css +0 -74
  44. data/web/public/css/highlight/paraiso-dark.css +0 -72
  45. data/web/public/css/highlight/paraiso-light.css +0 -72
  46. data/web/public/css/highlight/pojoaque.css +0 -83
  47. data/web/public/css/highlight/tomorrow-night-blue.css +0 -75
  48. data/web/public/css/highlight/tomorrow-night-bright.css +0 -74
  49. data/web/public/css/highlight/tomorrow-night-eighties.css +0 -74
  50. data/web/public/css/highlight/tomorrow-night.css +0 -75
  51. data/web/public/css/highlight/tomorrow.css +0 -72
  52. data/web/public/css/highlight/xt256.css +0 -92
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27a236fc7439566b6ea5056fcd4fb3ef08697d7e
4
- data.tar.gz: f0cacbf8131c633330d0c5f08dc35bc77832a3bf
3
+ metadata.gz: f917cf99ef4214b287c6714f7e6d71d1a3f69b04
4
+ data.tar.gz: aba8fdad553277c3bfed0c2554ea3179a9f3c9d9
5
5
  SHA512:
6
- metadata.gz: 8d4a620a2020a673d25bd3706582e999183e2fb269795855154afb11873daa5263f2b235ee36584ea3dac7bc134f03342781bdb29690c4356f448ba08d70b816
7
- data.tar.gz: 49a35368edc2326a9c7a47838063226eb698c0baf9e80ea8917aa0dc786141411dfcbe09829e9370d5a3cc9e05631474e23bf036ca2921a578a6e8fbc7baa1fe
6
+ metadata.gz: 5f080b355f30ac79ec7fc630f5179876fda59ae6e872c76ce120e19723f17da0e91ab074f5fc8d7f9d898f934d4aa14987a54077744d8fe27c6fd25545b19222
7
+ data.tar.gz: 3da078b0c834baa3c8b0158166cb75f9029939c1782207a1f17857400d32fe56ee6e9df839482e1c70e8d877623174c3a70619beaabbdf9a43d223ef46afb3a1
data/lib/cabbage_doc.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module CabbageDoc
2
2
  MARKER = ':cabbagedoc:'.freeze
3
+ VISIBILITY = %i(public private internal).freeze
4
+ VISIBILITY_REGEXP = VISIBILITY.map(&:to_s).map(&:capitalize).join('|').freeze
3
5
 
4
6
  autoload :Path, 'cabbage_doc/path'
5
7
  autoload :Singleton, 'cabbage_doc/singleton'
@@ -5,11 +5,12 @@ module CabbageDoc
5
5
  METHODS = %w(GET POST PUT DELETE).freeze
6
6
  METHODS_REGEXP = METHODS.join('|').freeze
7
7
 
8
- attr_reader :label, :name, :description, :path, :method, :parameters, :examples
8
+ attr_reader :label, :name, :description, :path, :method, :parameters, :examples, :visibility
9
9
 
10
10
  def initialize
11
11
  @parameters = []
12
12
  @examples = []
13
+ @visibility = VISIBILITY.first
13
14
  end
14
15
 
15
16
  def parse(text)
@@ -19,6 +20,7 @@ module CabbageDoc
19
20
  @name = parse_name(text)
20
21
  @label = parse_label(text)
21
22
  @description = parse_description(text)
23
+ @visibility = parse_visibility(text)
22
24
 
23
25
  @parameters, @examples = parse_parameters_and_examples(text)
24
26
 
@@ -74,13 +76,22 @@ module CabbageDoc
74
76
  end
75
77
 
76
78
  def parse_label(text)
77
- m = text.match(/#\s*Public:(.*?)$/)
78
- m[1].strip if m
79
+ m = text.match(/#\s*(#{VISIBILITY_REGEXP}):(.*?)$/)
80
+ m[2].strip if m
79
81
  end
80
82
 
81
83
  def parse_description(text)
82
84
  m = text.match(/#\s*Description:(.*?)$/)
83
85
  m[1].strip if m
84
86
  end
87
+
88
+ def parse_visibility(text)
89
+ m = text.match(/#\s*(#{VISIBILITY_REGEXP}):(.*?)$/)
90
+ if m
91
+ m[1].strip.downcase.to_sym
92
+ else
93
+ VISIBILITY.first
94
+ end
95
+ end
85
96
  end
86
97
  end
@@ -20,7 +20,8 @@ module CabbageDoc
20
20
  :path,
21
21
  :user_agent,
22
22
  :configurable,
23
- :verbose
23
+ :verbose,
24
+ :visibility
24
25
 
25
26
  def initialize
26
27
  Configuration.instance.tap do |config|
@@ -28,14 +29,19 @@ module CabbageDoc
28
29
  @scheme = config.scheme
29
30
  @path = config.path
30
31
  @user_agent = config.title
32
+ @verbose = config.verbose
33
+ @visibility = config.visibility.dup
31
34
  end
32
35
 
33
- @verbose = false
34
36
  @subdomains = []
35
37
  @configurable = []
36
38
  @type = :basic
37
39
  end
38
40
 
41
+ def visibility=(value)
42
+ @visibility = Array(value)
43
+ end
44
+
39
45
  def uri
40
46
  if path && path != '/'
41
47
  "#{root_uri}/#{path}"
@@ -8,12 +8,13 @@ module CabbageDoc
8
8
  scheme: 'https',
9
9
  verbose: false,
10
10
  dev: false,
11
+ visibility: [VISIBILITY.first],
11
12
  cache: Cache.new,
12
13
  request: proc { |request| request.perform },
13
14
  theme: 'github'
14
15
  }.freeze
15
16
 
16
- OPTIONAL_ATTRIBUTES = %i(welcome path scheme title verbose authentication dev request cache theme).freeze
17
+ OPTIONAL_ATTRIBUTES = %i(welcome path scheme title verbose authentication dev request cache theme visibility).freeze
17
18
  REQUIRED_ATTRIBUTES = %i(domain controllers root).freeze
18
19
  ATTRIBUTES = (OPTIONAL_ATTRIBUTES + REQUIRED_ATTRIBUTES).freeze
19
20
  CALLABLE_ATTRIBUTES = %i(controllers authentication request).freeze
@@ -30,6 +31,7 @@ module CabbageDoc
30
31
  validate_required!
31
32
  validate_callable!
32
33
  validate_root!
34
+ validate_visibility!
33
35
  end
34
36
 
35
37
  private
@@ -51,5 +53,12 @@ module CabbageDoc
51
53
  def validate_root!
52
54
  raise ArgumentError, "#{root} directory doesn't exist" unless Dir.exists?(root)
53
55
  end
56
+
57
+ def validate_visibility!
58
+ self.visibility = Array(visibility)
59
+ self.visibility.each do |v|
60
+ raise ArgumentError, "#{v} invalid visibility" unless VISIBILITY.include?(v)
61
+ end
62
+ end
54
63
  end
55
64
  end
@@ -3,14 +3,15 @@ module CabbageDoc
3
3
  include Parser
4
4
  include Cloneable
5
5
 
6
- attr_reader :label, :klass, :name, :path, :actions
6
+ attr_reader :label, :klass, :name, :path, :actions, :visibility
7
7
 
8
8
  def initialize
9
9
  @actions = []
10
+ @visibility = VISIBILITY.first
10
11
  end
11
12
 
12
13
  def parse(text)
13
- @label, @path, @klass = parse_label_path_and_class(text)
14
+ @label, @path, @klass, @visibility = parse_label_path_class_and_visibility(text)
14
15
  return false unless @label && @klass
15
16
 
16
17
  @name = compose_name(klass)
@@ -67,45 +68,76 @@ module CabbageDoc
67
68
  compose_label({}, klass).downcase
68
69
  end
69
70
 
70
- def parse_label_path_and_class(text)
71
+ def compose_visbility(metadata)
72
+ metadata[:visibility] || :public
73
+ end
74
+
75
+ def parse_label_path_class_and_visibility(text)
71
76
  klass = parse_class(text)
72
77
  return unless klass
73
78
 
74
79
  metadata = parse_metadata(text)
75
80
 
76
- [compose_label(metadata, klass), compose_path(metadata, klass), klass]
81
+ [
82
+ compose_label(metadata, klass),
83
+ compose_path(metadata, klass),
84
+ klass,
85
+ compose_visbility(metadata)
86
+ ]
77
87
  end
78
88
 
79
89
  def parse_actions(text)
80
90
  actions = []
81
91
 
82
- text.scan(/(#\s*Public:\s*.*?(#{Action::METHODS_REGEXP}):.*?def\s+.*?\s*#\s*#{MARKER})/m) do
83
- actions << Action.parse($1.strip)
92
+ text.scan(/(#\s*(#{VISIBILITY_REGEXP}):\s*.*?(#{Action::METHODS_REGEXP}):.*?def\s+.*?\s*#\s*#{MARKER})/m) do
93
+ actions << Action.parse(parse_action($1))
84
94
  end
85
95
 
86
96
  actions.compact
87
97
  end
88
98
 
99
+ def parse_action(text)
100
+ new_text = text.strip
101
+
102
+ if new_text.scan(/#\s*(#{VISIBILITY_REGEXP}):\s*/).size > 1
103
+ new_text.sub(/#\s*(#{VISIBILITY_REGEXP}):.*?#\s*(#{VISIBILITY_REGEXP}):/m, '# \2:').strip
104
+ else
105
+ new_text
106
+ end
107
+ end
108
+
89
109
  def parse_class(text)
90
110
  m = text.match(/class\s+(.*?)\s+?#\s+?#{MARKER}$/)
91
111
  m[1].strip.split('<').first.strip if m
92
112
  end
93
113
 
94
114
  def parse_metadata(text)
95
- m = text.match(/(#\s*Public:\s*.*?class\s+.*?\s*#\s*#{MARKER})/m)
115
+ m = text.match(/(#\s*(#{VISIBILITY_REGEXP}):\s*.*?class\s+.*?\s*#\s*#{MARKER})/m)
96
116
  return {} unless m
97
117
 
98
118
  metadata = m[1].strip
99
119
 
100
120
  {}.tap do |hash|
101
- m = metadata.match(/#\s*Public:(.*?)$/)
102
- hash[:label] = m[1].strip if m
121
+ m = metadata.match(/#\s*(#{VISIBILITY_REGEXP}):(.*?)$/)
122
+ if m
123
+ hash[:visibility] = parse_visibility(m[1])
124
+ hash[:label] = m[2].strip
125
+ end
103
126
 
104
127
  m = metadata.match(/#\s*PATH:\s*\/(.*?)$/)
105
128
  hash[:path] = m[1].strip if m
106
129
  end
107
130
  end
108
131
 
132
+ def parse_visibility(text)
133
+ visibility = text.to_s.strip.downcase
134
+ if visibility.size > 0
135
+ visibility.to_sym
136
+ else
137
+ VISIBILITY.first
138
+ end
139
+ end
140
+
109
141
  def actions?
110
142
  @actions.any?
111
143
  end
@@ -1,3 +1,3 @@
1
1
  module CabbageDoc
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
@@ -40,6 +40,14 @@ module CabbageDoc
40
40
  @_auth ||= Authentication.new(request)
41
41
  end
42
42
 
43
+ def visible?(o)
44
+ auth.visibility.include?(o.visibility)
45
+ end
46
+
47
+ def format_visibility(o)
48
+ o.visibility.to_s.capitalize if o.visibility != VISIBILITY.first
49
+ end
50
+
43
51
  def post_request
44
52
  @_post_request ||= Request.new(request, collection)
45
53
  end
@@ -49,11 +49,27 @@ a:hover
49
49
  display: none !important;
50
50
  }
51
51
 
52
+ .left
53
+ {
54
+ float: left;
55
+ }
56
+
57
+ .right
58
+ {
59
+ float: right;
60
+ }
61
+
52
62
  .clear
53
63
  {
54
64
  clear: both;
55
65
  }
56
66
 
67
+ .visibility
68
+ {
69
+ font-style: italic;
70
+ float: right;
71
+ }
72
+
57
73
  .application
58
74
  {
59
75
  margin: 10px auto;
@@ -137,7 +153,6 @@ a:hover
137
153
 
138
154
  .action .subresource
139
155
  {
140
- float: left;
141
156
  line-height: 31px;
142
157
  }
143
158
 
@@ -4,6 +4,7 @@
4
4
  .subresource
5
5
  %a{ href: 'javascript:void(0);' }= action.path
6
6
  %span= " : #{action.label}"
7
+ %span.visibility= format_visibility(action)
7
8
  .clear
8
9
  %form.hidden{ action: action.path, method: action.method }
9
10
  - if action.description
@@ -2,6 +2,9 @@
2
2
  .resource
3
3
  %a{ href: 'javascript:void(0);' }= controller.path
4
4
  %span= " : #{controller.label}"
5
+ %span.visibility= format_visibility(controller)
6
+ .clear
5
7
  .actions.hidden
6
8
  - controller.actions.each do |action|
7
- = haml :action, locals: { action: action }
9
+ - if visible?(action)
10
+ = haml :action, locals: { action: action }
@@ -1,3 +1,4 @@
1
1
  .controllers
2
2
  - collection.each do |controller|
3
- = haml :controller, locals: { controller: controller }
3
+ - if visible?(controller)
4
+ = haml :controller, locals: { controller: controller }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cabbage_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mihail Szabolcs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -159,57 +159,24 @@ files:
159
159
  - web/public/css/highlight/arduino-light.css
160
160
  - web/public/css/highlight/arta.css
161
161
  - web/public/css/highlight/ascetic.css
162
- - web/public/css/highlight/atelier-cave-dark.css
163
- - web/public/css/highlight/atelier-cave-light.css
164
- - web/public/css/highlight/atelier-dune-dark.css
165
- - web/public/css/highlight/atelier-dune-light.css
166
- - web/public/css/highlight/atelier-estuary-dark.css
167
- - web/public/css/highlight/atelier-estuary-light.css
168
- - web/public/css/highlight/atelier-forest-dark.css
169
- - web/public/css/highlight/atelier-forest-light.css
170
- - web/public/css/highlight/atelier-heath-dark.css
171
- - web/public/css/highlight/atelier-heath-light.css
172
- - web/public/css/highlight/atelier-lakeside-dark.css
173
- - web/public/css/highlight/atelier-lakeside-light.css
174
- - web/public/css/highlight/atelier-plateau-dark.css
175
- - web/public/css/highlight/atelier-plateau-light.css
176
- - web/public/css/highlight/atelier-savanna-dark.css
177
- - web/public/css/highlight/atelier-savanna-light.css
178
- - web/public/css/highlight/atelier-seaside-dark.css
179
- - web/public/css/highlight/atelier-seaside-light.css
180
- - web/public/css/highlight/atelier-sulphurpool-dark.css
181
- - web/public/css/highlight/atelier-sulphurpool-light.css
182
- - web/public/css/highlight/brown-paper.css
183
162
  - web/public/css/highlight/codepen-embed.css
184
- - web/public/css/highlight/color-brewer.css
185
- - web/public/css/highlight/dark.css
186
163
  - web/public/css/highlight/darkula.css
187
164
  - web/public/css/highlight/default.css
188
165
  - web/public/css/highlight/docco.css
189
166
  - web/public/css/highlight/dracula.css
190
- - web/public/css/highlight/far.css
191
167
  - web/public/css/highlight/foundation.css
192
168
  - web/public/css/highlight/github-gist.css
193
169
  - web/public/css/highlight/github.css
194
170
  - web/public/css/highlight/googlecode.css
195
171
  - web/public/css/highlight/grayscale.css
196
- - web/public/css/highlight/gruvbox-dark.css
197
- - web/public/css/highlight/gruvbox-light.css
198
- - web/public/css/highlight/hopscotch.css
199
172
  - web/public/css/highlight/hybrid.css
200
173
  - web/public/css/highlight/idea.css
201
174
  - web/public/css/highlight/ir-black.css
202
- - web/public/css/highlight/kimbie.dark.css
203
- - web/public/css/highlight/kimbie.light.css
204
175
  - web/public/css/highlight/magula.css
205
176
  - web/public/css/highlight/mono-blue.css
206
177
  - web/public/css/highlight/monokai-sublime.css
207
178
  - web/public/css/highlight/monokai.css
208
179
  - web/public/css/highlight/obsidian.css
209
- - web/public/css/highlight/ocean.css
210
- - web/public/css/highlight/paraiso-dark.css
211
- - web/public/css/highlight/paraiso-light.css
212
- - web/public/css/highlight/pojoaque.css
213
180
  - web/public/css/highlight/purebasic.css
214
181
  - web/public/css/highlight/qtcreator_dark.css
215
182
  - web/public/css/highlight/qtcreator_light.css
@@ -219,14 +186,8 @@ files:
219
186
  - web/public/css/highlight/solarized-dark.css
220
187
  - web/public/css/highlight/solarized-light.css
221
188
  - web/public/css/highlight/sunburst.css
222
- - web/public/css/highlight/tomorrow-night-blue.css
223
- - web/public/css/highlight/tomorrow-night-bright.css
224
- - web/public/css/highlight/tomorrow-night-eighties.css
225
- - web/public/css/highlight/tomorrow-night.css
226
- - web/public/css/highlight/tomorrow.css
227
189
  - web/public/css/highlight/vs.css
228
190
  - web/public/css/highlight/xcode.css
229
- - web/public/css/highlight/xt256.css
230
191
  - web/public/css/highlight/zenburn.css
231
192
  - web/public/js/application.js
232
193
  - web/public/js/highlight.min.js
@@ -1,83 +0,0 @@
1
- /* Base16 Atelier Cave Dark - Theme */
2
- /* by Bram de Haan (http://atelierbram.github.io/syntax-highlighting/atelier-schemes/cave) */
3
- /* Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16) */
4
-
5
- /* Atelier-Cave Comment */
6
- .hljs-comment,
7
- .hljs-quote {
8
- color: #7e7887;
9
- }
10
-
11
- /* Atelier-Cave Red */
12
- .hljs-variable,
13
- .hljs-template-variable,
14
- .hljs-attribute,
15
- .hljs-regexp,
16
- .hljs-link,
17
- .hljs-tag,
18
- .hljs-name,
19
- .hljs-selector-id,
20
- .hljs-selector-class {
21
- color: #be4678;
22
- }
23
-
24
- /* Atelier-Cave Orange */
25
- .hljs-number,
26
- .hljs-meta,
27
- .hljs-built_in,
28
- .hljs-builtin-name,
29
- .hljs-literal,
30
- .hljs-type,
31
- .hljs-params {
32
- color: #aa573c;
33
- }
34
-
35
- /* Atelier-Cave Green */
36
- .hljs-string,
37
- .hljs-symbol,
38
- .hljs-bullet {
39
- color: #2a9292;
40
- }
41
-
42
- /* Atelier-Cave Blue */
43
- .hljs-title,
44
- .hljs-section {
45
- color: #576ddb;
46
- }
47
-
48
- /* Atelier-Cave Purple */
49
- .hljs-keyword,
50
- .hljs-selector-tag {
51
- color: #955ae7;
52
- }
53
-
54
- .hljs-deletion,
55
- .hljs-addition {
56
- color: #19171c;
57
- display: inline-block;
58
- width: 100%;
59
- }
60
-
61
- .hljs-deletion {
62
- background-color: #be4678;
63
- }
64
-
65
- .hljs-addition {
66
- background-color: #2a9292;
67
- }
68
-
69
- .hljs {
70
- display: block;
71
- overflow-x: auto;
72
- background: #19171c;
73
- color: #8b8792;
74
- padding: 0.5em;
75
- }
76
-
77
- .hljs-emphasis {
78
- font-style: italic;
79
- }
80
-
81
- .hljs-strong {
82
- font-weight: bold;
83
- }