ready 0.0.1 → 0.0.2

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.
data/extra/formatter ADDED
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env zsh
2
+
3
+ SCRIPT_DIR=${0:A:h}
4
+ file=$1
5
+ typeset -x temp=$(mktemp)
6
+ cat $file > $temp
7
+ {
8
+ $SCRIPT_DIR/by -e "$(cat <<'EOF'
9
+
10
+ require 'prism'
11
+
12
+ TERM_RE = /_term/
13
+
14
+ def classify(code)
15
+ return :text if code.lines.all? { |l| l.strip.empty? || l.start_with?("#") }
16
+ clean = code.gsub(/---/, "")
17
+ r = Prism.parse(clean)
18
+ return :code if r.errors.empty?
19
+ has_term = r.errors.any? { |e| e.type.to_s.match?(TERM_RE) }
20
+ if has_term
21
+ (1..5).each do |n|
22
+ return :incomplete_code if Prism.parse(clean + ("\nend" * n)).errors.empty?
23
+ end
24
+ end
25
+ :text
26
+ end
27
+
28
+ def flush(buf, mode)
29
+ return if buf.empty?
30
+ text = buf.join("\n\n")
31
+ # Convert definition lists (term\n: desc) to term\n desc
32
+ # so glow doesn't render them with the 🠶 character
33
+ text.gsub!(/^: /m, " ")
34
+ if mode == :code
35
+ puts "```ruby"
36
+ puts text
37
+ puts "```"
38
+ else
39
+ puts text
40
+ end
41
+ puts
42
+ end
43
+
44
+ buf = []
45
+ mode = nil
46
+ accumulating = false
47
+
48
+ File.open(ENV.fetch("temp")).each("\n\n", chomp: true) do |para|
49
+ para.chomp!
50
+ next if para.strip.empty?
51
+
52
+ if accumulating
53
+ buf << para
54
+ combined_cls = classify(buf.join("\n"))
55
+ if combined_cls == :code
56
+ flush(buf, :code)
57
+ buf = []
58
+ mode = nil
59
+ accumulating = false
60
+ elsif combined_cls == :incomplete_code
61
+ # keep accumulating
62
+ else
63
+ # new paragraph broke it — flush accumulated as code, reprocess current
64
+ current = buf.pop
65
+ flush(buf, :code)
66
+ buf = []
67
+ accumulating = false
68
+
69
+ cls = classify(current)
70
+ if cls == :incomplete_code
71
+ accumulating = true
72
+ mode = :code
73
+ buf = [current]
74
+ else
75
+ mode = cls == :code ? :code : :text
76
+ buf = [current]
77
+ end
78
+ end
79
+ else
80
+ cls = classify(para)
81
+ if cls == :incomplete_code
82
+ if mode && mode != :code
83
+ flush(buf, mode)
84
+ buf = []
85
+ end
86
+ mode = :code
87
+ buf << para
88
+ accumulating = true
89
+ else
90
+ cur = cls == :code ? :code : :text
91
+ if mode && mode != cur
92
+ flush(buf, mode)
93
+ buf = []
94
+ end
95
+ mode = cur
96
+ buf << para
97
+ end
98
+ end
99
+ end
100
+
101
+ flush(buf, mode)
102
+ exit
103
+ warn :done
104
+ EOF
105
+ )"
106
+ } always {
107
+ rm -f $temp
108
+ }
@@ -0,0 +1,92 @@
1
+ require 'prism'
2
+
3
+ TERM_RE = /_term/
4
+
5
+ def classify(code)
6
+ return :text if code.lines.all? { |l| l.strip.empty? || l.start_with?("#") }
7
+ clean = code.gsub(/---/, "")
8
+ r = Prism.parse(clean)
9
+ return :code if r.errors.empty?
10
+ has_term = r.errors.any? { |e| e.type.to_s.match?(TERM_RE) }
11
+ if has_term
12
+ (1..5).each do |n|
13
+ return :incomplete_code if Prism.parse(clean + ("\nend" * n)).errors.empty?
14
+ end
15
+ end
16
+ :text
17
+ end
18
+
19
+ def flush(buf, mode)
20
+ return if buf.empty?
21
+ text = buf.join("\n\n")
22
+ # Convert definition lists (term\n: desc) to term\n desc
23
+ # so glow doesn't render them with the 🠶 character
24
+ text.gsub!(/^: /m, " ")
25
+ if mode == :code
26
+ puts "```ruby"
27
+ puts text
28
+ puts "```"
29
+ else
30
+ puts text
31
+ end
32
+ puts
33
+ end
34
+
35
+ buf = []
36
+ mode = nil
37
+ accumulating = false
38
+
39
+ ARGF.to_io.each("\n\n", chomp: true) do |paragraph|
40
+ paragraph.chomp!
41
+ next if paragraph.strip.empty?
42
+
43
+ if accumulating
44
+ buf << paragraph
45
+ combined_cls = classify(buf.join("\n"))
46
+ if combined_cls == :code
47
+ flush(buf, :code)
48
+ buf = []
49
+ mode = nil
50
+ accumulating = false
51
+ elsif combined_cls == :incomplete_code
52
+ # keep accumulating
53
+ else
54
+ # new paragraph broke it — flush accumulated as code, reprocess current
55
+ current = buf.pop
56
+ flush(buf, :code)
57
+ buf = []
58
+ accumulating = false
59
+
60
+ cls = classify(current)
61
+ if cls == :incomplete_code
62
+ accumulating = true
63
+ mode = :code
64
+ buf = [current]
65
+ else
66
+ mode = cls == :code ? :code : :text
67
+ buf = [current]
68
+ end
69
+ end
70
+ else
71
+ cls = classify(paragraph)
72
+ if cls == :incomplete_code
73
+ if mode && mode != :code
74
+ flush(buf, mode)
75
+ buf = []
76
+ end
77
+ mode = :code
78
+ buf << paragraph
79
+ accumulating = true
80
+ else
81
+ cur = cls == :code ? :code : :text
82
+ if mode && mode != cur
83
+ flush(buf, mode)
84
+ buf = []
85
+ end
86
+ mode = cur
87
+ buf << paragraph
88
+ end
89
+ end
90
+ end
91
+
92
+ flush(buf, mode)
data/extra/ri.rb ADDED
@@ -0,0 +1,78 @@
1
+ require "rdoc/ri"
2
+ require "rdoc/ri/driver"
3
+
4
+ ready_defaults = {
5
+ use_home: false,
6
+ use_site: false,
7
+ use_system: true,
8
+ use_gems: true,
9
+ use_stdout: true,
10
+ formatter: RDoc::Markup::ToAnsi
11
+ }
12
+
13
+ $ri_driver = RDoc::RI::Driver.new
14
+ # warm the cache
15
+ $ri_driver.classes
16
+
17
+ RDoc::RI::Driver.define_method :assign_attributes do |initial_options = {}|
18
+ @paging = false
19
+
20
+ original_default_options = self.class.default_options.update({})
21
+ default_options = original_default_options.merge(ready_defaults)
22
+ options = default_options.merge(initial_options)
23
+ # quick hack for now, optparse is the real one setting the defaults
24
+ options.merge!(ready_defaults)
25
+
26
+ @formatter_klass = options[:formatter]
27
+
28
+ require "profile" if options[:profile]
29
+
30
+ @names = options[:names]
31
+ @list = options[:list]
32
+ @list_doc_dirs = options[:list_doc_dirs]
33
+ @interactive = options[:interactive]
34
+ @server = options[:server]
35
+ @use_stdout = options[:use_stdout]
36
+ @show_all = options[:show_all]
37
+ @width = options[:width]
38
+ @expand_refs = options[:expand_refs]
39
+ end
40
+
41
+ RDoc::RI::Driver.define_method :classes_and_includes_and_extends_for do |name|
42
+ klasses = []
43
+ extends = []
44
+ includes = []
45
+
46
+ candidate_stores = classes[name] || [] # only stores that actually have `name`
47
+
48
+ found = candidate_stores.map do |store|
49
+ begin
50
+ klass = store.load_class name
51
+ klasses << klass
52
+ extends << [klass.extends, store] if klass.extends
53
+ includes << [klass.includes, store] if klass.includes
54
+ [store, klass]
55
+ rescue RDoc::Store::MissingFileError
56
+ end
57
+ end.compact
58
+
59
+ extends.reject! do |modules,|
60
+ modules.empty?
61
+ end
62
+
63
+ includes.reject! do |modules,|
64
+ modules.empty?
65
+ end
66
+
67
+ [found, klasses, includes, extends]
68
+ end
69
+
70
+ RDoc::RI::Driver.define_singleton_method :run do |argv|
71
+ options = process_args argv
72
+ if options[:dump_path]
73
+ dump options[:dump_path]
74
+ return
75
+ end
76
+ $ri_driver.assign_attributes(options)
77
+ $ri_driver.run
78
+ end