hse 0.1.19 → 0.1.21
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/hse/cli.rb +9 -4
- data/lib/hse/parse.rb +59 -1
- data/lib/hse/remote.rb +22 -12
- data/lib/hse/version.rb +1 -1
- metadata +2 -2
data/lib/hse/cli.rb
CHANGED
@@ -105,7 +105,7 @@ module Hse
|
|
105
105
|
desc 'check [FILE]', 'check the correctness of module in FILE'
|
106
106
|
def check(fname = 'default')
|
107
107
|
doc = parse.build fname
|
108
|
-
if doc[:
|
108
|
+
if doc[:ru].nil?
|
109
109
|
say "error: title should be filled", :red
|
110
110
|
elsif doc[:en].nil?
|
111
111
|
say "error: English title should be filled", :red
|
@@ -133,13 +133,13 @@ module Hse
|
|
133
133
|
desc 'push [FILE]', 'parse FILE, build json DOC and push DOC'
|
134
134
|
def push(fname = false, env = 'default')
|
135
135
|
doc = build fname
|
136
|
-
puts "BUILD DOC_ID = #{doc[:_id]}"
|
137
136
|
revision = remote(env).get_doc_revision(doc)
|
138
137
|
doc['_rev'] = revision if revision
|
139
138
|
puts "rev ====== #{revision}"
|
140
|
-
post_body = JSON.generate doc
|
141
139
|
puts "pushing document id #{doc[:_id]}"
|
142
|
-
|
140
|
+
#post_body = JSON.generate doc
|
141
|
+
#remote(env).put(doc[:_id], post_body)
|
142
|
+
remote(env).push_docs doc
|
143
143
|
end
|
144
144
|
|
145
145
|
desc 'generate [APPDIR]', 'generates .couchapprc'
|
@@ -153,6 +153,11 @@ module Hse
|
|
153
153
|
template('couchapprc.erb', '.couchapprc')
|
154
154
|
end
|
155
155
|
|
156
|
+
desc 'version', 'print version'
|
157
|
+
def version
|
158
|
+
say Hse::VERSION
|
159
|
+
end
|
160
|
+
|
156
161
|
|
157
162
|
private
|
158
163
|
|
data/lib/hse/parse.rb
CHANGED
@@ -8,8 +8,61 @@ module Hse
|
|
8
8
|
#load_couchapprc
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def readable path
|
12
|
+
fn = File.expand_path(File.join(app_dir, path))
|
13
|
+
puts "app_dir: #{app_dir}"
|
14
|
+
puts "readable: #{fn}"
|
15
|
+
File.readable?(fn) ? fn : false
|
16
|
+
end
|
17
|
+
|
18
|
+
def build path
|
19
|
+
readable_file = readable path
|
20
|
+
return false unless readable_file
|
21
|
+
doc = {type:"blog", body:""}
|
22
|
+
head = true
|
23
|
+
type = path.split("/").first.sub(/s$/,"")
|
24
|
+
return "path should start with posts or modules or events" unless %(post module event).include?(type)
|
25
|
+
doc[:type] = type
|
26
|
+
if type == "post"
|
27
|
+
time = Time.new
|
28
|
+
doc[:timestamp] = time.to_i #.strftime("%d/%m/%Y %H/%M/%S") # JS: "dd/MM/yyyy HH/mm/ss"
|
29
|
+
date = time.strftime("%d-%m-%Y")
|
30
|
+
doc[:date] = date
|
31
|
+
end
|
32
|
+
uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, path
|
33
|
+
doc[:_id] = uuid.to_s
|
34
|
+
lines = File.readlines readable_file
|
35
|
+
lines.each do |line|
|
36
|
+
line.strip!
|
37
|
+
next if line.empty?
|
38
|
+
if head && line.start_with?("---")
|
39
|
+
head = false
|
40
|
+
next
|
41
|
+
end
|
42
|
+
if head
|
43
|
+
parts = line.split(":")
|
44
|
+
key = parts[0].to_sym
|
45
|
+
val = parts[1..-1].join(":")
|
46
|
+
doc[key] = val.strip
|
47
|
+
next
|
48
|
+
end
|
49
|
+
line.gsub!("] (","](")
|
50
|
+
line += "\n\n"
|
51
|
+
doc[:body] += line
|
52
|
+
end
|
53
|
+
return "should be :ru, :en titles" unless doc[:en]
|
54
|
+
rawurl = doc[:en].split(":").first.gsub(" ", "-")
|
55
|
+
url = (type == "post") ? "#{date}-#{rawurl}" : rawurl
|
56
|
+
doc[:url] = url
|
57
|
+
doc
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_ fname
|
12
61
|
state = true
|
62
|
+
head = true
|
63
|
+
body = false
|
64
|
+
readable_file = readable path
|
65
|
+
return false unless readable_file
|
13
66
|
document = {body:[], more:[]}
|
14
67
|
type = fname.split("/").first.sub(/s$/,"")
|
15
68
|
document[:type] = type
|
@@ -27,6 +80,11 @@ module Hse
|
|
27
80
|
lines.each do |line|
|
28
81
|
line.sub!("\n","").strip!
|
29
82
|
next if line.empty?
|
83
|
+
if head && line.start_with?("---")
|
84
|
+
head = false
|
85
|
+
body = true
|
86
|
+
next
|
87
|
+
end
|
30
88
|
if line.start_with? "."
|
31
89
|
parts = line.split(":")
|
32
90
|
key= parts.first
|
data/lib/hse/remote.rb
CHANGED
@@ -57,25 +57,35 @@ module Hse
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def get_doc_revision doc
|
60
|
-
puts "getting current revision"
|
61
|
-
current = get_id doc
|
60
|
+
puts "getting current revision #{doc[:_id]}"
|
61
|
+
current = get_id doc[:_id] rescue nil
|
62
62
|
if current
|
63
|
-
|
64
|
-
puts "current revision: #{current_json['_rev']}"
|
63
|
+
puts "current revision: #{current['_rev']}"
|
65
64
|
end
|
66
|
-
current ?
|
65
|
+
current ? current['_rev'] : nil
|
67
66
|
end
|
68
67
|
|
69
|
-
def put id, body = ""
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
# def put id, body = ""
|
69
|
+
# path = "#{db_url}/#{id}"
|
70
|
+
# puts "remote: PUT path #{path}"
|
71
|
+
# puts "remote: PUT body: #{body[0..80]} ..."
|
72
|
+
# #response = Typhoeus::Request.put(path, :body => body)
|
73
|
+
# puts "PUT Response: #{response.code} #{response.body[0..200]}"
|
74
|
+
# response
|
75
|
+
# end
|
76
|
+
|
77
|
+
def push_docs docs
|
78
|
+
docs = docs.kind_of?(Array) ? docs : [docs]
|
79
|
+
docs.each_slice(1000) do |chunk|
|
80
|
+
json =RestClient.post "#{db_url}/_bulk_docs", {"docs" => chunk}.to_json, :content_type => :json, :accept => :json
|
81
|
+
JSON.parse(json)
|
82
|
+
puts "pushed #{chunk.size}"
|
83
|
+
end
|
84
|
+
true
|
76
85
|
end
|
77
86
|
|
78
87
|
|
79
88
|
|
89
|
+
|
80
90
|
end
|
81
91
|
end
|
data/lib/hse/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|