mdfiller 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d7747e80108116cd3b79ce41f6e9f2bd35aa870029d39a1e9a0714be58d95f33
4
+ data.tar.gz: 4d58a8bf1c29935623873692ff2d981d1091554a9d11d57ee45d8889ac30d2ec
5
+ SHA512:
6
+ metadata.gz: d01702b08d4eaec1b6af3aa8b171cd85bef49b7ac6b505224f86bebf7085e55da1f052ad89b9837b99278fb4ef406863db7f2faced32bdd6660515f8dfc5754a
7
+ data.tar.gz: eac0a9ef52389910cf6c13d88678dc3a4cc5baeb51755bcc45696257215391e6af04b2e4a1c588570ce2f026a55a1254c7346e74180ecfac92c5add484387caf
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ mdfiller
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Mdfiller
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mdfiller`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mdfiller.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/exe/mdf ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ version = '1.0.0'
4
+ ourlib = File.join(ENV['HOME'], '.rvm', 'gems', 'ruby-3.4.0-preview1@mdfiller', 'gems', "mdfiller-#{version}", 'lib')
5
+ $:<< ourlib
6
+ require "mdfiller"
7
+ require 'byebug'
8
+
9
+ dir = '.'
10
+ if ARGV.size >= 1
11
+ dir = ARGV[0]
12
+ end
13
+
14
+ mdf = Mdfiller::Filler.new(dir=dir)
15
+ puts(mdf.generate)
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mdfiller
4
+
5
+ class PureVirtualCalled < Error; end
6
+
7
+ class Base
8
+
9
+ attr_reader :files, :soft, :dir
10
+
11
+ def initialize(f_array, soft='', dir='.')
12
+ @files = f_array
13
+ @soft = soft
14
+ @dir = dir
15
+ end
16
+
17
+ def fill
18
+ return copy_files
19
+ end
20
+
21
+ protected
22
+
23
+ def copy_files
24
+ result = ''
25
+ self.files.each do
26
+ |fname|
27
+ result += "\n[#{fname}](#{self.dir}/#{fname})\n"
28
+ result += "```#{self.soft}\n"
29
+ File.open(File.join(self.dir, fname), 'r') { |fh| result += fh.readlines.join }
30
+ result += "```\n\n"
31
+ end
32
+ return result
33
+ end
34
+ end
35
+
36
+ class OrcAndScoFill < Base
37
+
38
+ def initialize(f_array, dir='.')
39
+ super(f_array, soft='csound', dir=dir)
40
+ end
41
+
42
+ end
43
+
44
+ class CsdFill < Base
45
+
46
+ def initialize(f_array, dir='.')
47
+ super(f_array, 'csound', dir=dir)
48
+ end
49
+ end
50
+
51
+ class PyFill < Base
52
+
53
+ def initialize(f_array, dir='.')
54
+ super(f_array, 'python', dir=dir)
55
+ end
56
+
57
+ protected
58
+
59
+ def copy_files
60
+ result = ''
61
+ self.files.each do
62
+ |fname|
63
+ pngname = File.basename("#{fname}", ".py") + '.png'
64
+ result += "\n[#{fname}](#{self.dir}/#{fname})\n```#{self.soft}\n"
65
+ File.open(File.join(self.dir, fname), 'r') { |fh| result += fh.readlines.join }
66
+ IO.popen("(cat #{self.dir}/#{fname} | sed -e '/^plt.show()$/d'; echo \"plt.savefig('#{self.dir}/#{pngname}')\") | python3") do
67
+ |ioh|
68
+ result += ioh.readlines.join
69
+ end
70
+ result += "```\n\nPlot prodotto:\n\n![#{pngname}](#{self.dir}/#{pngname})\n\n"
71
+ end
72
+ return result
73
+ end
74
+
75
+ end
76
+
77
+ class PngFill < Base
78
+
79
+ def copy_files
80
+ result = ''
81
+ whiteboard = 0
82
+ self.files.each do
83
+ |fname|
84
+ result += "\n![whiteboard n.#{whiteboard}](#{self.dir}/#{fname})\n"
85
+ whiteboard += 1
86
+ end
87
+ return result
88
+ end
89
+
90
+ end
91
+
92
+ class PdFill < Base
93
+
94
+ def initialize(f_array, dir='.')
95
+ super(f_array, 'pd', dir=dir)
96
+ end
97
+
98
+ protected
99
+
100
+ def copy_files
101
+ result = ''
102
+ shots = nil
103
+ fs = self.files
104
+ fs.each do
105
+ |fname|
106
+ command = [ 'pw-jack', 'puredata', "#{self.dir}/#{fname}" ]
107
+ pid = spawn_process(command)
108
+ sleep(1)
109
+ windows_to_shoot = get_windows_to_shoot
110
+ shots = shoot_windows(windows_to_shoot, fname)
111
+ shots.each { |s| result += "\n![#{s}](#{self.dir}/#{s})\n" }
112
+ kill_process(pid)
113
+ end
114
+ return result
115
+ end
116
+
117
+ private
118
+
119
+ def spawn_process(process)
120
+ pid = Process.spawn(*process, :out => :close, :err => :close)
121
+ unless pid.nil? # in parent
122
+ Process.detach(pid)
123
+ end
124
+ return pid
125
+ end
126
+
127
+ def kill_process(pid)
128
+ Process.kill('QUIT', pid)
129
+ end
130
+
131
+ def get_windows_to_shoot
132
+ result = {}
133
+ IO.popen("wmctrl -lx | egrep -e '(Gem|.*\.pd )'") do
134
+ |ioh|
135
+ lines = ioh.readlines
136
+ lines.each do
137
+ |l|
138
+ fields = l.split(/ +/).map { |f| f.chomp }
139
+ win = fields[0]
140
+ p = fields[4]
141
+ result[p] = win
142
+ end
143
+ end
144
+ return result
145
+ end
146
+
147
+ def shoot_windows(wts, fname)
148
+ shots = []
149
+ wts.each do
150
+ |k, win|
151
+ root = File.basename(fname, '.pd')
152
+ root += '-Gem' if k == 'Gem'
153
+ pngname = root + '.png'
154
+ command = system("scrot -ow #{win} #{self.dir}/#{pngname}")
155
+ shots << pngname
156
+ end
157
+ return shots
158
+ end
159
+
160
+ end
161
+
162
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mdfiller
4
+
5
+ class Filler
6
+
7
+ attr_reader :dir, :orcs_and_scos, :csds, :pys, :pngs, :pds
8
+
9
+ def initialize(dir = '.')
10
+ @dir = dir
11
+ @orcs_and_scos = parse_orcs_and_scos
12
+ @csds = parse_csds
13
+ @pys = parse_pys
14
+ @pngs = parse_pngs
15
+ @pds = parse_pds
16
+ end
17
+
18
+ def generate
19
+ result = header
20
+ result += "\n### Lavagne\n\n"
21
+ result += self.pngs.fill
22
+ result += "\n### Codice\n\n"
23
+ result += self.orcs_and_scos.fill
24
+ result += self.csds.fill
25
+ result += self.pys.fill
26
+ result += self.pds.fill
27
+ return result
28
+ end
29
+
30
+ private
31
+
32
+ def header
33
+ return "\n<!-- Filled in automatically by Mdfiller v.#{Mdfiller::VERSION} -->\n\n"
34
+ end
35
+
36
+ def parse_orcs_and_scos
37
+ files = parse('.[os][rc][co]')
38
+ return OrcAndScoFill.new(files, dir=self.dir)
39
+ end
40
+
41
+ def parse_csds
42
+ files = parse('.csd')
43
+ return CsdFill.new(files, dir=self.dir)
44
+ end
45
+
46
+ def parse_pys
47
+ files = parse('.py')
48
+ return PyFill.new(files, dir=self.dir)
49
+ end
50
+
51
+ def parse_pngs
52
+ files = parse('.png')
53
+ return PngFill.new(files, dir=self.dir)
54
+ end
55
+
56
+ def parse_pds
57
+ files = parse('.pd')
58
+ return PdFill.new(files, dir=self.dir)
59
+ end
60
+
61
+ def parse(sfx)
62
+ return Dir.glob(File.join("#{self.dir}", "*#{sfx}")).map { |f| File.basename(f) }
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mdfiller
4
+ VERSION = "1.0.0"
5
+ end
data/lib/mdfiller.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mdfiller/version"
4
+
5
+ module Mdfiller
6
+ class Error < StandardError; end
7
+
8
+ LIBPATH = File.expand_path(File.join('..', 'mdfiller'), __FILE__)
9
+
10
+ %w{
11
+ fill
12
+ filler
13
+ }.each { |f| require(File.join(LIBPATH, f)) }
14
+
15
+ end
data/sig/mdfiller.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Mdfiller
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdfiller
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicola Bernardini
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2024-11-13 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: mdfiller fills the README.md of each lesson with all its details
13
+ email:
14
+ - nicola.bernardini.rome@gmail.com
15
+ executables:
16
+ - mdf
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".ruby-gemset"
22
+ - ".ruby-version"
23
+ - README.md
24
+ - Rakefile
25
+ - exe/mdf
26
+ - lib/mdfiller.rb
27
+ - lib/mdfiller/fill.rb
28
+ - lib/mdfiller/filler.rb
29
+ - lib/mdfiller/version.rb
30
+ - sig/mdfiller.rbs
31
+ homepage: https://gitlab.com/nicb/mdfiller
32
+ licenses: []
33
+ metadata:
34
+ allowed_push_host: https://rubygems.org
35
+ homepage_uri: https://gitlab.com/nicb/mdfiller
36
+ source_code_uri: https://gitlab.com/nicb/mdfiller
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 3.0.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.6.0.dev
52
+ specification_version: 4
53
+ summary: Markdown lesson filler
54
+ test_files: []