mustermann-contrib 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1239 -0
  3. data/examples/highlighting.rb +35 -0
  4. data/highlighting.png +0 -0
  5. data/irb.png +0 -0
  6. data/lib/mustermann/cake.rb +18 -0
  7. data/lib/mustermann/express.rb +37 -0
  8. data/lib/mustermann/file_utils.rb +217 -0
  9. data/lib/mustermann/file_utils/glob_pattern.rb +39 -0
  10. data/lib/mustermann/fileutils.rb +1 -0
  11. data/lib/mustermann/flask.rb +198 -0
  12. data/lib/mustermann/grape.rb +35 -0
  13. data/lib/mustermann/pyramid.rb +28 -0
  14. data/lib/mustermann/rails.rb +46 -0
  15. data/lib/mustermann/shell.rb +56 -0
  16. data/lib/mustermann/simple.rb +50 -0
  17. data/lib/mustermann/string_scanner.rb +313 -0
  18. data/lib/mustermann/strscan.rb +1 -0
  19. data/lib/mustermann/template.rb +62 -0
  20. data/lib/mustermann/uri_template.rb +1 -0
  21. data/lib/mustermann/versions.rb +46 -0
  22. data/lib/mustermann/visualizer.rb +38 -0
  23. data/lib/mustermann/visualizer/highlight.rb +137 -0
  24. data/lib/mustermann/visualizer/highlighter.rb +37 -0
  25. data/lib/mustermann/visualizer/highlighter/ad_hoc.rb +94 -0
  26. data/lib/mustermann/visualizer/highlighter/ast.rb +102 -0
  27. data/lib/mustermann/visualizer/highlighter/composite.rb +45 -0
  28. data/lib/mustermann/visualizer/highlighter/dummy.rb +18 -0
  29. data/lib/mustermann/visualizer/highlighter/regular.rb +104 -0
  30. data/lib/mustermann/visualizer/pattern_extension.rb +68 -0
  31. data/lib/mustermann/visualizer/renderer/ansi.rb +23 -0
  32. data/lib/mustermann/visualizer/renderer/generic.rb +46 -0
  33. data/lib/mustermann/visualizer/renderer/hansi_template.rb +34 -0
  34. data/lib/mustermann/visualizer/renderer/html.rb +50 -0
  35. data/lib/mustermann/visualizer/renderer/sexp.rb +37 -0
  36. data/lib/mustermann/visualizer/tree.rb +63 -0
  37. data/lib/mustermann/visualizer/tree_renderer.rb +78 -0
  38. data/mustermann-contrib.gemspec +19 -0
  39. data/spec/cake_spec.rb +90 -0
  40. data/spec/express_spec.rb +209 -0
  41. data/spec/file_utils_spec.rb +119 -0
  42. data/spec/flask_spec.rb +361 -0
  43. data/spec/flask_subclass_spec.rb +368 -0
  44. data/spec/grape_spec.rb +747 -0
  45. data/spec/pattern_extension_spec.rb +49 -0
  46. data/spec/pyramid_spec.rb +101 -0
  47. data/spec/rails_spec.rb +647 -0
  48. data/spec/shell_spec.rb +147 -0
  49. data/spec/simple_spec.rb +268 -0
  50. data/spec/string_scanner_spec.rb +271 -0
  51. data/spec/template_spec.rb +841 -0
  52. data/spec/visualizer_spec.rb +199 -0
  53. data/theme.png +0 -0
  54. data/tree.png +0 -0
  55. metadata +126 -0
