yac 0.1.5 → 0.1.6
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/lib/format.rb +56 -0
- data/lib/yac.rb +2 -2
- data/yac.gemspec +2 -2
- metadata +2 -1
data/lib/format.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Format
|
2
|
+
Pdf_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Open PDF Document"
|
3
|
+
Image_Error = "Please Modify ~/.yacrc To Provide A Valid Command To Open Image Document"
|
4
|
+
|
5
|
+
def format_file(file)
|
6
|
+
@level = 0
|
7
|
+
case `file #{file}`
|
8
|
+
when / PDF /
|
9
|
+
puts Pdf_Error unless system("#{Yac::CONFIG["pdf_command"]||'evince'} #{file}")
|
10
|
+
when /( image )|(\.svg)/
|
11
|
+
puts Image_Error unless system("#{Yac::CONFIG["pic_command"]||'eog'} #{file}")
|
12
|
+
else
|
13
|
+
File.new(file).each do |x|
|
14
|
+
format_section(x)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def format_section(section,search = false)
|
20
|
+
case section
|
21
|
+
when /^(=+)\s+(.*)/
|
22
|
+
@level = search ? 1 : $1.size
|
23
|
+
colorful("\s"*2*(@level-1) + $2,"head#{@level}")
|
24
|
+
when /^(\s*)#/
|
25
|
+
else
|
26
|
+
colorful(section.sub(/^\#/,"#").sub(/^\s*/, "\s" * @level * 2 ))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def editor
|
31
|
+
Yac::CONFIG["editor"] || ENV['EDITOR'] || "vim"
|
32
|
+
end
|
33
|
+
|
34
|
+
def title_of_file(f)
|
35
|
+
f[0..((f.rindex('.')||0) - 1)]
|
36
|
+
end
|
37
|
+
|
38
|
+
def colorful(stuff,level="text",line_break = true)
|
39
|
+
stuff = empha(stuff,level)
|
40
|
+
print "\033[%sm%s\033[0m" % [Yac::CONFIG[level],stuff.rstrip]
|
41
|
+
print "\n" if line_break
|
42
|
+
end
|
43
|
+
|
44
|
+
def empha(stuff,level="text",empha_regexp=/(@@@(.*)@@@)/)
|
45
|
+
stuff.scan(empha_regexp) do |x|
|
46
|
+
return stuff.gsub(x[0],"\033[0m\033[#{Yac::CONFIG["empha"].to_s}m%s\033[0m\033[%sm" % [x[1],Yac::CONFIG[level]])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def show_possible_result
|
51
|
+
unless @all_result.to_s.empty?
|
52
|
+
colorful("ALL POSSIBLE RESULT:","possible_result_title")
|
53
|
+
colorful(@all_result.join("\s"*2),"possible_result_content")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/yac.rb
CHANGED
@@ -107,7 +107,7 @@ module Yac
|
|
107
107
|
rescue Git::GitExecuteError
|
108
108
|
FileUtils.rm_rf(@file_path)
|
109
109
|
end
|
110
|
-
end
|
110
|
+
end
|
111
111
|
|
112
112
|
def edit_single(args)
|
113
113
|
full_path(args)
|
@@ -182,5 +182,5 @@ module Yac
|
|
182
182
|
@file_path = @pri_path + args + ".ch"
|
183
183
|
@working_git = @pri_git
|
184
184
|
end
|
185
|
-
end
|
185
|
+
end
|
186
186
|
end
|
data/yac.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
GEM = "yac"
|
2
|
-
VER = "0.1.
|
2
|
+
VER = "0.1.6"
|
3
3
|
DATE = %q{2008-10-18}
|
4
4
|
AUTHOR = "Jinzhu Zhang"
|
5
5
|
EMAIL = "wosmvp@gmail.com"
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.autorequire = 'yac'
|
26
26
|
s.executables = ["yac"]
|
27
27
|
|
28
|
-
s.files = %w[README.rdoc README.cn yac.gemspec resources/yacrc bin/yac lib/yac.rb]
|
28
|
+
s.files = %w[README.rdoc README.cn yac.gemspec resources/yacrc bin/yac lib/yac.rb lib/format.rb]
|
29
29
|
|
30
30
|
#s.has_rdoc = true
|
31
31
|
s.rdoc_options = ["--quiet", "--title", "YAC => Yet Another Cheat", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jinzhu Zhang
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- resources/yacrc
|
38
38
|
- bin/yac
|
39
39
|
- lib/yac.rb
|
40
|
+
- lib/format.rb
|
40
41
|
has_rdoc: false
|
41
42
|
homepage: http://www.zhangjinzhu.com
|
42
43
|
post_install_message:
|