jocasta 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/jocasta +98 -0
  3. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: be8246d25880ca812759b249f7a8bbc76f3173349d87b1892426408b4a030100
4
+ data.tar.gz: e69ff3381bc18bf0154a78d9bf76a66c1a0cda198d6cda6dc3edb3b914941622
5
+ SHA512:
6
+ metadata.gz: 81396a17c717d9064a68dcfc63d34e921523dea26e05a97d12376be92ea8e415961c9bec5967e882806b3e3b6f075cc260d272dec6dc4ff6790bebc473c2a3b8
7
+ data.tar.gz: ed86d395be2b1d6de211b0fe5f41c8c0871a746a5137e41ce7c7982bc7a524c5e6e7220fbd77e3b19e72fb80ae9cc732d9a1f267fcbe8cc18f11e003bd8c6c8a
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'json'
5
+
6
+ # This script is based on a script by ReSwift that can be found at
7
+ # https://github.com/ReSwift/ReSwift/blob/master/.scripts/doc-preprocessor
8
+
9
+ def parse_options(paired_args)
10
+ options = { args: [] }
11
+ index = 0
12
+ while index < ARGV.length
13
+ arg = ARGV[index]
14
+
15
+ paired_key = paired_args[arg]
16
+ if paired_key
17
+ if index >= ARGV.length - 1
18
+ puts "Unable to find a value for the arg: '#{arg}'"
19
+ exit 1
20
+ end
21
+ options[paired_key] = ARGV[index + 1]
22
+ index += 1
23
+ elsif /--.+/ =~ arg
24
+ puts 'unknown option: ' + arg
25
+ else
26
+ options[:args].push arg
27
+ end
28
+ index += 1
29
+ end
30
+ options
31
+ end
32
+
33
+ def require_args(args, count)
34
+ return unless args.length != count
35
+
36
+ puts 'usage: jocasta [input] [output] [level] [section] [...options]'
37
+ exit 1
38
+ end
39
+
40
+ def get_section(content, level, section)
41
+ result = nil
42
+ found = false
43
+ content.split("\n").each do |line|
44
+ if /^\#{#{level}}\s*#{section}\s*$/ =~ line
45
+ result = ''
46
+ found = true
47
+ else
48
+ next unless found
49
+
50
+ break if /^\#{1,#{level}}\s*\w/ =~ line
51
+
52
+ result += "\n" + line
53
+ end
54
+ end
55
+ result
56
+ end
57
+
58
+ paired_args = {
59
+ '--title' => :title
60
+ }
61
+ options = parse_options paired_args
62
+
63
+ require_args options[:args], 4
64
+ file_in = options[:args][0]
65
+ file_out = options[:args][1]
66
+ level = options[:args][2].to_i
67
+ section_name = options[:args][3]
68
+
69
+ input = IO.read(file_in)
70
+
71
+ # -----
72
+
73
+ result = get_section input, level, section_name
74
+ unless result
75
+ puts "Unable to find section: '" + section_name + "'"
76
+ exit 1
77
+ end
78
+
79
+ level_hash = ''
80
+ (1..level).each do
81
+ level_hash += '#'
82
+ end
83
+ result = if options[:title]
84
+ "#{level_hash} #{options[:title]}\n" + result
85
+ else
86
+ "#{level_hash} #{section_name}\n" + result
87
+ end
88
+
89
+ # -----
90
+
91
+ if result == ''
92
+ puts 'Not writing output as result is empty'
93
+ exit 1
94
+ end
95
+
96
+ IO.write(file_out, result)
97
+
98
+ puts "[Processed]: #{file_out}"
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jocasta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Duarte Pinto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: duartemr.pinto@gmail.com
15
+ executables:
16
+ - jocasta
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/jocasta
21
+ homepage: https://rubygems.org/gems/jocasta
22
+ licenses:
23
+ - Apache-2.0
24
+ metadata:
25
+ source_code_uri: https://github.com/duartepinto/jocasta
26
+ bug_tracker_uri: https://github.com/duartepinto/jocasta/issues
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.0.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Utility to extract a section of a Markdown file and write it into a separate
46
+ file.
47
+ test_files: []