ffast 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3942d57d80b4c4a1cd1c8ff40f18cc56508a51f4b6cae53480536f7c36a60b05
4
- data.tar.gz: b60976ea570cf722ae6face8541881c6a1231b2d645727f25231a05c9f33f7ee
3
+ metadata.gz: ce52e9ab5a9d9da32683b21584af707cf5c87e460f3bd74297e9038ea38c5494
4
+ data.tar.gz: 2b68a433982c97f278829b95234aed4ea5e4aec19264f15f9bfbe8615da19c9a
5
5
  SHA512:
6
- metadata.gz: c4df11570f2b2cc164dbd43815a37443541c98c955d6c84ea0b24564fd03b8534cf73479844393ecd72c794231ad40baf678784f9863a8f90c157ac8477f3c9d
7
- data.tar.gz: d9481952776fc77d251a3c9f518f41e20d672298e9ff01b53b8673a0c0bc38f4919e4dd7234365e8044f5cef8e0738823d847900bea790f9796e6d8554342a06
6
+ metadata.gz: 246e52812d6f332636363e9f8dd960fa5e5ad3ecc50666007ae62041a212efc0e17f79dc01a675e15cd862f04bcc6771ac2ede3c8fd98c656b0efe7f34b67ffc
7
+ data.tar.gz: 641af33dbc8858631ae458bc53a4c1b7ce08c44da6788d0cdf7c8c3cae571a9bcb20630f3f9527aeea9a6023a920ac8fe8b0df83672b8280ab8415977114ff4b
data/Fastfile CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  # Fastfile is loaded when you start an expression with a dot.
4
3
  #
5
4
  # You can introduce shortcuts or methods that can be embedded during your
6
5
  # command line interactions with fast.
7
6
  #
8
7
  # Let's say you'd like to show the version that is over the version file
9
- Fast.shortcut(:version, '(casgn nil VERSION (str _))', 'lib/fast/version.rb')
8
+ version_file = Dir['lib/*/version.rb'].first
9
+ Fast.shortcut(:version, '(casgn nil VERSION (str _))', version_file)
10
10
 
11
11
  # Show all classes that inherits Fast::Find
12
12
  Fast.shortcut(:finders, '(class ... (const nil Find)', 'lib')
@@ -21,7 +21,7 @@ Fast.shortcut(:parser, '(class (const nil ExpressionParser)', 'lib/fast.rb')
21
21
 
22
22
  # Use `fast .bump_version` to rewrite the version file
23
23
  Fast.shortcut :bump_version do
24
- rewrite_file('(casgn nil VERSION (str _)', 'lib/fast/version.rb') do |node|
24
+ rewrite_file('(casgn nil VERSION (str _)', version_file) do |node|
25
25
  target = node.children.last.loc.expression
26
26
  pieces = target.source.split('.').map(&:to_i)
27
27
  pieces.reverse.each_with_index do |fragment, i|
@@ -35,3 +35,59 @@ Fast.shortcut :bump_version do
35
35
  replace(target, "'#{pieces.join('.')}'")
36
36
  end
37
37
  end
38
+
39
+ # List all shortcut with comments
40
+ Fast.shortcut :shortcuts do
41
+ fast_files.each do |file|
42
+ lines = File.readlines(file).map { |line| line.chomp.gsub(/\s*#/, '').strip }
43
+ result = capture_file('(send _ :shortcut $(sym _) ...)', file)
44
+ result = [result] unless result.is_a? Array
45
+ result.each do |capture|
46
+ target = capture.loc.expression
47
+ puts "fast .#{target.source[1..].ljust(30)} # #{lines[target.line - 2]}"
48
+ end
49
+ end
50
+ end
51
+
52
+ # Use to walkthrough the docs files with fast examples
53
+ # fast .intro
54
+ Fast.shortcut :intro do
55
+ ARGV << File.join(File.dirname(__FILE__), 'docs', 'walkthrough.md')
56
+
57
+ Fast.shortcuts[:walk].run
58
+ end
59
+
60
+ # Useful for `fast .walk file.md` but not required by the library.
61
+ private
62
+ def require_or_install_tty_md
63
+ require 'tty-markdown'
64
+ rescue LoadError
65
+ puts 'Installing tty-markdown gem to better engage you :)'
66
+ Gem.install('tty-markdown')
67
+ puts 'Done! Now, back to our topic \o/'
68
+ system('clear')
69
+ retry
70
+ end
71
+
72
+ # Interactive command line walkthrough
73
+ # fast .walk docs/walkthrough.md
74
+ Fast.shortcut :walk do
75
+ require_or_install_tty_md
76
+ file = ARGV.last
77
+ execute = ->(line) { system(line) }
78
+ walk = ->(line) { line.each_char { |c| sleep(0.02) and print(c) } }
79
+ File.readlines(file).each do |line|
80
+ case line
81
+ when /^fast /
82
+ walk[line]
83
+ execute[line]
84
+ when /^\$ /
85
+ walk[line]
86
+ execute[line[2..]]
87
+ when /^!{3}\s/
88
+ # Skip warnings that are only for web tutorials
89
+ else
90
+ walk[TTY::Markdown.parse(line)]
91
+ end
92
+ end
93
+ end