mumukit-directives 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mumukit/directives/comment_type.rb +55 -0
- data/lib/mumukit/directives/directive.rb +12 -0
- data/lib/mumukit/directives/flags.rb +23 -0
- data/lib/mumukit/directives/interpolations.rb +34 -0
- data/lib/mumukit/directives/pipeline.rb +24 -0
- data/lib/mumukit/directives/sections.rb +25 -0
- data/lib/mumukit/directives/version.rb +5 -0
- data/lib/mumukit/directives.rb +15 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmE1ODQxZDk0N2E5Mjk4NDU2NDA1Y2I0M2RjYTI1MTJlMzFlZjJlNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTdhZDE5ZTg3ODlmNDA3YjU1M2VjM2Y3YzU3NjAzZGM1MjgyMzk5Ng==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGRiNjA1YjQ5OWE2MGU0NTM4ZGI2YzBkM2Y3NWVmYjc2Yjg1OTE3N2EwODM3
|
10
|
+
YzAwZDRhNDhiMDM0ZmJkNmU1YjUwNGRlZTA1MTJiYjE4YTZlNDI0ZmIxMGUz
|
11
|
+
OTZmMjc4YzZkOGQ2ZTQwNTEyZjgyNjEzYjE0YmZkOWM4NGE3YzY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDEwMjUwZDBmZTc5ODc0MjkzNmIyZjdjNmMxNmVjM2MxMzcyMGEwODQ4YmMw
|
14
|
+
OWUyMWE0NTQyNTFhMDlkMWNlZTY4ZDM3NGYxNmFiNzdjM2QyNGI0ODMzMjhh
|
15
|
+
ZTRhNjdkZGIyNjExMmNlYTRmN2I4NWUyNWYzMjQ3N2JmNGZjMjk=
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mumukit/directives"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Mumukit::Directives::CommentType
|
2
|
+
def self.parse(string)
|
3
|
+
case string
|
4
|
+
when 'ruby' then
|
5
|
+
Mumukit::Directives::Ruby
|
6
|
+
when 'haskell' then
|
7
|
+
Mumukit::Directives::Haskell
|
8
|
+
else
|
9
|
+
Mumukit::Directives::Cpp
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Cpp
|
14
|
+
def self.open_comment
|
15
|
+
/\/\*/
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.close_comment
|
19
|
+
/\*\//
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.to_s
|
23
|
+
'cpp'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Ruby
|
28
|
+
def self.open_comment
|
29
|
+
/#/
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.close_comment
|
33
|
+
/#/
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.to_s
|
37
|
+
'ruby'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Haskell
|
42
|
+
def self.open_comment
|
43
|
+
/\{-/
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.close_comment
|
47
|
+
/-\}/
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.to_s
|
51
|
+
'haskell'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Mumukit::Directives::Directive
|
2
|
+
attr_writer :comment_type
|
3
|
+
|
4
|
+
def comment_regexp
|
5
|
+
/#{comment_type.open_comment}#{regexp}#{comment_type.close_comment}/
|
6
|
+
end
|
7
|
+
|
8
|
+
def comment_type
|
9
|
+
@comment_type ||= Mumukit::Directives::CommentType::Cpp
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Mumukit::Directives::Flags < Mumukit::Directives::Directive
|
2
|
+
def flags(code)
|
3
|
+
code.captures(comment_regexp).map { $1 }
|
4
|
+
end
|
5
|
+
|
6
|
+
def regexp
|
7
|
+
/\[(.+?)\]/
|
8
|
+
end
|
9
|
+
|
10
|
+
def active?(flag, code)
|
11
|
+
flags(code).include? flag
|
12
|
+
end
|
13
|
+
|
14
|
+
def transform(sections)
|
15
|
+
if active?('IgnoreContentOnQuery', sections['extra']) && sections['query'].present?
|
16
|
+
sections.except('content')
|
17
|
+
else
|
18
|
+
sections
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Mumukit::Directives::Interpolations < Mumukit::Directives::Directive
|
2
|
+
def initialize(key)
|
3
|
+
@key = key
|
4
|
+
end
|
5
|
+
|
6
|
+
def regexp
|
7
|
+
/\.\.\.(.+?)\.\.\./
|
8
|
+
end
|
9
|
+
|
10
|
+
def interpolations?(code)
|
11
|
+
(code =~ comment_regexp).present?
|
12
|
+
end
|
13
|
+
|
14
|
+
def interpolate(code, sections)
|
15
|
+
interpolated = []
|
16
|
+
|
17
|
+
var = code.captures(comment_regexp) do
|
18
|
+
interpolated << $1
|
19
|
+
sections[$1]
|
20
|
+
end
|
21
|
+
|
22
|
+
[var, interpolated.uniq]
|
23
|
+
end
|
24
|
+
|
25
|
+
def transform(sections)
|
26
|
+
code = sections[@key]
|
27
|
+
if interpolations? code
|
28
|
+
interpolation, interpolated = interpolate code, sections.except(@key)
|
29
|
+
sections.merge(@key => interpolation).except(*interpolated)
|
30
|
+
else
|
31
|
+
sections
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Mumukit::Directives::Pipeline
|
2
|
+
def initialize(directives, comment_type=nil)
|
3
|
+
@directives = directives
|
4
|
+
configure(comment_type)
|
5
|
+
end
|
6
|
+
|
7
|
+
def transform(request)
|
8
|
+
base_sections = request.to_stringified_h
|
9
|
+
rest = base_sections.slice!('test', 'extra', 'content', 'query')
|
10
|
+
|
11
|
+
@directives
|
12
|
+
.inject(base_sections) { |sections, it| it.transform(sections) }
|
13
|
+
.amend(rest)
|
14
|
+
.to_struct
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def configure(comment_type)
|
20
|
+
@directives.each do |it|
|
21
|
+
it.comment_type = comment_type
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Mumukit::Directives::Sections < Mumukit::Directives::Directive
|
2
|
+
def regexp
|
3
|
+
/<(.+?)##{comment_type.close_comment}(.+?)#{comment_type.open_comment}#(.+?)>/
|
4
|
+
end
|
5
|
+
|
6
|
+
def split_sections(code)
|
7
|
+
sections = code.captures(comment_regexp).map do
|
8
|
+
[$1, $2]
|
9
|
+
end
|
10
|
+
Hash[sections]
|
11
|
+
end
|
12
|
+
|
13
|
+
def transform(sections)
|
14
|
+
result = {}
|
15
|
+
sections.each do |key, code|
|
16
|
+
new_sections = split_sections(code)
|
17
|
+
if new_sections.present?
|
18
|
+
result.merge!(new_sections)
|
19
|
+
else
|
20
|
+
result[key] = code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'mumukit/core'
|
2
|
+
|
3
|
+
require_relative './directives/version'
|
4
|
+
|
5
|
+
module Mumukit
|
6
|
+
module Directives
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative './directives/comment_type'
|
11
|
+
require_relative './directives/directive'
|
12
|
+
require_relative './directives/flags'
|
13
|
+
require_relative './directives/interpolations'
|
14
|
+
require_relative './directives/sections'
|
15
|
+
require_relative './directives/pipeline'
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mumukit-directives
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Franco Leonardo Bulgarelli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mumukit-core
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
description: A directives preprocessor for mumuki
|
84
|
+
email:
|
85
|
+
- franco@mumuki.org
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- bin/console
|
91
|
+
- bin/setup
|
92
|
+
- lib/mumukit/directives.rb
|
93
|
+
- lib/mumukit/directives/comment_type.rb
|
94
|
+
- lib/mumukit/directives/directive.rb
|
95
|
+
- lib/mumukit/directives/flags.rb
|
96
|
+
- lib/mumukit/directives/interpolations.rb
|
97
|
+
- lib/mumukit/directives/pipeline.rb
|
98
|
+
- lib/mumukit/directives/sections.rb
|
99
|
+
- lib/mumukit/directives/version.rb
|
100
|
+
homepage: https://github.com/mumuki/mumukit-directives
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
- bin
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Interpolations, sections and flags pipelines for mumuki
|
125
|
+
test_files: []
|