cheatorious 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +47 -0
- data/GEM_VERSION +1 -1
- data/README.md +59 -23
- data/bin/cheatorious +2 -17
- data/examples/simple_vim +0 -0
- data/{bin/vim_example.rb → examples/simple_vim.rb} +0 -0
- data/examples/writer_sample.rb +70 -0
- data/lib/cheatorious.rb +10 -0
- data/lib/cheatorious/cheatsheet.rb +2 -13
- data/lib/cheatorious/cli.rb +130 -0
- data/lib/cheatorious/search.rb +39 -14
- data/lib/cheatorious/writer/text.rb +10 -9
- metadata +10 -7
- data/lib/tasks/task_sample.rake +0 -7
data/CHANGELOG.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#v0.2.0 (Dec/29 2011 09:59 -0200 by Luis Cipriani)
|
2
|
+
|
3
|
+
Changes:
|
4
|
+
|
5
|
+
- Changed Writer#header and constructor method signature
|
6
|
+
- Command line interface parser now is done by Thor
|
7
|
+
|
8
|
+
Features:
|
9
|
+
|
10
|
+
- Added the following commands to the command line interface
|
11
|
+
- list
|
12
|
+
- import
|
13
|
+
- view
|
14
|
+
- search
|
15
|
+
- writers
|
16
|
+
- alias
|
17
|
+
- All the settings and compiled cheatsheets are saved to .cheatorious home folder
|
18
|
+
- Provided reverse, section, sensitive search filters
|
19
|
+
- Added simple_vim sample by default to every installation
|
20
|
+
|
21
|
+
#v0.1.1 (2011-12-12)
|
22
|
+
|
23
|
+
Bugfixes:
|
24
|
+
|
25
|
+
- Configured executables in the gemspec file
|
26
|
+
|
27
|
+
# v0.1.0 (2011-12-12)
|
28
|
+
|
29
|
+
Features:
|
30
|
+
|
31
|
+
- basic gem structure and initial implementation of DSL
|
32
|
+
- dsl now support keyboard key settings
|
33
|
+
- maintaining a reverse index for other types of searches
|
34
|
+
- Ruby DSL to create your cheatsheets
|
35
|
+
- Command-line interface
|
36
|
+
- input the cheatsheet file
|
37
|
+
- full listing
|
38
|
+
- search by keyword
|
39
|
+
- Compilation
|
40
|
+
- marshal serialization
|
41
|
+
- base64 serialization
|
42
|
+
- serialized types verification
|
43
|
+
- Writers (output formating)
|
44
|
+
- simple text ouptut
|
45
|
+
|
46
|
+
----
|
47
|
+
_this cheatsheet is generated by [step-up](https://github.com/kawamanza/step-up)_
|
data/GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v0.
|
1
|
+
v0.2.0+1
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Create a file and use the following syntax, shown in the example below:
|
|
25
25
|
author "Luis Cipriani", "github.com/lfcipriani"
|
26
26
|
version "1.0.0"
|
27
27
|
|
28
|
-
# you can configure some keyboard keys variables
|
28
|
+
# you can configure some keyboard keys variables, you can change it later to fit your personal preferences
|
29
29
|
key :control, "^"
|
30
30
|
key :esc , "<esc>"
|
31
31
|
key :leader , ","
|
@@ -53,48 +53,84 @@ Create a file and use the following syntax, shown in the example below:
|
|
53
53
|
section "Files" do
|
54
54
|
__ "Open file", ":e"
|
55
55
|
|
56
|
-
# you can go infinitely deep with sections
|
56
|
+
# you can go infinitely deep with sections (seriously)
|
57
57
|
section "Saving" do
|
58
58
|
__ "Save file", ":w"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
## Compiling your cheatsheet ##
|
64
|
-
|
65
|
-
In this alpha version, the compilation is transparently done by cheatorious, but in future versions you'll be able to:
|
66
|
-
|
67
|
-
* serialize your cheatsheet for exporting
|
68
|
-
* export in Base64 to make the search faster
|
69
|
-
* export a standalone executable script
|
70
|
-
|
71
63
|
## Using cheatorious ##
|
72
64
|
|
73
65
|
The CLI usage goes as follows:
|
74
66
|
|
75
|
-
$ cheatorious
|
67
|
+
$ cheatorious # get help
|
68
|
+
$ cheatorious help [TASK] # get help for a specific task
|
69
|
+
$ cheatorious import FILE # import a cheatsheet description FILE (example above)
|
70
|
+
$ cheatorious list # lists the available cheatsheets
|
71
|
+
$ cheatorious view CHEATSHEET [OPTIONS] # view a CHEATSHEET
|
76
72
|
|
77
|
-
|
73
|
+
To search on your cheatsheets:
|
74
|
+
|
75
|
+
$ cheatorious help search
|
76
|
+
Usage:
|
77
|
+
cheatorious search CHEATSHEET [KEYWORD] [OPTIONS]
|
78
78
|
|
79
|
-
|
79
|
+
Options:
|
80
|
+
-s, [--section] # matches KEYWORD only on section names, returning all entries and sections inside it.
|
81
|
+
-r, [--reverse] # reverse means to search only the values of a cheatsheet (and not entries, as usual). For example, search by shortcuts.
|
82
|
+
-S, [--sensitive] # case sensitive search (insensitive is default).
|
83
|
+
-w, [--writer=WRITER] # writer to use for the output. If not set, uses the default.
|
80
84
|
|
81
|
-
|
85
|
+
search for KEYWORD in CHEATSHEET entries only.
|
86
|
+
The CHEATSHEET variable could be a name (for imported cheatsheets) or a file that describes a cheatsheet.
|
87
|
+
Omit KEYWORD to view the full cheatsheet.
|
88
|
+
|
89
|
+
If you are tired to type everything above to do a simple search, use the alias command:
|
90
|
+
|
91
|
+
$ bin/cheatorious help alias
|
92
|
+
Usage:
|
93
|
+
cheatorious alias NAME CHEATSHEET
|
94
|
+
|
95
|
+
return a shell alias command with NAME for easy access to searching a CHEATSHEET.
|
96
|
+
The CHEATSHEET variable must be an imported cheatsheet.
|
97
|
+
Example: cheatorious alias svim simple_vim >> ~/.bashrc
|
98
|
+
next time just use: svim KEYWORD [OPTIONS]
|
99
|
+
|
100
|
+
The command will just show the command, it's up to you to decide where to put it.
|
82
101
|
|
83
|
-
|
84
|
-
* reverse search
|
85
|
-
* standalone script generation
|
86
|
-
* case sensitive search
|
87
|
-
* better ouput layout, colored
|
88
|
-
* more features in command line
|
89
|
-
* other output writers
|
102
|
+
## Writers ##
|
90
103
|
|
91
|
-
|
104
|
+
Cheatorious has a default Text writer to give a fairly nice output for your cheatsheet. Since we can have multiple writers avaiable, you can list and set a default writer through the command *writers*:
|
105
|
+
|
106
|
+
$ bin/cheatorious help writers
|
107
|
+
Usage:
|
108
|
+
cheatorious writers [OPTIONS]
|
109
|
+
|
110
|
+
Options:
|
111
|
+
-d, [--default=DEFAULT] # set a default writer for next searches.
|
112
|
+
|
113
|
+
lists the available writers or set a default
|
114
|
+
|
115
|
+
I'll work to provide more options of output as soon as possible (markdown, colored, HTML, etc), but you can also contribute writing your own writers and sending a pull request to this project. Check the examples folder to see a Writer sample, you just need to implement that interface.
|
116
|
+
|
117
|
+
## Tips to improve the experience! ##
|
92
118
|
|
93
119
|
* In Macs, cheatorious is very powerful if used with [DTerm](http://decimus.net/DTerm)
|
120
|
+
* Create aliases to save typings in the cheatsheets you use more
|
121
|
+
* Sync your cheatsheets with Dropbox by creating a symlink for the `~/.cheatorious` folder
|
122
|
+
|
123
|
+
## TODO ##
|
124
|
+
|
125
|
+
* standalone script generation (works indenpendently of cheatorious being installed or not)
|
126
|
+
* more writers, better ouput layout, colored
|
127
|
+
* more cheatsheets
|
94
128
|
|
95
129
|
## Contributing ##
|
96
130
|
|
97
|
-
|
131
|
+
If you have cheatsheets, share with us at [cheatorious cheatsheet repository](https://github.com/lfcipriani/cheatorious-cheatsheets).
|
132
|
+
|
133
|
+
You can also contribute in the Core or Writers, feel free to:
|
98
134
|
|
99
135
|
* Fork
|
100
136
|
* Implement tests
|
data/bin/cheatorious
CHANGED
@@ -1,19 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
def cheatsheet_for(name, &block)
|
4
|
-
@cheatsheet_model = Cheatorious::CheatSheet.compile(name, &block)
|
5
|
-
end
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/cheatorious')
|
6
3
|
|
7
|
-
|
8
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/cheatorious')
|
9
|
-
|
10
|
-
if File.exist?(ARGV[0])
|
11
|
-
load ARGV[0]
|
12
|
-
result = Cheatorious::Search.execute(@cheatsheet_model, ARGV[1] || "")
|
13
|
-
puts result
|
14
|
-
else
|
15
|
-
puts "File not found: #{ARGV[0]}"
|
16
|
-
end
|
17
|
-
else
|
18
|
-
puts "Usage: cheatorious cheatsheet_file [keyword]"
|
19
|
-
end
|
4
|
+
Cheatorious::CLI.start
|
data/examples/simple_vim
ADDED
Binary file
|
File without changes
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Cheatorious
|
2
|
+
module Writer
|
3
|
+
# This is an example of a Writer
|
4
|
+
#
|
5
|
+
# To implement your own Writer, just create a class inside
|
6
|
+
# Cheatorious::Writer module and implement the interface
|
7
|
+
# represented by the public methods below.
|
8
|
+
class WriterSample
|
9
|
+
def initialize
|
10
|
+
@section_stack = []
|
11
|
+
@result = ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def header(name, author = "", version = "", description = "")
|
15
|
+
line
|
16
|
+
line "-" * 80
|
17
|
+
line "#{name} (#{version})"
|
18
|
+
line
|
19
|
+
line "Author : #{author[0]} (#{author[1]})"
|
20
|
+
line "Description: #{description}"
|
21
|
+
line "-" * 80
|
22
|
+
line
|
23
|
+
end
|
24
|
+
|
25
|
+
def search_header(query, results_count, options)
|
26
|
+
search_type = options.keys.join(", ")
|
27
|
+
search_type += " " if search_type.size > 0
|
28
|
+
line
|
29
|
+
line "Your #{search_type}search for '#{query}' returned #{results_count} #{results_count > 1 ? "results" : "result"}:" if results_count != 0
|
30
|
+
line "Your #{search_type}search for '#{query}' doesn't returned any result. Try with another keyword." if results_count == 0
|
31
|
+
line
|
32
|
+
end
|
33
|
+
|
34
|
+
def footer
|
35
|
+
line
|
36
|
+
line "-" * 80
|
37
|
+
line "generated by Cheatorious (https://github.com/lfcipriani/cheatorious)"
|
38
|
+
end
|
39
|
+
|
40
|
+
def section_start(section)
|
41
|
+
@section_stack.push(section)
|
42
|
+
line indentation("-") + " #{section}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def section_end
|
46
|
+
@section_stack.pop
|
47
|
+
end
|
48
|
+
|
49
|
+
def entry(name, *values)
|
50
|
+
e = "#{indentation(" ")} - #{name}: "
|
51
|
+
e << values.join(", ")
|
52
|
+
line e
|
53
|
+
end
|
54
|
+
|
55
|
+
def result
|
56
|
+
@result
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def line(str = "")
|
62
|
+
@result += str + "\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
def indentation(char)
|
66
|
+
char * 2 * @section_stack.size
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/cheatorious.rb
CHANGED
@@ -5,8 +5,18 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))
|
|
5
5
|
require "rubygems"
|
6
6
|
require "bundler/setup"
|
7
7
|
|
8
|
+
# Adding Dir.home method if it's not available
|
9
|
+
unless Dir.respond_to?(:home)
|
10
|
+
class Dir
|
11
|
+
def self.home
|
12
|
+
File.expand_path(File.join("~"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
# Gem requirements
|
9
18
|
module Cheatorious
|
19
|
+
autoload :CLI , "cheatorious/cli"
|
10
20
|
autoload :CheatSheet, "cheatorious/cheatsheet"
|
11
21
|
autoload :Utils , "cheatorious/utils"
|
12
22
|
autoload :Search , "cheatorious/search"
|
@@ -17,8 +17,7 @@ module Cheatorious
|
|
17
17
|
@cheat_hash = {
|
18
18
|
:info => { :name => name },
|
19
19
|
:cheatsheet => {
|
20
|
-
:root => []
|
21
|
-
:reverse => {}
|
20
|
+
:root => []
|
22
21
|
}
|
23
22
|
}
|
24
23
|
@current_section = @cheat_hash[:cheatsheet][:root]
|
@@ -70,12 +69,6 @@ module Cheatorious
|
|
70
69
|
|
71
70
|
values.each do |v|
|
72
71
|
new_entry << v
|
73
|
-
|
74
|
-
reverse_entry = {
|
75
|
-
:name => name,
|
76
|
-
:section => @stack.dup
|
77
|
-
}
|
78
|
-
reverse_index.key?(v) ? reverse_index[v] << reverse_entry : reverse_index[v] = [reverse_entry]
|
79
72
|
end
|
80
73
|
|
81
74
|
@current_section << new_entry
|
@@ -101,10 +94,6 @@ module Cheatorious
|
|
101
94
|
def sheet
|
102
95
|
@cheat_hash[:cheatsheet]
|
103
96
|
end
|
104
|
-
|
105
|
-
def reverse_index
|
106
|
-
@cheat_hash[:cheatsheet][:reverse]
|
107
|
-
end
|
108
|
-
|
97
|
+
|
109
98
|
end
|
110
99
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Cheatorious
|
4
|
+
module DslExecutor
|
5
|
+
def self.cheatsheet_for(name, &block)
|
6
|
+
Cheatorious::CheatSheet.compile(name, @output, &block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class CLI < Thor
|
11
|
+
include Thor::Actions
|
12
|
+
|
13
|
+
desc "list", "lists the available cheatsheets. See 'import' command."
|
14
|
+
def list
|
15
|
+
ensure_workspace_exist
|
16
|
+
puts (cheatsheet_list.empty? ? "You don't have imported cheatsheets. See 'import' command." : "You have #{cheatsheet_list.size} cheatsheet(s):")
|
17
|
+
puts cheatsheet_list.join("\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "import FILE", "import a cheatsheet description FILE.\nCheck https://github.com/lfcipriani/cheatorious to learn how to create your own cheatsheets."
|
21
|
+
def import(file)
|
22
|
+
ensure_workspace_exist
|
23
|
+
name = File.basename(file, ".rb")
|
24
|
+
return if cheatsheet_list.include?(name) &&
|
25
|
+
!yes?("Do you want to override the existent #{name} cheatsheet? (y/n)")
|
26
|
+
if File.exist?(file)
|
27
|
+
source = File.read(file)
|
28
|
+
bytes = DslExecutor.module_eval("@output = :bytes\n"+source)
|
29
|
+
File.open(File.join(workspace_path, "compiled", name), 'w') {|f| f.write(bytes) }
|
30
|
+
File.open(File.join(workspace_path, "originals", name + ".rb"), 'w') {|f| f.write(source) }
|
31
|
+
puts "Cheatsheet imported successfuly! Try 'cheatorious view #{name}'\nThe original cheatsheet file was copied to #{File.join(workspace_path, "originals", name + ".rb")}"
|
32
|
+
else
|
33
|
+
puts "The specified file doesn't exist: #{file}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "view CHEATSHEET [OPTIONS]", "view a CHEATSHEET.\nThe CHEATSHEET variable could be a name (for imported cheatsheets) or a file that describes a cheatsheet."
|
38
|
+
method_option :writer, :aliases => "-w", :type => :string, :desc => "writer to use for the output. If not set, uses the default."
|
39
|
+
def view(cheatsheet)
|
40
|
+
invoke :search
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "search CHEATSHEET [KEYWORD] [OPTIONS]", "search for KEYWORD in CHEATSHEET entries only.\nThe CHEATSHEET variable could be a name (for imported cheatsheets) or a file that describes a cheatsheet.\nOmit KEYWORD to view the full cheatsheet."
|
44
|
+
method_option :section, :aliases => "-s", :type => :boolean, :desc => "matches KEYWORD only on section names, returning all entries and sections inside it."
|
45
|
+
method_option :reverse, :aliases => "-r", :type => :boolean, :desc => "reverse means to search only the values of a cheatsheet (and not entries, as usual). For example, search by shortcuts."
|
46
|
+
method_option :sensitive, :aliases => "-S", :type => :boolean, :desc => "case sensitive search (insensitive is default)."
|
47
|
+
method_option :writer, :aliases => "-w", :type => :string, :desc => "writer to use for the output. If not set, uses the default."
|
48
|
+
def search(cheatsheet, keyword = "")
|
49
|
+
ensure_workspace_exist
|
50
|
+
writer = options["writer"] ? writer_for(options["writer"]) : default_writer
|
51
|
+
model = nil
|
52
|
+
if cheatsheet_list.include?(cheatsheet)
|
53
|
+
model = File.read(File.join(workspace_path, "compiled", cheatsheet))
|
54
|
+
elsif File.exist?(cheatsheet)
|
55
|
+
model = DslExecutor.module_eval("@output = nil\n" + File.read(cheatsheet))
|
56
|
+
end
|
57
|
+
if model
|
58
|
+
puts Cheatorious::Search.execute(model, keyword, writer, options.dup)
|
59
|
+
else
|
60
|
+
puts "Invalid cheatsheet name or file name: #{cheatsheet}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "writers [OPTIONS]", "lists the available writers or set a default"
|
65
|
+
method_option :default, :aliases => "-d", :type => :string, :desc => "set a default writer for next searches."
|
66
|
+
def writers
|
67
|
+
ensure_workspace_exist
|
68
|
+
if options["default"]
|
69
|
+
if Cheatorious::Writer.constants.map {|c| c.to_s}.include?(options["default"])
|
70
|
+
config = YAML.load(File.open(File.join(workspace_path, "config")))
|
71
|
+
config["default_writer"] = options["default"]
|
72
|
+
File.open(File.join(workspace_path, "config"), "w") {|f| f.write(config.to_yaml) }
|
73
|
+
puts "The default writer now is #{options["default"]}"
|
74
|
+
else
|
75
|
+
puts "Invalid writer name, use 'cheatorious writers' to choose one from the available."
|
76
|
+
end
|
77
|
+
else
|
78
|
+
puts "The following writers are available:\n"
|
79
|
+
dw = default_writer.to_s
|
80
|
+
puts Cheatorious::Writer.constants.map {|w| (dw.end_with?(w.to_s) ? w.to_s + " (default)" : w.to_s) }.join("\n")
|
81
|
+
puts "\nUse -d option to set a default writer."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
desc "alias NAME CHEATSHEET", "return a shell alias command with NAME for easy access to searching a CHEATSHEET.\nThe CHEATSHEET variable must be an imported cheatsheet.\nExample: cheatorious alias svim simple_vim >> ~/.bashrc\n next time just use: svim KEYWORD [OPTIONS]"
|
86
|
+
def alias(name, cheatsheet)
|
87
|
+
ensure_workspace_exist
|
88
|
+
if cheatsheet_list.include?(cheatsheet)
|
89
|
+
puts "alias #{name}='cheatorious search #{cheatsheet}'"
|
90
|
+
else
|
91
|
+
puts "Invalid cheatsheet name: #{cheatsheet}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def cheatsheet_list
|
98
|
+
Dir[File.join(workspace_path, "compiled", "*")].map {|c| File.basename(c)}
|
99
|
+
end
|
100
|
+
|
101
|
+
def writer_for(constant)
|
102
|
+
Cheatorious::Writer.const_get(constant)
|
103
|
+
end
|
104
|
+
|
105
|
+
def default_writer
|
106
|
+
writer_for(YAML.load(File.open(File.join(workspace_path, "config")))["default_writer"])
|
107
|
+
end
|
108
|
+
|
109
|
+
def ensure_workspace_exist
|
110
|
+
unless File.directory?(workspace_path)
|
111
|
+
Dir.mkdir(workspace_path)
|
112
|
+
end
|
113
|
+
unless File.exist?(File.join(workspace_path, "config"))
|
114
|
+
create_file File.join(workspace_path, "config"), "default_writer: Text\n", :verbose => false
|
115
|
+
end
|
116
|
+
unless File.directory?(File.join(workspace_path, "compiled"))
|
117
|
+
Dir.mkdir(File.join(workspace_path, "compiled"))
|
118
|
+
FileUtils.cp(File.expand_path(File.join(__FILE__, "..", "..", "..", "examples", "simple_vim")), File.join(workspace_path, "compiled"))
|
119
|
+
end
|
120
|
+
unless File.directory?(File.join(workspace_path, "originals"))
|
121
|
+
Dir.mkdir(File.join(workspace_path, "originals"))
|
122
|
+
FileUtils.cp(File.expand_path(File.join(__FILE__, "..", "..", "..", "examples", "simple_vim.rb")), File.join(workspace_path, "originals"))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def workspace_path
|
127
|
+
@workspace ||= File.join(Dir.home, ".cheatorious")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/cheatorious/search.rb
CHANGED
@@ -14,17 +14,20 @@ module Cheatorious
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def execute(query = "", writer = Writer::Text, options = {})
|
17
|
-
|
17
|
+
info = @cheat_model[:info]
|
18
|
+
options.delete("reverse") if options["section"] && options["reverse"]
|
18
19
|
|
20
|
+
# Filtering
|
19
21
|
filtered = @cheat_model[:cheatsheet][:root].dup
|
20
|
-
unless print_full?(
|
22
|
+
unless print_full?(query)
|
21
23
|
filtered, results_count = depth_search(query, filtered, options)
|
22
24
|
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
# Writing
|
27
|
+
w = writer.new
|
28
|
+
print_full?(query) ? w.header(info[:name], info[:author], info[:version], info[:description]) : w.search_header(query, results_count, options)
|
26
29
|
write_contents(filtered, w, options)
|
27
|
-
w.footer if print_full?(
|
30
|
+
w.footer if print_full?(query)
|
28
31
|
|
29
32
|
return w.result
|
30
33
|
end
|
@@ -33,21 +36,43 @@ module Cheatorious
|
|
33
36
|
|
34
37
|
def depth_search(query, section, options)
|
35
38
|
match_count = 0
|
39
|
+
|
36
40
|
result = section.select do |item|
|
41
|
+
|
37
42
|
if item.kind_of?(Array) #entry
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
unless options["section"]
|
44
|
+
name = item[0]
|
45
|
+
matched = false
|
46
|
+
if options["reverse"]
|
47
|
+
item[1..-1].each do |value|
|
48
|
+
matched = match?(query, value, options["sensitive"])
|
49
|
+
break if matched
|
50
|
+
end
|
51
|
+
else
|
52
|
+
matched = match?(query, name, options["sensitive"])
|
53
|
+
end
|
54
|
+
match_count += 1 if matched
|
55
|
+
matched
|
56
|
+
else
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
42
60
|
elsif item.kind_of?(Hash) #section
|
43
61
|
name = item.keys.first
|
44
|
-
|
62
|
+
if options["section"] && match?(query, name, options["sensitive"])
|
63
|
+
count = 1
|
64
|
+
else
|
65
|
+
item[name], count = depth_search(query, item[name], options)
|
66
|
+
end
|
45
67
|
match_count += count
|
46
68
|
item[name].size > 0
|
69
|
+
|
47
70
|
else
|
48
71
|
false
|
49
72
|
end
|
73
|
+
|
50
74
|
end
|
75
|
+
|
51
76
|
return result, match_count
|
52
77
|
end
|
53
78
|
|
@@ -65,12 +90,12 @@ module Cheatorious
|
|
65
90
|
end
|
66
91
|
end
|
67
92
|
|
68
|
-
def match?(query, name)
|
69
|
-
|
93
|
+
def match?(query, name, sensitive)
|
94
|
+
!(Regexp.new(Regexp.escape(query), (sensitive ? 0 : Regexp::IGNORECASE)) =~ name).nil?
|
70
95
|
end
|
71
96
|
|
72
|
-
def print_full?(
|
73
|
-
|
97
|
+
def print_full?(query)
|
98
|
+
query.empty?
|
74
99
|
end
|
75
100
|
|
76
101
|
end
|
@@ -1,27 +1,28 @@
|
|
1
1
|
module Cheatorious
|
2
2
|
module Writer
|
3
3
|
class Text
|
4
|
-
def initialize
|
5
|
-
@info = cheatsheet_info
|
4
|
+
def initialize
|
6
5
|
@section_stack = []
|
7
6
|
@result = ""
|
8
7
|
end
|
9
8
|
|
10
|
-
def header
|
9
|
+
def header(name, author = "", version = "", description = "")
|
11
10
|
line
|
12
11
|
line "-" * 80
|
13
|
-
line "#{
|
12
|
+
line "#{name} (#{version})"
|
14
13
|
line
|
15
|
-
line "Author : #{
|
16
|
-
line "Description: #{
|
14
|
+
line "Author : #{author[0]} (#{author[1]})"
|
15
|
+
line "Description: #{description}"
|
17
16
|
line "-" * 80
|
18
17
|
line
|
19
18
|
end
|
20
19
|
|
21
|
-
def search_header(query, results_count,
|
20
|
+
def search_header(query, results_count, options)
|
21
|
+
search_type = options.keys.join(", ")
|
22
|
+
search_type += " " if search_type.size > 0
|
22
23
|
line
|
23
|
-
line "Your search for '#{query}' returned #{results_count} #{results_count > 1 ? "
|
24
|
-
line "Your search for '#{query}' doesn't returned any
|
24
|
+
line "Your #{search_type}search for '#{query}' returned #{results_count} #{results_count > 1 ? "results" : "result"}:" if results_count != 0
|
25
|
+
line "Your #{search_type}search for '#{query}' doesn't returned any result. Try with another keyword." if results_count == 0
|
25
26
|
line
|
26
27
|
end
|
27
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheatorious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: step-up
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152693740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152693740
|
25
25
|
description:
|
26
26
|
email: lfcipriani@gmail.com
|
27
27
|
executables:
|
@@ -30,20 +30,23 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
files:
|
32
32
|
- .travis.yml
|
33
|
+
- CHANGELOG.md
|
33
34
|
- LICENSE
|
34
35
|
- README.md
|
35
36
|
- bin/cheatorious
|
36
|
-
- bin/vim_example.rb
|
37
37
|
- cheatorious.gemspec
|
38
|
+
- examples/simple_vim
|
39
|
+
- examples/simple_vim.rb
|
40
|
+
- examples/writer_sample.rb
|
38
41
|
- lib/cheatorious.rb
|
39
42
|
- lib/cheatorious/.gitkeep
|
40
43
|
- lib/cheatorious/cheatsheet.rb
|
44
|
+
- lib/cheatorious/cli.rb
|
41
45
|
- lib/cheatorious/search.rb
|
42
46
|
- lib/cheatorious/utils.rb
|
43
47
|
- lib/cheatorious/version.rb
|
44
48
|
- lib/cheatorious/writer.rb
|
45
49
|
- lib/cheatorious/writer/text.rb
|
46
|
-
- lib/tasks/task_sample.rake
|
47
50
|
- GEM_VERSION
|
48
51
|
homepage: https://github.com/abril/cheatorious
|
49
52
|
licenses: []
|
@@ -59,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
62
|
version: '0'
|
60
63
|
segments:
|
61
64
|
- 0
|
62
|
-
hash:
|
65
|
+
hash: 3692149591727871031
|
63
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
67
|
none: false
|
65
68
|
requirements:
|