singer 0.1.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/exe/singer +2 -7
- data/lib/singer/configuration.rb +4 -0
- data/lib/singer/paths.rb +20 -0
- data/lib/singer/template.rb +35 -0
- data/lib/singer/templating_methods.rb +14 -0
- data/lib/singer/version.rb +1 -1
- data/lib/singer.rb +21 -1
- data/templates/tdd/lib/__SNAKECASE_NAME__.rb +13 -0
- data/templates/tdd/test/test___SNAKECASE_NAME__.rb +16 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d324ad6ec097b02fe9db6ab844205b37dd6a53450d69d5c7780d5bd7e7743efa
|
4
|
+
data.tar.gz: 9990fccac83a6ce04a3d89da50e7dd6b109edbfb74fa48e938b40839c34dfe5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5ae6fa28d28668e5afa00615770a6e69628f767e7adaa1344d26bc6e9e0e4c26a60c17aeb51ccae165ad4e50a77fac52b9e38d391d3de01ff398df36bda6682
|
7
|
+
data.tar.gz: f1f56ff0b4234f45d9a68835d9c69110481567aa7a3554f06240913b6125e9017439d601754e522710b326bf6f402b1771f181b2ffb27cf746da1a8fc3762990
|
data/exe/singer
CHANGED
data/lib/singer/paths.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Singer
|
2
|
+
# helps find files
|
3
|
+
class Paths
|
4
|
+
def self.templates_from_gem
|
5
|
+
@templates_from_gem ||= File.expand_path('../../templates', __dir__)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.output_path(...)
|
9
|
+
File.join(...).gsub(/__([[:alpha:]][[:word:]]+)__/) do |match|
|
10
|
+
potential_config = $1.downcase
|
11
|
+
|
12
|
+
if CONFIGURATION.respond_to?(potential_config)
|
13
|
+
CONFIGURATION.send(potential_config)
|
14
|
+
else
|
15
|
+
match
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Singer
|
4
|
+
# describes one type of code that Singer can generate
|
5
|
+
class Template
|
6
|
+
def self.all
|
7
|
+
@all ||= load_all
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.load_all
|
11
|
+
Dir[File.join(Paths.templates_from_gem, '*')].to_h do |template_dir|
|
12
|
+
[File.basename(template_dir), new(template_dir)]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :path, :files
|
17
|
+
|
18
|
+
def initialize(path)
|
19
|
+
@path = path
|
20
|
+
Dir.chdir(path) do # we could use only Dir[base: path], but all the code uses relative paths
|
21
|
+
entries = Dir['**/*']
|
22
|
+
@files = entries.select{ File.file?(_1) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate(output_path)
|
27
|
+
files.each do |file|
|
28
|
+
source_file = File.join(path, file)
|
29
|
+
target_file = Paths.output_path(output_path, file)
|
30
|
+
FileUtils.mkdir_p(File.dirname(target_file))
|
31
|
+
TemplatingMethods.send(:erb, source_file, target_file)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Singer
|
4
|
+
# different ways to create output file from source template file
|
5
|
+
class TemplatingMethods
|
6
|
+
def self.copy(source_file, target_file)
|
7
|
+
FileUtils.cp(source_file, target_file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.erb(source_file, target_file)
|
11
|
+
File.write(target_file, ERB.new(File.read(source_file)).result)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/singer/version.rb
CHANGED
data/lib/singer.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
require_relative 'singer/version'
|
2
|
+
require_relative 'singer/configuration'
|
3
|
+
require_relative 'singer/paths'
|
4
|
+
require_relative 'singer/template'
|
5
|
+
require_relative 'singer/templating_methods'
|
2
6
|
|
7
|
+
# Singer, which generates Sinatra apps etc. from templates
|
3
8
|
module Singer
|
4
9
|
class Error < StandardError; end
|
5
|
-
|
10
|
+
class NameMissingError < StandardError; end
|
11
|
+
|
12
|
+
def self.configure(argvies)
|
13
|
+
raise NameMissingError, 'Missing mandatory argument NAME' if argvies.empty?
|
14
|
+
|
15
|
+
encase_name(argvies.last)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.encase_name(name)
|
19
|
+
CONFIGURATION.snakecase_name = name.gsub(/(\w)([A-Z])/){ "#{$1}_#{$2}" }.gsub(/_+/, '_').downcase
|
20
|
+
CONFIGURATION.camelcase_name = CONFIGURATION.snakecase_name.split('_').map(&:capitalize).join
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.generate
|
24
|
+
Template.all['tdd'].generate('.')
|
25
|
+
end
|
6
26
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
# require 'awesome_print'
|
3
|
+
|
4
|
+
class <%= Singer::CONFIGURATION.camelcase_name %>
|
5
|
+
def hello(who:)
|
6
|
+
"Hello, #{who}."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
|
11
|
+
ciastka = <%= Singer::CONFIGURATION.camelcase_name %>.new
|
12
|
+
puts "Testing testing: #{ciastka.hello(who: :world).green}"
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'minitest/rg'
|
2
|
+
require 'minitest/autorun' if $PROGRAM_NAME == __FILE__
|
3
|
+
|
4
|
+
require_relative '../lib/<%= Singer::CONFIGURATION.snakecase_name %>'
|
5
|
+
|
6
|
+
class Test<%= Singer::CONFIGURATION.camelcase_name %> < Minitest::Test
|
7
|
+
# TEST_INPUT = File.read('input_mini.txt').lines(chomp: true)
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@<%= Singer::CONFIGURATION.snakecase_name %> = <%= Singer::CONFIGURATION.camelcase_name %>.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_hello_interpolates_into_string
|
14
|
+
assert_equal 'Hello, world.', @<%= Singer::CONFIGURATION.snakecase_name %>.hello(who: :world)
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Chludziński
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
11
|
-
dependencies:
|
10
|
+
date: 2025-01-21 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: erb
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
12
26
|
description: |
|
13
27
|
Singer is a highly configurable templating system intended for generating Ruby boilerplate.
|
14
28
|
It aims to make creating and extending Sinatra apps easier.
|
@@ -23,7 +37,13 @@ files:
|
|
23
37
|
- README.md
|
24
38
|
- exe/singer
|
25
39
|
- lib/singer.rb
|
40
|
+
- lib/singer/configuration.rb
|
41
|
+
- lib/singer/paths.rb
|
42
|
+
- lib/singer/template.rb
|
43
|
+
- lib/singer/templating_methods.rb
|
26
44
|
- lib/singer/version.rb
|
45
|
+
- templates/tdd/lib/__SNAKECASE_NAME__.rb
|
46
|
+
- templates/tdd/test/test___SNAKECASE_NAME__.rb
|
27
47
|
homepage: https://gitlab.com/tanstaafl/singer/
|
28
48
|
licenses:
|
29
49
|
- MIT
|