hse 0.0.1 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hse/cli.rb +5 -0
- data/lib/hse/parse.rb +40 -19
- data/lib/hse/remote.rb +21 -0
- data/lib/hse/version.rb +1 -1
- metadata +2 -2
data/lib/hse/cli.rb
CHANGED
@@ -91,6 +91,11 @@ module Hse
|
|
91
91
|
remote(env).get doc
|
92
92
|
end
|
93
93
|
|
94
|
+
desc 'user [EMAIL] push=false', 'get/push user by email'
|
95
|
+
def user(email = false, push = false, env = 'default')
|
96
|
+
remote(env).user email, push
|
97
|
+
end
|
98
|
+
|
94
99
|
desc 'build [FILE]', 'parse FILE'
|
95
100
|
def build(fname = 'default')
|
96
101
|
doc = parse.build fname
|
data/lib/hse/parse.rb
CHANGED
@@ -9,37 +9,58 @@ module Hse
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def build fname
|
12
|
-
|
12
|
+
state = true
|
13
|
+
document = {body:[], more:[]}
|
14
|
+
type = fname.split("/").first.sub(/s$/,"")
|
15
|
+
document[:type] = type
|
16
|
+
if type == "post"
|
17
|
+
time = Time.new
|
18
|
+
document[:timestamp] = time.to_i #.strftime("%d/%m/%Y %H/%M/%S") # JS: "dd/MM/yyyy HH/mm/ss"
|
19
|
+
date = time.strftime("%d-%m-%Y")
|
20
|
+
document[:date] = date
|
21
|
+
end
|
13
22
|
path = File.expand_path(File.join(app_dir, fname))
|
14
|
-
|
15
|
-
uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, "#{fname}"
|
23
|
+
uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, "#{fname}-#{date}"
|
16
24
|
document[:_id] = uuid.to_s
|
17
|
-
lines = File.readlines path
|
25
|
+
lines = File.readlines path rescue return("no path #{path}")
|
26
|
+
|
18
27
|
lines.each do |line|
|
19
28
|
line.sub!("\n","").strip!
|
20
29
|
next if line.empty?
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
if line.start_with? "."
|
31
|
+
parts = line.split(":")
|
32
|
+
key= parts.first
|
33
|
+
mark = key.sub(/^\./,"").strip
|
34
|
+
fulltitle = line.sub("#{key}:", "").strip
|
24
35
|
end
|
25
|
-
parts = line.split(":")
|
26
|
-
key= parts.first
|
27
|
-
mark = key.sub("#","").strip
|
28
|
-
tail = line.sub("#{key}:", "").strip
|
29
36
|
case mark
|
30
|
-
when "
|
31
|
-
|
32
|
-
|
37
|
+
when "ru"
|
38
|
+
# titles = fulltitle.split(":")
|
39
|
+
# title = titles.first
|
40
|
+
# document[:long] = titles.last if titles.size > 1
|
41
|
+
document[:ru] = fulltitle
|
33
42
|
when "en"
|
34
|
-
|
35
|
-
|
43
|
+
titles = fulltitle.split(":")
|
44
|
+
title = titles.first
|
45
|
+
document[:en] = fulltitle
|
46
|
+
rawurl = title.gsub(" ", "-")
|
47
|
+
url = (type == "post") ? "#{date}-#{rawurl}" : rawurl
|
48
|
+
document[:url] = url
|
36
49
|
when "de"
|
37
|
-
document[:de] =
|
50
|
+
document[:de] = fulltitle
|
38
51
|
when "author"
|
39
|
-
document[:author] =
|
52
|
+
document[:author] = fulltitle
|
40
53
|
when "tags"
|
41
|
-
|
54
|
+
next unless fulltitle
|
55
|
+
tags = fulltitle.strip.split(/[[:punct:]]| /).reject!{|c|c.empty?}
|
56
|
+
document[:tags] = tags if tags
|
57
|
+
when "more"
|
58
|
+
state = false
|
42
59
|
else
|
60
|
+
state ? document[:body].push(line) : document[:more].push(line)
|
61
|
+
end
|
62
|
+
unless line.start_with? "#"
|
63
|
+
next
|
43
64
|
end
|
44
65
|
end
|
45
66
|
document
|
data/lib/hse/remote.rb
CHANGED
@@ -48,6 +48,27 @@ module Hse
|
|
48
48
|
response.code == 200 ? response.body : nil
|
49
49
|
end
|
50
50
|
|
51
|
+
def user email, push
|
52
|
+
server = "#{db_url}".split("/")[0..-2].join("/")
|
53
|
+
path = "#{server}/_users/org.couchdb.user:#{email}"
|
54
|
+
response = Typhoeus::Request.get(path)
|
55
|
+
#puts "GET Response: #{response.code} #{response.body[0..200]}"
|
56
|
+
response.code == 200 ? response.body : nil
|
57
|
+
user = JSON.parse(response.body)
|
58
|
+
puts user.inspect
|
59
|
+
return unless push
|
60
|
+
# curl -vX PUT $HOST/_users/org.couchdb.user:bob -d '{"name":"bob", "password":"bobspassword", "roles":[], "type":"user"}' -H "Content-Type: application/json"
|
61
|
+
picture = email.split("@").first
|
62
|
+
id = "org.couchdb.user:#{email}"
|
63
|
+
newuser = {type:"user", roles:[], _id: id, name: email, password:email, email: email, picture: picture, iterations:1000}
|
64
|
+
newuser["_rev"] = user["_rev"] if user
|
65
|
+
json = newuser.to_json
|
66
|
+
path = "#{server}/_users/#{id}"
|
67
|
+
#headers = {"Content-Type" => "application/json"}
|
68
|
+
response = Typhoeus::Request.put(path, body:json)
|
69
|
+
puts "PUT Response: #{response.code} #{response.body[0..200]}"
|
70
|
+
end
|
71
|
+
|
51
72
|
def get_doc_revision doc
|
52
73
|
puts "getting current revision"
|
53
74
|
current = get doc
|
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.
|
4
|
+
version: 0.1.14
|
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-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|