my_help 0.8.6 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/'../test'/.my_help/.my_help_conf.yml +2 -0
- data/'../test'/.my_help/emacs.org +50 -0
- data/{lib/templates → '../test'/.my_help}/org.org +0 -0
- data/{lib/templates → '../test'/.my_help}/todo.org +0 -0
- data/.gitignore +7 -0
- data/.my_help/example2.org +9 -0
- data/.rspec +1 -2
- data/.rspec_status +13 -0
- data/.yardoc/checksums +3 -3
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/Gemfile +10 -5
- data/Gemfile.lock +61 -88
- data/README.org +35 -47
- data/Rakefile +25 -14
- data/doc/MyHelp/Control.html +443 -221
- data/doc/MyHelp.html +7 -7
- data/doc/OrgToYaml.html +12 -10
- data/doc/_index.html +7 -7
- data/doc/class_list.html +2 -2
- data/doc/css/style.css +3 -2
- data/doc/file.README.html +29 -29
- data/doc/file_list.html +2 -2
- data/doc/frames.html +2 -2
- data/doc/index.html +29 -29
- data/doc/js/app.js +14 -3
- data/doc/method_list.html +24 -8
- data/doc/top-level-namespace.html +6 -6
- data/docs/README.html +218 -0
- data/docs/README.org +202 -0
- data/docs/old_docs/16b_nasu.pdf +0 -0
- data/docs/old_docs/17b_oyagi.pdf +0 -0
- data/docs/old_docs/19b_okabata.pdf +0 -0
- data/docs/old_docs/19b_yamaguchi.pdf +0 -0
- data/docs/old_docs/features/delete.feature +7 -0
- data/docs/old_docs/features/edit.feature +7 -0
- data/docs/old_docs/features/list.feature +6 -0
- data/docs/old_docs/features/new.feature +7 -0
- data/docs/old_docs/features/step_definitions/delete_spec.rb +12 -0
- data/docs/old_docs/features/step_definitions/edit_spec.rb +14 -0
- data/docs/old_docs/features/step_definitions/list_spec.rb +10 -0
- data/docs/old_docs/features/step_definitions/new_spec.rb +12 -0
- data/docs/old_docs/features/support/env.rb +3 -0
- data/docs/old_docs/fukumori_symp/18_human_interface_fukumori_workshop.pdf +0 -0
- data/docs/old_docs/fukumori_symp/memo_perp_magician.pdf +0 -0
- data/docs/old_docs/fukumori_symp//347/237/245/350/255/230/343/201/256/347/233/264/344/272/244/350/243/234/347/251/272/351/226/223.png +0 -0
- data/exe/my_help +1 -142
- data/lib/my_help/cli.rb +106 -0
- data/lib/my_help/config.rb +70 -0
- data/lib/my_help/git_cli.rb +40 -0
- data/lib/my_help/init.rb +28 -0
- data/lib/my_help/list.rb +76 -0
- data/lib/my_help/md2hash.rb +54 -0
- data/lib/my_help/modify.rb +33 -0
- data/lib/my_help/org2hash.rb +45 -0
- data/lib/my_help/org2yml.rb +14 -14
- data/lib/my_help/version.rb +3 -1
- data/lib/my_help.rb +23 -7
- data/lib/templates/emacs.org +13 -14
- data/lib/templates/example.md +17 -0
- data/lib/templates/example.org +9 -0
- data/my_help.gemspec +26 -22
- data/tmp.txt +14 -0
- metadata +51 -25
- data/README.html +0 -443
- data/README.rdoc +0 -6
- data/bin/my_help_thor +0 -66
- data/exe/my_help_gli +0 -82
- data/lib/my_help/my_help_controll.rb +0 -222
- data/lib/my_help/tomo_help_controll.rb +0 -0
- data/lib/templates/help_template.org +0 -8
data/exe/my_help
CHANGED
@@ -1,145 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'thor'
|
3
2
|
require 'my_help'
|
4
|
-
require 'colorize'
|
5
|
-
require 'command_line/global'
|
6
3
|
|
7
|
-
|
8
|
-
desc('setup', 'set up the test database')
|
9
|
-
def setup(*args)
|
10
|
-
$control = MyHelp::Control.new()
|
11
|
-
end
|
12
|
-
|
13
|
-
desc "list [HELP] [ITEM]", "list all helps, specific HELP, or ITEM"
|
14
|
-
def list(*args)
|
15
|
-
invoke :setup
|
16
|
-
file = args[0]
|
17
|
-
item = args[1]
|
18
|
-
if file.nil?
|
19
|
-
puts $control.list_all.blue # list []
|
20
|
-
elsif item.nil?
|
21
|
-
begin
|
22
|
-
puts $control.list_help(file) # list [file]
|
23
|
-
rescue => e
|
24
|
-
puts e.to_s.red
|
25
|
-
end
|
26
|
-
else
|
27
|
-
begin
|
28
|
-
puts $control.show_item(file, item) # list [file] [item]
|
29
|
-
rescue => e
|
30
|
-
puts e.to_s.red
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
desc "version", "show version"
|
36
|
-
def version
|
37
|
-
invoke :setup
|
38
|
-
puts MyHelp::VERSION
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "set_editor EDITOR_NAME", "set editor to EDITOR_NAME"
|
42
|
-
def set_editor(editor_name)
|
43
|
-
invoke :setup
|
44
|
-
$control.set_editor(editor_name)
|
45
|
-
end
|
46
|
-
|
47
|
-
desc "edit HELP", "edit HELP"
|
48
|
-
def edit(help_name)
|
49
|
-
invoke :setup
|
50
|
-
$control.edit_help(help_name)
|
51
|
-
end
|
52
|
-
|
53
|
-
desc "new HELP", "make new HELP"
|
54
|
-
def new(help_name)
|
55
|
-
invoke :setup
|
56
|
-
$control.init_help(help_name)
|
57
|
-
end
|
58
|
-
|
59
|
-
desc "delete HELP", "delete HELP"
|
60
|
-
def delete(help_name)
|
61
|
-
invoke :setup
|
62
|
-
$control.delete_help(help_name)
|
63
|
-
end
|
64
|
-
|
65
|
-
=begin
|
66
|
-
desc "git [push|pull]", "git push or pull"
|
67
|
-
def git(push_or_pull)
|
68
|
-
p push_or_pull
|
69
|
-
invoke :setup
|
70
|
-
dir = $control.local_help_dir
|
71
|
-
Dir.chdir(dir) do
|
72
|
-
case push_or_pull
|
73
|
-
when 'push'
|
74
|
-
comms = ['git add -A',
|
75
|
-
"git commit -m 'git push from my_help'",
|
76
|
-
"git push origin master"]
|
77
|
-
when 'pull'
|
78
|
-
comms = ['git pull origin master']
|
79
|
-
else
|
80
|
-
raise "my_help git was called by the other than 'push or pull'"
|
81
|
-
end
|
82
|
-
comms.each do |comm|
|
83
|
-
c = command_line(comm)
|
84
|
-
puts c.stdout.blue
|
85
|
-
puts c.stderr.red
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
=end
|
90
|
-
|
91
|
-
desc "git [push|pull]", "git push or pull"
|
92
|
-
def git(push_or_pull,*args)
|
93
|
-
p push_or_pull
|
94
|
-
invoke :setup
|
95
|
-
argument_size = args.size
|
96
|
-
Dir.chdir($control.local_help_dir) do
|
97
|
-
case push_or_pull
|
98
|
-
when 'push'
|
99
|
-
if argument_size == 0
|
100
|
-
comms = ['git add -A',
|
101
|
-
"git commit -m 'git push from my_help'",
|
102
|
-
"git push origin master"]
|
103
|
-
else
|
104
|
-
p args
|
105
|
-
argument_size.times do |i|
|
106
|
-
orgfile = args[i] + '.org'
|
107
|
-
file = File.join($control.local_help_dir,orgfile)
|
108
|
-
if File.exist?(file) == true
|
109
|
-
puts orgfile.green
|
110
|
-
dir = $control.local_help_dir
|
111
|
-
Dir.chdir(dir) do
|
112
|
-
comm = 'git add ' + file
|
113
|
-
puts c
|
114
|
-
c = command_line(comm)
|
115
|
-
puts c.stdout.blue
|
116
|
-
puts c.stderr.red
|
117
|
-
end
|
118
|
-
else
|
119
|
-
puts (orgfile + " does not existed").red
|
120
|
-
end
|
121
|
-
end
|
122
|
-
comms = ["git commit -m 'git push from my_help'",
|
123
|
-
"git push origin master"]
|
124
|
-
end
|
125
|
-
when 'pull'
|
126
|
-
comms = ['git pull origin master']
|
127
|
-
else
|
128
|
-
raise "my_help git was called by the other than 'push or pull'"
|
129
|
-
end
|
130
|
-
comms.each do |comm|
|
131
|
-
puts comm
|
132
|
-
c = command_line(comm)
|
133
|
-
puts c.stdout.blue
|
134
|
-
puts c.stderr.red
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
# desc "search {find_char}", "search FIND_CHAR"
|
139
|
-
# def search(find_char)
|
140
|
-
# invoke :setup
|
141
|
-
# $control.search_help(find_char)
|
142
|
-
# end
|
143
|
-
end
|
144
|
-
|
145
|
-
MyCLI.start(ARGV)
|
4
|
+
MyHelp::CLI.start(ARGV)
|
data/lib/my_help/cli.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
module MyHelp
|
2
|
+
class CLI < Thor
|
3
|
+
include GetConfig
|
4
|
+
class_option :help_dir, :type => :string
|
5
|
+
# option :help_dir, :type => :string
|
6
|
+
# option :layer, :type => :numeric
|
7
|
+
|
8
|
+
# THOR to SILENCE DEPRECATION
|
9
|
+
# https://qiita.com/tbpgr/items/5edb1454634157ff816d
|
10
|
+
class << self
|
11
|
+
def exit_on_failure?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "version", "show version"
|
17
|
+
|
18
|
+
def version
|
19
|
+
puts VERSION
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "git [pull|push]", "git operations"
|
23
|
+
subcommand "git", Git
|
24
|
+
|
25
|
+
desc "init", "initialize my_help environment"
|
26
|
+
|
27
|
+
def init(*args)
|
28
|
+
config = get_config # for using methods in Config
|
29
|
+
#config.ask_default
|
30
|
+
init = Init.new(config)
|
31
|
+
raise "Local help dir exist." if init.help_dir_exist?
|
32
|
+
puts "Choose default markup '.org' [Y or .md]? "
|
33
|
+
response = $stdin.gets.chomp
|
34
|
+
config.configure(:ext => response) unless response.upcase[0] == "Y"
|
35
|
+
init.mk_help_dir
|
36
|
+
config.save_config
|
37
|
+
init.cp_templates
|
38
|
+
puts "If you want change editor use my_help set editor code."
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "set [:key] [VAL]", "set editor or ext"
|
42
|
+
|
43
|
+
def set(*args)
|
44
|
+
config = get_config # for using methods in Config
|
45
|
+
key = args[0] || ""
|
46
|
+
config.configure(key.to_sym => args[1])
|
47
|
+
config.save_config
|
48
|
+
conf_file_path = config[:conf_file]
|
49
|
+
puts "conf_file_path: %s" % conf_file_path
|
50
|
+
puts File.read(conf_file_path)
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "list [HELP] [ITEM]", "list helps"
|
54
|
+
# option :help_dir, :type => :string
|
55
|
+
option :layer, :type => :numeric
|
56
|
+
# use method_options [[https://github.com/rails/thor/wiki/Method-Options]]
|
57
|
+
def list(*args)
|
58
|
+
config = get_config
|
59
|
+
help_dir = options["help_dir"] || config[:local_help_dir]
|
60
|
+
layer = options["layer"] || 1
|
61
|
+
puts List.new(help_dir,
|
62
|
+
config[:ext],
|
63
|
+
layer).list(*args.join(" "))
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "edit [HELP]", "edit help"
|
67
|
+
|
68
|
+
def edit(*args)
|
69
|
+
c = get_config
|
70
|
+
help_name = args[0]
|
71
|
+
Modify.new(c).edit(help_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "new [HELP]", "mk new HELP"
|
75
|
+
|
76
|
+
def new(*args)
|
77
|
+
c = get_config
|
78
|
+
help_name = args[0]
|
79
|
+
help_file = File.join(c[:local_help_dir], help_name + c[:ext])
|
80
|
+
Modify.new(c).new(help_file)
|
81
|
+
# puts res.stdout
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "delete [HELP]", "delete HELP"
|
85
|
+
|
86
|
+
def delete(*args)
|
87
|
+
c = get_config
|
88
|
+
help_name = args[0]
|
89
|
+
help_file = File.join(c[:local_help_dir], help_name + c[:ext])
|
90
|
+
puts "Are you sure to delete #{help_file}? [YN]"
|
91
|
+
responce = $stdin.gets.chomp
|
92
|
+
if responce.upcase[0] == "Y"
|
93
|
+
Modify.new(c).delete(help_file)
|
94
|
+
else
|
95
|
+
puts "Leave #{help_file} exists."
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
desc "hello", "hello"
|
100
|
+
|
101
|
+
def hello
|
102
|
+
name = $stdin.gets.chomp
|
103
|
+
puts("Hello #{name}.")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module MyHelp
|
2
|
+
|
3
|
+
# make @config from default and load yaml
|
4
|
+
# as shown
|
5
|
+
# https://stackoverflow.com/questions/6233124/where-to-place-access-config-file-in-gem
|
6
|
+
class Config
|
7
|
+
attr_reader :valid_config_keys
|
8
|
+
# Configuration defaults
|
9
|
+
def initialize(conf_path = nil)
|
10
|
+
conf_path ||= ENV["HOME"]
|
11
|
+
local_help_dir = File.join(conf_path, ".my_help")
|
12
|
+
@config = {
|
13
|
+
template_dir: File.expand_path("../templates", __dir__),
|
14
|
+
local_help_dir: local_help_dir,
|
15
|
+
conf_file: File.join(local_help_dir, ".my_help_conf.yml"),
|
16
|
+
editor: ENV["EDITOR"] || "emacs",
|
17
|
+
ext: ".org",
|
18
|
+
verbose: false,
|
19
|
+
}
|
20
|
+
@valid_config_keys = @config.keys
|
21
|
+
configure_with(@config[:conf_file])
|
22
|
+
# YAML.dump(@config, File.open(@config[:conf_file], 'w'))
|
23
|
+
# no good for multiple testers.
|
24
|
+
end
|
25
|
+
|
26
|
+
# Configure through hash
|
27
|
+
def configure(opts = nil)
|
28
|
+
return if opts == nil
|
29
|
+
opts.each do |k, v|
|
30
|
+
if @valid_config_keys.include? k.to_sym
|
31
|
+
@config[k.to_sym] = v
|
32
|
+
elsif k == "".to_sym
|
33
|
+
print "Valid key words are follows:"
|
34
|
+
p @valid_config_keys
|
35
|
+
else
|
36
|
+
raise KeyError.new("Error: keyword '#{k}' is invalid",
|
37
|
+
receiver: @config,
|
38
|
+
key: k)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@config
|
42
|
+
end
|
43
|
+
|
44
|
+
# Configure through yaml file
|
45
|
+
def configure_with(path)
|
46
|
+
begin
|
47
|
+
config = YAML.safe_load(IO.read(path),
|
48
|
+
permitted_classes: [Symbol])
|
49
|
+
rescue Errno::ENOENT => e
|
50
|
+
message = "WARNING: #{e.message}.\nUsing default conf."
|
51
|
+
$stderr.puts message if @config[:verbose]
|
52
|
+
rescue Psych::SyntaxError => e
|
53
|
+
message = "WARNING: #{e.message}.\nUsing default conf."
|
54
|
+
$stderr.puts message if @config[:verbose]
|
55
|
+
end
|
56
|
+
configure(config)
|
57
|
+
end
|
58
|
+
|
59
|
+
# save config in @config[:conf_file]
|
60
|
+
def save_config()
|
61
|
+
File.write(@config[:conf_file], YAML.dump(config))
|
62
|
+
end
|
63
|
+
|
64
|
+
attr_reader :config
|
65
|
+
|
66
|
+
def [](sym)
|
67
|
+
@config[sym]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MyHelp
|
2
|
+
module GetConfig
|
3
|
+
def get_config #(args)
|
4
|
+
parent_help_dir = options["help_dir"] || ""
|
5
|
+
parent_help_dir = ENV["HOME"] unless File.exist?(parent_help_dir)
|
6
|
+
return Config.new(parent_help_dir)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Git < Thor
|
11
|
+
include MyHelp::GetConfig
|
12
|
+
|
13
|
+
desc "pull", "pull my helps"
|
14
|
+
|
15
|
+
def pull
|
16
|
+
puts "called my_help git pull"
|
17
|
+
config = get_config
|
18
|
+
help_dir = config[:local_help_dir]
|
19
|
+
puts "on the target git directory : %s" % help_dir
|
20
|
+
Dir.chdir(help_dir) do
|
21
|
+
system "git pull origin main"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "push", "push my helps"
|
26
|
+
|
27
|
+
def push
|
28
|
+
puts "called my_help git push"
|
29
|
+
config = get_config
|
30
|
+
help_dir = config[:local_help_dir]
|
31
|
+
puts "on the target git directory : %s" % help_dir
|
32
|
+
Dir.chdir(help_dir) do
|
33
|
+
system "git add -A"
|
34
|
+
system "git commit -m 'auto commit from my_help'"
|
35
|
+
system "git pull origin main"
|
36
|
+
system "git push origin main"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/my_help/init.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module MyHelp
|
2
|
+
class Init
|
3
|
+
def initialize(config)
|
4
|
+
@config = config
|
5
|
+
end
|
6
|
+
|
7
|
+
def help_dir_exist?
|
8
|
+
File.exist?(@config[:local_help_dir])
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_conf_exist
|
12
|
+
File.exist?(@config[:conf_file])
|
13
|
+
end
|
14
|
+
|
15
|
+
def mk_help_dir
|
16
|
+
FileUtils.mkdir(@config[:local_help_dir])
|
17
|
+
end
|
18
|
+
|
19
|
+
def cp_templates
|
20
|
+
target_dir = @config[:local_help_dir]
|
21
|
+
src_dir = @config[:template_dir]
|
22
|
+
ext = @config[:ext]
|
23
|
+
Dir.glob(File.join(src_dir, "*#{ext}")).each do |file|
|
24
|
+
FileUtils.cp(file, target_dir, verbose: false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/my_help/list.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative "./org2yml"
|
2
|
+
#require "colorize"
|
3
|
+
require "colorized_string"
|
4
|
+
|
5
|
+
module MyHelp
|
6
|
+
# Your code goes here...
|
7
|
+
class List
|
8
|
+
def initialize(path = "", ext = ".org", layer = 1)
|
9
|
+
@path = path
|
10
|
+
@ext = ext
|
11
|
+
p @layer = layer
|
12
|
+
end
|
13
|
+
|
14
|
+
def list(help_options = "", level = 0)
|
15
|
+
name, item = help_options.split(" ")
|
16
|
+
if item == nil && name == nil
|
17
|
+
list_helps()
|
18
|
+
else
|
19
|
+
path = File.exists?(name + @ext) ? name + @ext :
|
20
|
+
File.join(@path, name + @ext)
|
21
|
+
list_help_with(path, name, item)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_help(file)
|
26
|
+
info = {}
|
27
|
+
info[:items] = Org2Hash.new(File.read(file)).contents
|
28
|
+
info[:name] = File.basename(file).split(".")[0]
|
29
|
+
return info
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_helps()
|
33
|
+
files = File.join(@path, "*#{@ext}")
|
34
|
+
Dir.glob(files).inject("") do |out, file|
|
35
|
+
# p [out, file]
|
36
|
+
help_info = read_help(file)
|
37
|
+
out << "%10s: %s\n" % [help_info[:name],
|
38
|
+
help_info[:items]["head"].split("\n")[0]]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# defaultで@path/name.@extのヘルプを読み込んで,itemを表示
|
43
|
+
#
|
44
|
+
def list_help_with(path, name, item)
|
45
|
+
@help_info = read_help(path)
|
46
|
+
output = ColorizedString["my_help called with name : #{name}, item : #{item}\n"].colorize(:cyan)
|
47
|
+
|
48
|
+
if item == nil
|
49
|
+
@help_info[:items].each_pair do |item, val|
|
50
|
+
item, desc = item.split(":")
|
51
|
+
desc ||= ""
|
52
|
+
output << "- %20s : %s\n" % [item, desc]
|
53
|
+
end
|
54
|
+
else
|
55
|
+
output << find_near(item)
|
56
|
+
end
|
57
|
+
return output
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_near(input_item)
|
61
|
+
candidates = []
|
62
|
+
@help_info[:items].each_pair do |item, val|
|
63
|
+
candidates << item if item.include?(input_item)
|
64
|
+
end
|
65
|
+
if candidates.size == 0
|
66
|
+
"Can't find similar item name with : #{input_item}"
|
67
|
+
else
|
68
|
+
contents = candidates.collect do |near_item|
|
69
|
+
ColorizedString["item : #{near_item} \n"].colorize(:cyan) +
|
70
|
+
@help_info[:items][near_item]
|
71
|
+
end
|
72
|
+
contents.join("\n")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MyHelp
|
2
|
+
class Md2Hash
|
3
|
+
attr_accessor :md_text, :contents, :results, :opts
|
4
|
+
|
5
|
+
def initialize(md_text = "", **opts)
|
6
|
+
@opts = opts
|
7
|
+
@md_text = md_text.split("\n")
|
8
|
+
@contents = fsm
|
9
|
+
#fsm()
|
10
|
+
end
|
11
|
+
|
12
|
+
TRANS = {
|
13
|
+
#current
|
14
|
+
# new action
|
15
|
+
#-----------------------------------
|
16
|
+
init: {
|
17
|
+
#"*" => [:init, :ignore],
|
18
|
+
:default => [:init, :ignore],
|
19
|
+
"#" => [:reading, :item],
|
20
|
+
},
|
21
|
+
reading: {
|
22
|
+
"#" => [:reading, :item],
|
23
|
+
:default => [:reading, :data],
|
24
|
+
},
|
25
|
+
}
|
26
|
+
|
27
|
+
def fsm
|
28
|
+
contents = {}
|
29
|
+
state = :init
|
30
|
+
@results = []
|
31
|
+
item = ""
|
32
|
+
@md_text.each do |line|
|
33
|
+
state, action = TRANS[state][line[0]] || TRANS[state][:default]
|
34
|
+
|
35
|
+
if line[0..1] == "#+" # line[1] != " "
|
36
|
+
state = :init
|
37
|
+
action = :ignore
|
38
|
+
end
|
39
|
+
|
40
|
+
results << [line, state, action]
|
41
|
+
|
42
|
+
case action
|
43
|
+
when :ignore
|
44
|
+
when :item
|
45
|
+
item = line.match(/^# (.+)/)[1]
|
46
|
+
contents[item] = []
|
47
|
+
when :data
|
48
|
+
contents[item] << line
|
49
|
+
end
|
50
|
+
end
|
51
|
+
return contents
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module MyHelp
|
2
|
+
class Modify
|
3
|
+
def initialize(conf)
|
4
|
+
@conf = conf
|
5
|
+
end
|
6
|
+
|
7
|
+
def new(help_file)
|
8
|
+
target = help_file
|
9
|
+
source = File.join(@conf[:template_dir], "example.org")
|
10
|
+
FileUtils.cp(source, target, verbose: @conf[:verbose])
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete(help_file)
|
14
|
+
if File.exist?(help_file)
|
15
|
+
FileUtils.rm(help_file, verbose: @conf[:verbose])
|
16
|
+
else
|
17
|
+
puts "file #{help_file} does not exist."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit(help_name)
|
22
|
+
p help_file = File.join(@conf[:local_help_dir],
|
23
|
+
help_name + @conf[:ext])
|
24
|
+
if File.exist?(help_file)
|
25
|
+
p comm = "#{@conf[:editor]} #{help_file}"
|
26
|
+
system(comm)
|
27
|
+
else
|
28
|
+
puts "file #{help_file} does not exist,"
|
29
|
+
puts "make #{help_name} first by 'new' command."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module MyHelp
|
2
|
+
# get org and trans it to hash by FSM
|
3
|
+
class Org2Hash
|
4
|
+
attr_accessor :contents, :text
|
5
|
+
# current_state => [ new_state, action ]
|
6
|
+
TRANSITIONS = {
|
7
|
+
:header_read => {
|
8
|
+
"* " => [:contents_read, :start_new_item],
|
9
|
+
:default => [:header_read, :ignore],
|
10
|
+
},
|
11
|
+
:contents_read => {
|
12
|
+
"* " => [:contents_read, :start_new_item],
|
13
|
+
:default => [:contents_read, :add_contents],
|
14
|
+
},
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(org_text)
|
18
|
+
@text = org_text
|
19
|
+
@contents = Hash.new
|
20
|
+
simple_fsm()
|
21
|
+
end
|
22
|
+
|
23
|
+
def simple_fsm()
|
24
|
+
state = :header_read
|
25
|
+
item = ""
|
26
|
+
@text.split("\n").each do |line|
|
27
|
+
next if line.size < 1
|
28
|
+
state, action = TRANSITIONS[state][line[0..1]] ||
|
29
|
+
TRANSITIONS[state][:default]
|
30
|
+
case action
|
31
|
+
when :ignore
|
32
|
+
when :start_new_item
|
33
|
+
item = read_item(line)
|
34
|
+
@contents[item] = ""
|
35
|
+
when :add_contents
|
36
|
+
@contents[item] += line + "\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def read_item(line)
|
42
|
+
line.match(/\* (.+)/)[1]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/my_help/org2yml.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "yaml"
|
3
|
+
require "pp"
|
4
4
|
|
5
|
-
class
|
5
|
+
class Org2Yaml
|
6
6
|
attr_accessor :help_cont
|
7
7
|
|
8
8
|
def initialize(file)
|
9
9
|
@help_cont = {} #{ head: [File.basename(file, '.org')] }
|
10
10
|
@head_sym = nil
|
11
|
-
@conts =
|
11
|
+
@conts = ""
|
12
12
|
@short_stored = []
|
13
13
|
org_to_yaml(File.readlines(file))
|
14
14
|
end
|
15
15
|
|
16
16
|
def make_options(line)
|
17
|
-
head, desc = line.split(
|
17
|
+
head, desc = line.split(":")
|
18
18
|
desc ||= head.to_s
|
19
19
|
short = "-#{head[0]}"
|
20
|
-
if @short_stored.include?(short) or head==
|
21
|
-
short =
|
20
|
+
if @short_stored.include?(short) or head == "license" or head == "head"
|
21
|
+
short = ""
|
22
22
|
else
|
23
23
|
@short_stored << short
|
24
24
|
end
|
@@ -27,28 +27,28 @@ class OrgToYaml
|
|
27
27
|
|
28
28
|
def next_cont(head)
|
29
29
|
@help_cont[@head_sym][:cont] = @conts if @head_sym
|
30
|
-
return if head ==
|
31
|
-
@conts =
|
30
|
+
return if head == "EOF"
|
31
|
+
@conts = ""
|
32
32
|
@head_sym = head.to_sym
|
33
33
|
@help_cont[@head_sym] = {
|
34
|
-
opts: make_options(head), title: head, cont:
|
34
|
+
opts: make_options(head), title: head, cont: "",
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
38
|
def org_to_yaml(lines)
|
39
39
|
lines.each do |line|
|
40
|
-
m = line.force_encoding(Encoding::UTF_8).match(
|
40
|
+
m = line.force_encoding(Encoding::UTF_8).match(/^(\*+) (.+)/u)
|
41
41
|
if m
|
42
|
-
next_cont m[
|
42
|
+
next_cont m[2]
|
43
43
|
else
|
44
44
|
@conts << line
|
45
45
|
end
|
46
46
|
end
|
47
|
-
next_cont
|
47
|
+
next_cont "EOF"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
if $PROGRAM_NAME == __FILE__
|
51
|
+
if $PROGRAM_NAME == __FILE__
|
52
52
|
helps = OrgToYaml.new(ARGV[0])
|
53
53
|
pp helps.help_cont
|
54
54
|
end
|
data/lib/my_help/version.rb
CHANGED