@@ -0,0 +1,199 @@
1
+ require 'support'
2
+ require 'mustermann/visualizer'
3
+
4
+ describe Mustermann::Visualizer do
5
+ subject(:highlight) { Mustermann::Visualizer.highlight(pattern) }
6
+ before { Hansi.mode = 256 }
7
+ after { Hansi.mode = nil }
8
+
9
+ describe :highlight do
10
+ context :sinatra do
11
+ context "/a" do
12
+ let(:pattern) { Mustermann.new("/a") }
13
+ its(:to_ansi) { should be == "\e[0m\e[38;5;246m\e[38;5;246m\e[38;5;247m/\e[0m\e[38;5;246m\e[38;5;246m\e[38;5;246ma\e[0m" }
14
+ its(:to_html) { should be == '<span style="color: #839496;"><span style="color: #93a1a1;">/</span><span style="color: #839496;">a</span></span></span>' }
15
+ its(:to_sexp) { should be == '(root (separator /) (char a))' }
16
+ its(:to_pattern) { should be == pattern }
17
+ its(:to_s) { should be == "/a" }
18
+ its(:stylesheet) { should include(".mustermann_pattern .mustermann_illegal {\n color: #8b0000;") }
19
+
20
+ example do
21
+ highlight.to_html(css: false).should be ==
22
+ '<span class="mustermann_pattern"><span class="mustermann_root"><span class="mustermann_separator">/</span><span class="mustermann_char">a</span></span></span>'
23
+ end
24
+
25
+ example do
26
+ renderer = Mustermann::Visualizer::Renderer::Generic
27
+ result = highlight.render_with(renderer)
28
+ result.should be == pattern.to_s
29
+ end
30
+ end
31
+
32
+ context '/:name' do
33
+ let(:pattern) { Mustermann.new("/:name") }
34
+ its(:to_sexp) { should be == "(root (separator /) (capture : (name name)))" }
35
+ end
36
+
37
+ context '/{name}' do
38
+ let(:pattern) { Mustermann.new("/{name}") }
39
+ its(:to_sexp) { should be == "(root (separator /) (capture { (name name) }))" }
40
+ end
41
+
42
+ context '/{+name}' do
43
+ let(:pattern) { Mustermann.new("/{+name}") }
44
+ its(:to_sexp) { should be == "(root (separator /) (named_splat {+ (name name) }))" }
45
+ end
46
+
47
+ context ':user(@:host)?' do
48
+ let(:pattern) { Mustermann.new(':user(@:host)?') }
49
+ its(:to_sexp) { should be == '(root (capture : (name user)) (optional (group "(" (char @) (capture : (name host)) ")") ?))' }
50
+ end
51
+
52
+ context 'a b' do
53
+ let(:pattern) { Mustermann.new('a b') }
54
+ its(:to_sexp) { should be == '(root (char a) (char " ") (char b))' }
55
+ end
56
+
57
+ context 'a|b' do
58
+ let(:pattern) { Mustermann.new('a|b') }
59
+ its(:to_sexp) { should be == '(root (union (char a) | (char b)))' }
60
+ end
61
+
62
+ context '(a|b)' do
63
+ let(:pattern) { Mustermann.new('(a|b)c') }
64
+ its(:to_sexp) { should be == '(root (union "(" (char a) | (char b) ")") (char c))' }
65
+ end
66
+
67
+ context '\:a' do
68
+ let(:pattern) { Mustermann.new('\:a') }
69
+ its(:to_sexp) { should be == '(root (escaped "\\\\" (escaped_char :)) (char a))' }
70
+ end
71
+ end
72
+
73
+ context :regexp do
74
+ context 'a' do
75
+ let(:pattern) { Mustermann.new('a', type: :regexp) }
76
+ its(:to_sexp) { should be == '(root (char a))' }
77
+ end
78
+
79
+ context '/(\d+)' do
80
+ let(:pattern) { Mustermann.new('/(\d+)', type: :regexp) }
81
+ its(:to_sexp) { should be == '(root (separator /) (capture "(" (special "\\\\d") (special +))))' }
82
+ end
83
+
84
+ context '\A' do
85
+ let(:pattern) { Mustermann.new('\A', type: :regexp, check_anchors: false) }
86
+ its(:to_sexp) { should be == '(root (illegal "\\\\A"))' }
87
+ end
88
+
89
+ context '(?<name>.)\g<name>' do
90
+ let(:pattern) { Mustermann.new('(?<name>.)\g<name>', type: :regexp) }
91
+ its(:to_sexp) { should be == '(root (capture "(?<" (name name) >(special .))) (special "\\\\g<name>"))' }
92
+ end
93
+
94
+ context '\p{Ll}' do
95
+ let(:pattern) { Mustermann.new('\p{Ll}', type: :regexp) }
96
+ its(:to_sexp) { should be == '(root (special "\\\\p{Ll}"))' }
97
+ end
98
+
99
+ context '\/' do
100
+ let(:pattern) { Mustermann.new('\/', type: :regexp) }
101
+ its(:to_sexp) { should be == '(root (separator /))' }
102
+ end
103
+
104
+ context '\[' do
105
+ let(:pattern) { Mustermann.new('\[', type: :regexp) }
106
+ its(:to_sexp) { should be == '(root (escaped "\\\\" (escaped_char [)))' }
107
+ end
108
+
109
+ context '^' do
110
+ let(:pattern) { Mustermann.new('^', type: :regexp, check_anchors: false) }
111
+ its(:to_sexp) { should be == '(root (illegal ^))' }
112
+ end
113
+
114
+ context '(?-mix:.)' do
115
+ let(:pattern) { Mustermann.new('(?-mix:.)', type: :regexp) }
116
+ its(:to_sexp) { should be == '(root (special "(?-mix:") (special .) (special ")"))' }
117
+ end
118
+
119
+ context '[a\d]' do
120
+ let(:pattern) { Mustermann.new('[a\d]', type: :regexp) }
121
+ its(:to_sexp) { should be == '(root (special [) (char a) (special "\\\\d") (special ]))' }
122
+ end
123
+
124
+ context '[^a-z]' do
125
+ let(:pattern) { Mustermann.new('[^a-z]', type: :regexp) }
126
+ its(:to_sexp) { should be == '(root (special [) (special ^) (char a) (special -) (char z) (special ]))' }
127
+ end
128
+
129
+ context '[[:digit:]]' do
130
+ let(:pattern) { Mustermann.new('[[:digit:]]', type: :regexp) }
131
+ its(:to_sexp) { should be == '(root (special [[:digit:]]))' }
132
+ end
133
+
134
+ context 'a{1,}' do
135
+ let(:pattern) { Mustermann.new('a{1,}', type: :regexp) }
136
+ its(:to_sexp) { should be == "(root (char a) (special {1,}))" }
137
+ end
138
+ end
139
+
140
+ context :template do
141
+ context '/{name}' do
142
+ let(:pattern) { Mustermann.new("/{+foo,bar*}", type: :template) }
143
+ its(:to_sexp) { should be == "(root (separator /) (expression {+ (variable (name foo)) , (variable (name bar) *) }))" }
144
+ end
145
+ end
146
+
147
+ context "custom AST based pattern" do
148
+ let(:my_type) { Class.new(Mustermann::AST::Pattern) { on('x') { |*| node(:char, "o") } }}
149
+ let(:pattern) { Mustermann.new("fxx", type: my_type) }
150
+ its(:to_sexp) { should be == "(root (char f) (escaped x) (escaped x))" }
151
+ end
152
+
153
+ context "without known highlighter" do
154
+ let(:pattern) { Mustermann::Pattern.new("foo") }
155
+ its(:to_sexp) { should be == "(root (unknown foo))" }
156
+ end
157
+
158
+ context :composite do
159
+ let(:pattern) { Mustermann.new(":a", ":b") ^ Mustermann.new(":c") }
160
+ its(:to_sexp) do
161
+ should be == '(composite (quote "(") (composite (type sinatra:) (quote "\\"") ' \
162
+ '(root (capture : (name a))) (quote "\\"") (quote " | ") (type sinatra:) (quote ' \
163
+ '"\\"") (root (capture : (name b))) (quote "\\"")) (quote ")") (quote " ^ ") (type ' \
164
+ 'sinatra:) (quote "\\"") (root (capture : (name c))) (quote "\\""))'
165
+ end
166
+ end
167
+ end
168
+
169
+ describe :tree do
170
+ subject(:tree) { Mustermann::Visualizer.tree(pattern) }
171
+
172
+ context :sinatra do
173
+ context "/:a(@:b)" do
174
+ let(:pattern) { Mustermann.new("/:a(@:b)") }
175
+ let(:tree_data) do
176
+ <<-TREE.gsub(/^\s+/, '')
177
+ \e[38;5;61m\e[0m\e[38;5;100mroot\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m\e[0m\e[38;5;66m\e[4m\e[38;5;100m/:a(@:b)\e[0m\e[38;5;66m\e[38;5;242m\e[0m\e[38;5;66m\" \e[0m
178
+ \e[38;5;61m└ \e[0m\e[38;5;166mpayload\e[0m
179
+ \e[38;5;61m ├ \e[0m\e[38;5;100mseparator\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m\e[0m\e[38;5;66m\e[4m\e[38;5;100m/\e[0m\e[38;5;66m\e[38;5;242m:a(@:b)\e[0m\e[38;5;66m\" \e[0m
180
+ \e[38;5;61m ├ \e[0m\e[38;5;100mcapture\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m/\e[0m\e[38;5;66m\e[4m\e[38;5;100m:a\e[0m\e[38;5;66m\e[38;5;242m(@:b)\e[0m\e[38;5;66m\" \e[0m
181
+ \e[38;5;61m └ \e[0m\e[38;5;100mgroup\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m/:a\e[0m\e[38;5;66m\e[4m\e[38;5;100m(@:b)\e[0m\e[38;5;66m\e[38;5;242m\e[0m\e[38;5;66m\" \e[0m
182
+ \e[38;5;61m └ \e[0m\e[38;5;166mpayload\e[0m
183
+ \e[38;5;61m ├ \e[0m\e[38;5;100mchar\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m/:a(\e[0m\e[38;5;66m\e[4m\e[38;5;100m@\e[0m\e[38;5;66m\e[38;5;242m:b)\e[0m\e[38;5;66m\" \e[0m
184
+ \e[38;5;61m └ \e[0m\e[38;5;100mcapture\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m/:a(@\e[0m\e[38;5;66m\e[4m\e[38;5;100m:b\e[0m\e[38;5;66m\e[38;5;242m)\e[0m\e[38;5;66m\" \e[0m
185
+ TREE
186
+ end
187
+ its(:to_s) { should be == tree_data }
188
+ end
189
+ end
190
+
191
+ context :shell do
192
+ context "/**/*" do
193
+ let(:pattern) { Mustermann.new("/**/*", type: :shell) }
194
+ let(:tree_data) { "\e[38;5;61m\e[0m\e[38;5;100mpattern (not AST based)\e[0m \e[0m\e[38;5;66m\"\e[0m\e[38;5;66m\e[38;5;242m\e[0m\e[38;5;66m\e[4m\e[38;5;100m/**/*\e[0m\e[38;5;66m\e[38;5;242m\e[0m\e[38;5;66m\" \e[0m\n" }
195
+ its(:to_s) { should be == tree_data }
196
+ end
197
+ end
198
+ end
199
+ end
data/theme.png ADDED
Binary file
data/tree.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mustermann-contrib
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta2
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ - Zachary Scott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mustermann
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0.beta2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0.beta2
28
+ - !ruby/object:Gem::Dependency
29
+ name: hansi
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.2.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.2.0
42
+ description: Adds many plugins to Mustermman
43
+ email: mail@zzak.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - examples/highlighting.rb
50
+ - highlighting.png
51
+ - irb.png
52
+ - lib/mustermann/cake.rb
53
+ - lib/mustermann/express.rb
54
+ - lib/mustermann/file_utils.rb
55
+ - lib/mustermann/file_utils/glob_pattern.rb
56
+ - lib/mustermann/fileutils.rb
57
+ - lib/mustermann/flask.rb
58
+ - lib/mustermann/grape.rb
59
+ - lib/mustermann/pyramid.rb
60
+ - lib/mustermann/rails.rb
61
+ - lib/mustermann/shell.rb
62
+ - lib/mustermann/simple.rb
63
+ - lib/mustermann/string_scanner.rb
64
+ - lib/mustermann/strscan.rb
65
+ - lib/mustermann/template.rb
66
+ - lib/mustermann/uri_template.rb
67
+ - lib/mustermann/versions.rb
68
+ - lib/mustermann/visualizer.rb
69
+ - lib/mustermann/visualizer/highlight.rb
70
+ - lib/mustermann/visualizer/highlighter.rb
71
+ - lib/mustermann/visualizer/highlighter/ad_hoc.rb
72
+ - lib/mustermann/visualizer/highlighter/ast.rb
73
+ - lib/mustermann/visualizer/highlighter/composite.rb
74
+ - lib/mustermann/visualizer/highlighter/dummy.rb
75
+ - lib/mustermann/visualizer/highlighter/regular.rb
76
+ - lib/mustermann/visualizer/pattern_extension.rb
77
+ - lib/mustermann/visualizer/renderer/ansi.rb
78
+ - lib/mustermann/visualizer/renderer/generic.rb
79
+ - lib/mustermann/visualizer/renderer/hansi_template.rb
80
+ - lib/mustermann/visualizer/renderer/html.rb
81
+ - lib/mustermann/visualizer/renderer/sexp.rb
82
+ - lib/mustermann/visualizer/tree.rb
83
+ - lib/mustermann/visualizer/tree_renderer.rb
84
+ - mustermann-contrib.gemspec
85
+ - spec/cake_spec.rb
86
+ - spec/express_spec.rb
87
+ - spec/file_utils_spec.rb
88
+ - spec/flask_spec.rb
89
+ - spec/flask_subclass_spec.rb
90
+ - spec/grape_spec.rb
91
+ - spec/pattern_extension_spec.rb
92
+ - spec/pyramid_spec.rb
93
+ - spec/rails_spec.rb
94
+ - spec/shell_spec.rb
95
+ - spec/simple_spec.rb
96
+ - spec/string_scanner_spec.rb
97
+ - spec/template_spec.rb
98
+ - spec/visualizer_spec.rb
99
+ - theme.png
100
+ - tree.png
101
+ homepage: https://github.com/sinatra/mustermann
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 2.2.0
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">"
117
+ - !ruby/object:Gem::Version
118
+ version: 1.3.1
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.5.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Collection of extensions for Mustermann
125
+ test_files: []
126
+ has_rdoc: