thot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3bc290fd549f5d8f74f3976bf295caf1948c4034c6b70b6d611481a9062d6192
4
+ data.tar.gz: af1047cf61a5570eb1fdb6981689bbc099fd0c01455401a6842d951b36f001f9
5
+ SHA512:
6
+ metadata.gz: b8d2156265be4a1f7521a2a05a9f928e1016e059c55451c4d7f7bc76022f7390888e8361ed6daee4111972b974c0eb06b9b2859767c28d9c8bfbdb15794ff5c0
7
+ data.tar.gz: cc24897736a165ee81c3e8f38ba81e5d1926768192ad08c938664e18145a2a16f00a57aa0bb3772745476a63d2c0a77b2623d1a03ba72d77c7c5c6380b036c61
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /yardoc/
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ Exclude:
5
+ - 'spec/template_spec.rb'
6
+
7
+
8
+
9
+ # definitive :
10
+ Style/ClassVars:
11
+ Enabled: false
12
+ Gemspec/RequireMFA:
13
+ Enabled: false
14
+ Security/YAMLLoad:
15
+ Enabled: false
16
+ Style/MutableConstant:
17
+ Enabled: false
18
+
19
+ # to study :
20
+
21
+ Metrics/ClassLength:
22
+ Enabled: false
23
+ Metrics/AbcSize:
24
+ Enabled: false
25
+ Metrics/CyclomaticComplexity:
26
+ Enabled: false
27
+ Metrics/MethodLength:
28
+ Enabled: false
29
+ Metrics/PerceivedComplexity:
30
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Pierre Alphonse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Thot
2
+
3
+ Thot is THe Operative Templating : the simpliest solution for Ruby and command to templatize
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'thot'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install thot
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Ultragreen/thot.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "version"
4
+ require 'rake/version_task'
5
+ require 'code_statistics'
6
+ require 'yard'
7
+ require 'yard/rake/yardoc_task.rb'
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+
13
+ Rake::VersionTask.new
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+
18
+ task :default => :spec
19
+
20
+ YARD::Rake::YardocTask.new do |t|
21
+ t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
22
+ t.options += ['-o', "yardoc"]
23
+ end
24
+
25
+ YARD::Config.load_plugin('yard-rspec')
26
+
27
+ namespace :yardoc do
28
+ task :clobber do
29
+ rm_r "yardoc" rescue nil
30
+ rm_r ".yardoc" rescue nil
31
+ rm_r "pkg" rescue nil
32
+ end
33
+ end
34
+ task :clobber => "yardoc:clobber"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thot"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require 'version'
2
+ module Thot
3
+ VERSION = Version.current
4
+ end
data/lib/thot.rb ADDED
@@ -0,0 +1,93 @@
1
+ # coding: utf-8
2
+ require "thot/version"
3
+
4
+ # Thot base module
5
+ module Thot
6
+ class Error < StandardError; end
7
+
8
+
9
+ # KISS template Engine
10
+ class Template
11
+
12
+ # getter of the list of token
13
+ attr_reader :list_token
14
+ # getter of the template file
15
+ attr_reader :template_file
16
+ # getter of the flat content of the template
17
+ attr_reader :content
18
+
19
+ # constructor : generate the pseudo accessor for template Class from token list
20
+ def initialize(template_file: , list_token: , strict: true)
21
+
22
+
23
+ @template_file = template_file
24
+ raise NoTemplateFile::new('No template file found') unless File::exist?(@template_file)
25
+ begin
26
+ @content = IO::readlines(@template_file).join.chomp
27
+ rescue
28
+ raise NoTemplateFile::new('No template file found')
29
+ end
30
+ token_from_template = @content.scan(/%%(\w+)%%/).flatten.uniq.map{ |item| item.downcase.to_sym}
31
+ begin
32
+ @list_token = list_token
33
+ @hash_token = Hash::new; @list_token.each{|_item| @hash_token[_item.to_s] = String::new('')}
34
+ rescue
35
+ raise InvalidTokenList::new("Token list malformation")
36
+ end
37
+ if strict
38
+ raise InvalidTokenList::new("Token list doesn't match the template") unless token_from_template.sort == @list_token.sort
39
+ else
40
+ raise InvalidTokenList::new("Token list doesn't match the template") unless (token_from_template.sort & @list_token.sort) == token_from_template.sort
41
+ end
42
+ @list_token.each{|_token| eval("def #{_token}=(_value); raise ArgumentError::new('Not a String') unless _value.class == String; @hash_token['#{_token}'] = _value ;end")}
43
+ @list_token.each{|_token| eval("def #{_token}; @hash_token['#{_token}'] ;end")}
44
+ end
45
+
46
+ # generic accessor
47
+ # @param [Symbol] _token in the token list
48
+ # @param [String] _value a text value
49
+ # @raise [ArgumentError] if _valu is not a String
50
+ def token(_token,_value)
51
+ raise ArgumentError::new('Not a String') unless _value.class == String
52
+ @hash_token[_token.to_s] = _value
53
+ end
54
+
55
+ # map a hash against templates token_list
56
+ # @param [Hash] _hash a hash data to map
57
+ def map(_hash)
58
+ _data = {}
59
+ _hash.each { |item,val|
60
+ raise ArgumentError::new("#{item} : Not a String") unless val.class == String
61
+ _data[item.to_s.downcase] = val
62
+ }
63
+ raise InvalidTokenList::new("Token list malformation") unless _data.keys.sort == @list_token.map{|_token| _token.to_s }.sort
64
+ @hash_token = _data
65
+ end
66
+
67
+ # collector for pseudo accessor to prevent bad mapping
68
+ # @raise [NotAToken] if caling an accessor not mapped in token list
69
+ def method_missing(_name,*_args)
70
+ raise NotAToken
71
+ end
72
+
73
+ # the templater;proceed to templating
74
+ # @return [String] the template output
75
+ def output
76
+ _my_res = String::new('')
77
+ _my_res = @content
78
+ @list_token.each{|_token|
79
+ _my_res.gsub!(/%%#{_token.to_s.upcase}%%/,@hash_token[_token.to_s])
80
+ }
81
+ return _my_res
82
+ end
83
+
84
+ end
85
+
86
+ # Exception for an invalid Token list
87
+ class InvalidTokenList < Exception; end
88
+ # Exception for an malformed token
89
+ class NotAToken < Exception; end
90
+ # Exception for an invalid template file
91
+ class NoTemplateFile < Exception; end
92
+
93
+ end
data/thot.gemspec ADDED
@@ -0,0 +1,33 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "thot"
4
+ spec.version = `cat VERSION`.chomp
5
+ spec.authors = ["Romain GEORGES"]
6
+ spec.email = ["gems@ultragreen.net"]
7
+
8
+ spec.summary = "THe Operative Templating "
9
+ spec.description = "the simpliest way to template in Ruby and command"
10
+ spec.homepage = "https://github.com/Ultragreen/thot"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency 'rake', '~> 12.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rubocop', '~> 1.32'
28
+ spec.add_development_dependency "roodi", "~> 5.0"
29
+ spec.add_development_dependency 'code_statistics', '~> 0.2.13'
30
+ spec.add_development_dependency "yard", "~> 0.9.27"
31
+ spec.add_development_dependency "yard-rspec", "~> 0.1"
32
+ spec.add_development_dependency'version', '~> 1.1'
33
+ end
@@ -0,0 +1,24 @@
1
+ AssignmentInConditionalCheck:
2
+ CaseMissingElseCheck:
3
+ ClassLineCountCheck:
4
+ line_count: 300 # including comments yard
5
+ ClassNameCheck:
6
+ pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
7
+ #ClassVariableCheck:
8
+ CyclomaticComplexityBlockCheck:
9
+ complexity: 5
10
+ CyclomaticComplexityMethodCheck:
11
+ complexity: 10
12
+ EmptyRescueBodyCheck:
13
+ ForLoopCheck:
14
+ MethodLineCountCheck:
15
+ line_count: 30
16
+ MethodNameCheck:
17
+ pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
18
+ # MissingForeignKeyIndexCheck:
19
+ ModuleLineCountCheck:
20
+ line_count: 300
21
+ ModuleNameCheck:
22
+ pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
23
+ ParameterNumberCheck:
24
+ parameter_count: 5
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Romain GEORGES
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-15 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: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.32'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.32'
55
+ - !ruby/object:Gem::Dependency
56
+ name: roodi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: code_statistics
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.13
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.13
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.27
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.27
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: version
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.1'
125
+ description: the simpliest way to template in Ruby and command
126
+ email:
127
+ - gems@ultragreen.net
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - VERSION
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/thot.rb
143
+ - lib/thot/version.rb
144
+ - thot.gemspec
145
+ - ultragreen_roodi_coding_convention.yml
146
+ homepage: https://github.com/Ultragreen/thot
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ homepage_uri: https://github.com/Ultragreen/thot
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 2.3.0
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubygems_version: 3.2.3
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: THe Operative Templating
170
+ test_files: []