jeny 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/jeny/code_block.rb +1 -1
- data/lib/jeny/command/generate.rb +9 -0
- data/lib/jeny/command/snippets.rb +30 -9
- data/lib/jeny/command/support.rb +0 -7
- data/lib/jeny/command.rb +4 -3
- data/lib/jeny/configuration.rb +3 -3
- data/lib/jeny/file/full.rb +4 -4
- data/lib/jeny/file/with_blocks.rb +14 -11
- data/lib/jeny/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6db35c1fd878f2bc7af87ba0215aa8129c5e8110e19466a3499a6cdcdcef70e8
|
4
|
+
data.tar.gz: 66fc2826d8cf09bf5fed06c3632e530048a640c5f6df0d679cc0409b8e96ebd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91302c64a85dbe34f87dc1a1c75e2c743a6a7962f25a64732547502bc17bdd946882b29ad0ccd8757171c8897690cc079d8c5fb0569b03e65e8e4480281ecd0b
|
7
|
+
data.tar.gz: 87817c9880ef4cba5665a0b41fbbbce70955a3c05c2666d1b860f12906836c3b58a8ccea1b218c69f8df9d34bff9fac5147f553120a070a530a4f46a3c5b9ce8
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Jeny
|
2
2
|
|
3
|
-
![](https://
|
3
|
+
[![Tests](https://github.com/enspirit/jeny/actions/workflows/integration.yml/badge.svg)](https://github.com/enspirit/jeny/actions/workflows/integration.yml)
|
4
4
|
|
5
5
|
Jeny is a simple yet powerful commandline tool for scaffolding new
|
6
6
|
projects and generating code snippets in existing ones.
|
data/lib/jeny/code_block.rb
CHANGED
@@ -30,6 +30,15 @@ module Jeny
|
|
30
30
|
edit_changed_files(changed)
|
31
31
|
end
|
32
32
|
|
33
|
+
private
|
34
|
+
|
35
|
+
def target_for(source, data = self.data)
|
36
|
+
relative = source.relative_to(from)
|
37
|
+
relative.each_filename.map{|f|
|
38
|
+
Dialect.render(f.gsub(/.jeny$/, ""), data)
|
39
|
+
}.inject(to){|t,part| t/part }
|
40
|
+
end
|
41
|
+
|
33
42
|
end # class Generate
|
34
43
|
end # class Command
|
35
44
|
end # module Jeny
|
@@ -11,19 +11,16 @@ module Jeny
|
|
11
11
|
end
|
12
12
|
attr_reader :config, :data, :asset, :from
|
13
13
|
|
14
|
-
alias :to :from
|
15
|
-
|
16
14
|
def call
|
17
15
|
puts
|
18
16
|
sm, state = config.state_manager, OpenStruct.new
|
19
17
|
sm.stash(state) if config.sm_stash?
|
20
18
|
|
21
19
|
changed = []
|
22
|
-
from.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
changed << pair if pair
|
20
|
+
from.each do |source|
|
21
|
+
parent = source
|
22
|
+
parent = source.parent until parent.directory?
|
23
|
+
_call(source, parent, changed)
|
27
24
|
end
|
28
25
|
|
29
26
|
sm.commit(changed.map(&:first), state) if config.sm_commit?
|
@@ -36,7 +33,25 @@ module Jeny
|
|
36
33
|
sm.unstash(state) if config.sm_stash?
|
37
34
|
end
|
38
35
|
|
39
|
-
def
|
36
|
+
def _call(source, parent, changed)
|
37
|
+
raise ArgumentError, parent unless parent.directory?
|
38
|
+
|
39
|
+
if source.file?
|
40
|
+
return if config.ignore_file?(source)
|
41
|
+
pair = snippet_it(source, parent)
|
42
|
+
changed << pair if pair
|
43
|
+
elsif source.directory?
|
44
|
+
source.glob("**/*").each do |sub|
|
45
|
+
next if sub.directory?
|
46
|
+
_call(sub, parent, changed)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
raise ArgumentError, "Not a file, nor or directly: #{source}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
private :_call
|
53
|
+
|
54
|
+
def snippet_it(source, parent)
|
40
55
|
target, target_content = nil
|
41
56
|
if source.ext =~ /\.?jeny/
|
42
57
|
file = File::Full.new(source, config)
|
@@ -62,7 +77,13 @@ module Jeny
|
|
62
77
|
target ? [target, target_content] : nil
|
63
78
|
rescue => ex
|
64
79
|
msg = "Error in `#{simplify_path(source)}`: #{ex.message}"
|
65
|
-
raise Error, msg
|
80
|
+
raise Error, msg, ex.backtrace
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def target_for(source, data = self.data)
|
86
|
+
Path(Dialect.render(source.to_s.gsub(/\.jeny/, ""), data))
|
66
87
|
end
|
67
88
|
|
68
89
|
end # class Snippets
|
data/lib/jeny/command/support.rb
CHANGED
@@ -2,13 +2,6 @@ module Jeny
|
|
2
2
|
class Command
|
3
3
|
module Support
|
4
4
|
|
5
|
-
def target_for(source, data = self.data)
|
6
|
-
relative = source.relative_to(from)
|
7
|
-
relative.each_filename.map{|f|
|
8
|
-
Dialect.render(f.gsub(/.jeny$/, ""), data)
|
9
|
-
}.inject(to){|t,part| t/part }
|
10
|
-
end
|
11
|
-
|
12
5
|
def simplify_path(path)
|
13
6
|
if path.to_s.start_with?(Path.pwd.to_s)
|
14
7
|
path.relative_to(Path.pwd)
|
data/lib/jeny/command.rb
CHANGED
@@ -26,10 +26,11 @@ module Jeny
|
|
26
26
|
to.mkdir_p
|
27
27
|
Generate.new(@config, jeny_data, from, to).call
|
28
28
|
when "s", "snippets"
|
29
|
-
_, asset, source = args
|
29
|
+
_, asset, *source = args
|
30
30
|
raise Error, "Asset must be specified" if asset.nil? or Path(asset).exist?
|
31
|
-
source
|
32
|
-
|
31
|
+
source = [Path.pwd] if source.empty?
|
32
|
+
from = source.map{|t| Path(t) }
|
33
|
+
Snippets.new(@config, jeny_data, asset, from).call
|
33
34
|
else
|
34
35
|
raise Error, "Unknown command `#{command}`"
|
35
36
|
end
|
data/lib/jeny/configuration.rb
CHANGED
@@ -6,8 +6,8 @@ module Jeny
|
|
6
6
|
}
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@jeny_block_delimiter = "
|
10
|
-
@ignore_pattern = /^(vendor|\.bundle)/
|
9
|
+
@jeny_block_delimiter = "(#|\/\/)jeny"
|
10
|
+
@ignore_pattern = /^(vendor|\.bundle|.min.js|.min.css)/
|
11
11
|
@editor_command = default_editor_command
|
12
12
|
@edit_changed_files = DEFAULT_EDIT_PROC
|
13
13
|
@state_manager = default_state_manager
|
@@ -54,7 +54,7 @@ module Jeny
|
|
54
54
|
# either true of false.
|
55
55
|
#
|
56
56
|
# Both are true by default.
|
57
|
-
|
57
|
+
attr_accessor :state_manager_options
|
58
58
|
|
59
59
|
# :nodoc:
|
60
60
|
def sm_stash?
|
data/lib/jeny/file/full.rb
CHANGED
@@ -3,7 +3,7 @@ module Jeny
|
|
3
3
|
class Full < File
|
4
4
|
|
5
5
|
def context_rgx
|
6
|
-
/^#{config.jeny_block_delimiter}\(([a-z]+)\)\s*$/
|
6
|
+
/^#{config.jeny_block_delimiter}\((?<asset>[a-z]+)\)\s*$/
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_jeny_context?
|
@@ -11,8 +11,8 @@ module Jeny
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def instantiate_context(data)
|
14
|
-
if path.readlines.first
|
15
|
-
data[
|
14
|
+
if match = path.readlines.first.match(context_rgx)
|
15
|
+
data[match[:asset]]
|
16
16
|
else
|
17
17
|
data
|
18
18
|
end
|
@@ -21,7 +21,7 @@ module Jeny
|
|
21
21
|
def instantiate(data)
|
22
22
|
path.readlines.map{|l|
|
23
23
|
next if l =~ context_rgx
|
24
|
-
Dialect.render(l, data)
|
24
|
+
Dialect.render(l, data) rescue l
|
25
25
|
}.compact.join("")
|
26
26
|
end
|
27
27
|
|
@@ -4,31 +4,34 @@ module Jeny
|
|
4
4
|
|
5
5
|
def has_jeny_blocks?
|
6
6
|
!jeny_blocks.empty?
|
7
|
+
rescue Exception => ex
|
8
|
+
puts "WARN: #{path} skipped: #{ex.message}"
|
9
|
+
false
|
7
10
|
end
|
8
|
-
|
11
|
+
|
9
12
|
def jeny_blocks
|
10
13
|
@jeny_blocks ||= _parse_jeny_blocks(path.readlines, 0, [])
|
11
14
|
end
|
12
|
-
|
15
|
+
|
13
16
|
def instantiate(data)
|
14
17
|
return path.read unless has_jeny_blocks?
|
15
18
|
_instantiate(data, path.readlines, 0, jeny_blocks, []).join("")
|
16
19
|
end
|
17
|
-
|
20
|
+
|
18
21
|
private
|
19
|
-
|
22
|
+
|
20
23
|
def _parse_jeny_blocks(lines, index, blocks)
|
21
24
|
if index >= lines.size
|
22
25
|
blocks
|
23
|
-
elsif lines[index]
|
26
|
+
elsif match = (lines[index].match(jeny_block_regex))
|
24
27
|
source, new_index = _parse_jeny_block(lines, index)
|
25
|
-
blocks << CodeBlock.new(source, path, index+1,
|
28
|
+
blocks << CodeBlock.new(source, path, index+1, match[:asset])
|
26
29
|
_parse_jeny_blocks(lines, new_index+1, blocks)
|
27
30
|
else
|
28
31
|
_parse_jeny_blocks(lines, index+1, blocks)
|
29
32
|
end
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
def _parse_jeny_block(lines, index, str = "")
|
33
36
|
if lines[index] =~ jeny_block_regex
|
34
37
|
_parse_jeny_block(lines, index+1, str + lines[index])
|
@@ -40,7 +43,7 @@ module Jeny
|
|
40
43
|
[source, index]
|
41
44
|
end
|
42
45
|
end
|
43
|
-
|
46
|
+
|
44
47
|
def _instantiate(data, lines, index, blocks, acc)
|
45
48
|
block = blocks.first
|
46
49
|
if block.nil?
|
@@ -57,11 +60,11 @@ module Jeny
|
|
57
60
|
_instantiate(data, lines, block.line_index, blocks, acc)
|
58
61
|
end
|
59
62
|
end
|
60
|
-
|
63
|
+
|
61
64
|
def jeny_block_regex
|
62
|
-
@jeny_block_regex ||= %r{^\s*#{config.jeny_block_delimiter}\(([a-z]+)\)}m
|
65
|
+
@jeny_block_regex ||= %r{^\s*#{config.jeny_block_delimiter}\((?<asset>[a-z]+)\)}m
|
63
66
|
end
|
64
|
-
|
67
|
+
|
65
68
|
def jeny_block_gsub
|
66
69
|
@jeny_block_gsub ||= %r{#{config.jeny_block_delimiter}(\([a-z]+\))[ ]?}
|
67
70
|
end
|
data/lib/jeny/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: path
|
@@ -99,7 +99,7 @@ homepage: http://github.com/enspirit/jeny
|
|
99
99
|
licenses:
|
100
100
|
- MIT
|
101
101
|
metadata: {}
|
102
|
-
post_install_message:
|
102
|
+
post_install_message:
|
103
103
|
rdoc_options: []
|
104
104
|
require_paths:
|
105
105
|
- lib
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubygems_version: 3.1.4
|
118
|
-
signing_key:
|
118
|
+
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Simple scaffolding and code generation
|
121
121
|
test_files: []
|