diglossa 0.2.24 → 0.2.27

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,19 +20,34 @@ The examples and descriptions below does not cover all the options available via
20
20
  Commands:
21
21
 
22
22
  dg help [COMMAND] # Describe available commands or one specific command
23
- dg author [NIC, push] # get author by NIC
23
+ dg generate [APPDIR] # generate .couchapprc
24
24
 
25
- book contents:
25
+ get:
26
+ dg get [OBJ] [PARAM], ex:
27
+ dg get id _ID, i.e: get id lib-tree or get id 05b33841744f209d3342bbfcf76cb574
28
+ dg get book by root file-path or url, i.e:
29
+ dg get book Greek/Plato/Dialogues (url) or get NT/Greek/Plato/Dialogues (file-path)
30
+ dg get texts by root path or url
31
+ dg get coms by root path or url
26
32
 
27
- dg build [PATH] # parse BOOK by root PATH(.json/.yml) and build hash, ex: dg build "NT/Palama/Triads"
28
- dg warns [PATH] # print errors and warns about BOOK by PATH
29
- dg get [PATH/URL] # get BOOK tree by root path or url, i.e. "Greek/Plato/Dialogues" or "NT/Greek/Plat...
30
- dg push [PATH] # builds, checks and pushes BOOK to couchdb by root PATH
33
+ build:
34
+ dg build [OBJ] [PATH], ex:
35
+ dg build json obj, i.e.: build json authors/psell.json
36
+ dg build book path, ex: dg build book NT/Palama/Triads
37
+ dg build urls path (array of the urls in a book)
38
+ no build for text and comments, use push and then get
31
39
 
32
- texts (paragraphs):
40
+ warns:
41
+ dg warns book [PATH], ex:
42
+ dg warns book NT/Palama/Triads
43
+
44
+ push:
45
+ dg push [OBJ] [PATH] env, ex:
46
+ dg push json/book/texts,
47
+ dg push book NT/Palama/Triads
48
+ dg push book NT/Palama/Triads production
49
+ dg push texts NT/Palama/Triads (pushes all texts and comms at once)
33
50
 
34
- dg gettexts [URL, delete] # get or delete! text docs by exact URL: dg gettexts "Psell/Chronographia/Part-1" N...
35
- dg pushtexts [PATH] # parse texts for root PATH, ex: dg docs "NT/Palama/Triads"
36
51
 
37
52
 
38
53
  ## .couchapprc
@@ -58,7 +73,7 @@ Do not forget to generate .couchapprc file with <tt>dg gen your_appname</tt> and
58
73
 
59
74
  ## ToDo
60
75
 
61
- dg library # library contents get/push
76
+ dg delete [OBJ] [PATH]
62
77
 
63
78
  ## Community
64
79
 
data/bin/dg-author ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'diglossa'
4
+
5
+ Diglossa::Author.start
data/diglossa.gemspec CHANGED
@@ -13,12 +13,11 @@ Gem::Specification.new do |gem|
13
13
  gem.homepage = ""
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ #gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.executables = ["dg"]
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- #gem.add_development_dependency "redcarpet", "~> 1.17"
22
21
  gem.add_development_dependency "yard", "~> 0.7.5"
23
22
  gem.add_development_dependency "rspec-core", "~> 2.0"
24
23
  gem.add_development_dependency "rspec-expectations", "~> 2.0"
@@ -28,6 +27,7 @@ Gem::Specification.new do |gem|
28
27
  gem.add_runtime_dependency(%q<mime-types>, ["~> 1.16"])
29
28
  #gem.add_runtime_dependency(%q<typhoeus>, ["~> 0.6.3"])
30
29
  gem.add_runtime_dependency(%q<rest-client>)
30
+ gem.add_runtime_dependency(%q<addressable>)
31
31
  gem.add_runtime_dependency(%q<thor>, ["~> 0.15"])
32
32
  #gem.add_runtime_dependency(%q<thor>, ["~> 0.15"])
33
33
  gem.add_runtime_dependency(%q<uuidtools>, ["~> 2.1"])
@@ -0,0 +1,106 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'thor'
3
+ require 'thor/actions'
4
+ require 'uuidtools'
5
+ require 'rest_client'
6
+ require 'yaml'
7
+ require 'pp'
8
+
9
+ module Diglossa
10
+ class Author < ::Thor
11
+ include Thor::Actions
12
+
13
+ attr_accessor :appdir, :config_file, :debug
14
+ attr_reader :config
15
+
16
+ class_option "appdir",
17
+ :type => :string,
18
+ :banner => "set the application directory to work with. assumes the current directory"
19
+
20
+ method_option "appname",
21
+ :type => :string,
22
+ :banner => "set the name of the application for templating. defaults to the basename of the appdir"
23
+
24
+ default_task :help
25
+
26
+ desc 'get [PATH/URL]', 'get BOOK tree by root path or url, i.e. "Greek/Plato/Dialogues" or "NT/Greek/Plato/Dialogues" '
27
+ def get(path, env = 'default')
28
+ size = path.split("/").size
29
+ url = size < 3 ? path : path.to_url
30
+ resp = remote(env).get_book url
31
+ resp ? pp(resp) : say("no book by url #{url}", :red)
32
+ end
33
+
34
+ desc 'build [PATH]', 'parse author.json by PATH(.json/.yml) and build hash, ex: dg-author build "authors/psell"'
35
+ def build(path = 'authors/author')
36
+ fn = File.expand_path(File.join(appdir, path))
37
+ readable = File.readable?("#{fn}.json") ? "#{fn}.json" : File.readable?("#{fn}.yml") ? "#{fn}.yml" : false
38
+ if readable
39
+ hash = JSON.parse(File.read(readable))
40
+ pp hash
41
+ else
42
+ say "Could not find author.json or author.yml at '#{fn}'. "
43
+ end
44
+ #return nil unless fullname
45
+
46
+ # if File.readable?(config_path)
47
+ # @config = JSON.parse(File.read(config_path))
48
+ # else
49
+ # raise "Could not find config at '#{config_path}'. Run `soca init`"
50
+ # end
51
+
52
+ # #hash = parse.author_build path
53
+ # pp hash
54
+ #book = parse.seed_build path
55
+ #book ? pp(book) : say("can not build book by path #{path}", :red)
56
+ end
57
+
58
+ desc 'push [PATH]', 'builds, checks and pushes BOOK to couchdb by root PATH'
59
+ def push(path, env = 'default')
60
+ books = parse.build path, "book"
61
+ resp = remote(env).push_book books
62
+ resp ? pp(resp) : say("WARN: no book to push by #{path}", :red)
63
+ end
64
+
65
+ # choose seeds directory
66
+ desc 'author_ [NIC, push]', 'get author by NIC'
67
+ def author(nic, push=false, env = 'default')
68
+ response = remote(env).author nic
69
+ response.empty? ? say("WARN: no author #{nic}", :red) : pp(response)
70
+ return unless push
71
+ doc = parse.parse_author(nic)
72
+ dbdoc = response.find{|d|d["nic"] == nic}
73
+ if dbdoc
74
+ doc["_id"] = dbdoc["_id"]
75
+ doc["_rev"] = dbdoc["_rev"]
76
+ end
77
+ response = remote(env).push_docs doc
78
+ pp response
79
+ end
80
+
81
+ def initialize(*)
82
+ super
83
+ self.appdir = options[:appdir] || File.expand_path(Dir.pwd)
84
+ # self.config_file = options[:config]
85
+ self.source_paths << File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
86
+ end
87
+
88
+ private
89
+
90
+ def remote(env)
91
+ Diglossa::Remote.new appdir, env
92
+ rescue => e
93
+ say e.message, :red
94
+ exit
95
+ end
96
+
97
+ def parse
98
+ Diglossa::Parse.new appdir
99
+ rescue => e
100
+ say e.message, :red
101
+ exit
102
+ end
103
+
104
+
105
+ end
106
+ end
data/lib/diglossa/cli.rb CHANGED
@@ -6,7 +6,8 @@ require 'uuidtools'
6
6
  require 'rest_client'
7
7
  require 'yaml'
8
8
  require 'pp'
9
- #require 'redcarpet'
9
+ #require 'addressable'
10
+ require "addressable/uri"
10
11
 
11
12
  module Diglossa
12
13
  class CLI < ::Thor
@@ -26,64 +27,109 @@ module Diglossa
26
27
 
27
28
  default_task :help
28
29
 
29
-
30
- desc 'get [PATH/URL]', 'get BOOK tree by root path or url, i.e. "Greek/Plato/Dialogues" or "NT/Greek/Plato/Dialogues" '
31
- def get(path, env = 'default')
30
+ desc 'get [OBJ] [PARAM]', 'get author nic
31
+ get id _ID, i.e:
32
+ get id lib-tree or get id 05b33841744f209d3342bbfcf76cb574
33
+ get book by root file-path or url, i.e:
34
+ get book Greek/Plato/Dialogues (url) or get NT/Greek/Plato/Dialogues (file-path)
35
+ get texts by root path or url
36
+ get coms by root path or url
37
+ '
38
+ def get(obj, path, env = 'default')
32
39
  size = path.split("/").size
33
40
  url = size < 3 ? path : path.to_url
34
- resp = remote(env).get_book url
35
- resp ? pp(resp) : say("no book by url #{url}", :red)
36
- end
37
-
38
- desc 'build [PATH]', 'parse BOOK by root PATH(.json/.yml) and build hash, ex: dg build "NT/Palama/Triads"'
39
- def build(path = 'default', push = "book")
40
- book = parse.build path, "book"
41
- book ? pp(book) : say("can not build book by path #{path}", :red)
42
- end
43
-
44
- desc 'push [PATH]', 'builds, checks and pushes BOOK to couchdb by root PATH'
45
- def push(path, env = 'default')
46
- books = parse.build path, "book"
47
- resp = remote(env).push_book books
48
- resp ? pp(resp) : say("WARN: no book to push by #{path}", :red)
49
- end
50
-
51
- desc 'warns [PATH]', 'print errors and warns about BOOK by PATH'
52
- def warns(path, env = 'default')
53
- resp = parse.build path, "warns"
54
- resp ? pp(resp) : say("WARN: no book to push by #{path}", :red)
41
+ puts "URL: #{url}" unless path == url
42
+ case obj
43
+ when "author"
44
+ resp = remote(env).author path
45
+ when "id"
46
+ resp = remote(env).get_id path
47
+ when "texts"
48
+ urls = build "urls", path, false
49
+ urls.each do |url|
50
+ resp = remote(env).get_texts url
51
+ end
52
+ when "coms"
53
+ urls = build "urls", path, false
54
+ urls.each do |url|
55
+ puts "get coms by url: #{url}"
56
+ resp = remote(env).get_coms url
57
+ end
58
+ when ""
59
+ when ""
60
+ when "book"
61
+ resp = remote(env).get_book url
62
+ end
63
+ resp ? pp(resp) : say("no #{obj} by PARAM #{path}", :red)
55
64
  end
56
65
 
57
- desc 'pushtexts [PATH]', 'parse texts for root PATH, ex: dg docs "NT/Palama/Triads"'
58
- def pushtexts(path = 'default')
59
- fpaths = parse.build path, "docs"
60
- fpaths ? pp(fpaths) : say("can not build texts by path #{path}", :red)
66
+ desc 'warns book [PATH]', 'warns book PATH, ex:
67
+ dg warns book NT/Palama/Triads
68
+ '
69
+ def warns(obj, path)
70
+ case obj
71
+ #when "blog"
72
+ #hash = parse.build_blog path
73
+ when "book"
74
+ hash = parse.build_book path, "warns"
75
+ when ""
76
+ else
77
+ hash = false
78
+ end
79
+ #hash ? pp(hash) : say("can not build OBJ by path #{path}", :red)
80
+ hash ? pp(hash) : say("use: warns _book_ path", :red)
61
81
  end
62
82
 
63
- desc 'gettexts [URL, delete]', 'get or delete! text docs by exact URL: dg gettexts "Psell/Chronographia/Part-1" NB: defis'
64
- def gettexts(url, delete=false, env = 'default') # 125037 rows
65
- docs = remote(env).texts_get url
66
- docs.empty? ? say("WARN: no docs by url: #{url}", :red) : pp(docs)
67
- return unless delete == "delete!"
68
- docs.each{|doc|doc["_deleted"] = true}
69
- response = remote(env).push_docs docs
70
- pp response
83
+ desc 'build [OBJ] [PATH]', 'build json obj, i.e.
84
+ build json authors/psell.json
85
+ build book path, ex: dg build book NT/Palama/Triads
86
+ build urls path - array of the urls in a book
87
+ no build for text and comments, use push and then get
88
+ '
89
+ def build(obj, path, print = true)
90
+ case obj
91
+ when "blog"
92
+ hash = parse.build_blog path
93
+ when "json"
94
+ hash = parse.build_json path
95
+ when "book"
96
+ hash = parse.build_book path, "book"
97
+ when "urls"
98
+ hash = parse.build_book_urls path
99
+ when "texts"
100
+ hash = "use dg push texts PATH"
101
+ when ""
102
+ when ""
103
+ else
104
+ hash = false
105
+ end
106
+ if print
107
+ hash ? pp(hash) : say("can not build OBJ by path #{path}", :red)
108
+ else
109
+ hash
110
+ end
71
111
  end
72
112
 
73
- # choose seeds directory
74
- desc 'author [NIC, push]', 'get author by NIC'
75
- def author(nic, push=false, env = 'default')
76
- response = remote(env).author nic
77
- response.empty? ? say("WARN: no author #{nic}", :red) : pp(response)
78
- return unless push
79
- doc = parse.parse_author(nic)
80
- dbdoc = response.find{|d|d["nic"] == nic}
81
- if dbdoc
82
- doc["_id"] = dbdoc["_id"]
83
- doc["_rev"] = dbdoc["_rev"]
113
+ desc 'push [OBJ] [PATH] env', 'push json/book/texts,
114
+ dg push book NT/Palama/Triads
115
+ dg push book NT/Palama/Triads production
116
+ dg push texts NT/Palama/Triads (pushes all texts and comms at once)
117
+
118
+ '
119
+ def push(obj, path, env = 'default')
120
+ case obj
121
+ when "blog"
122
+ #resp = remote(env).push_docs docs
123
+ when "json"
124
+ resp = remote(env).push_docs docs
125
+ when "book"
126
+ docs = parse.build_book path, "book"
127
+ resp = remote(env).push_book docs
128
+ when "texts"
129
+ resp = parse.build_book path, "texts"
130
+ else
84
131
  end
85
- response = remote(env).push_docs doc
86
- pp response
132
+ resp ? pp(resp) : say("ERR: no book to push by #{path}", :red)
87
133
  end
88
134
 
89
135
  def initialize(*)
@@ -93,25 +139,7 @@ module Diglossa
93
139
  self.source_paths << File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
94
140
  end
95
141
 
96
- # desc 'consts [ENV]', 'outputs the app CONSTS for the ENV'
97
- # def consts(env = 'default')
98
- # say DIGLOSSA::lib
99
- # end
100
-
101
-
102
- # desc 'blog [FILE]', 'parse blog FILE.en or FILE.ru'
103
- # def blog(fname = 'default')
104
- # parse.blog fname
105
- # end
106
-
107
- # desc 'get [URL]', 'get URL'
108
- # def get(url, env = 'default')
109
- # remote(env).get url
110
- # end
111
-
112
- # end
113
-
114
- desc 'generate [APPDIR]', 'generates .couchapprc'
142
+ desc 'generate [APPDIR]', 'generate .couchapprc'
115
143
  def generate(to = nil)
116
144
  self.appdir = to if to
117
145
  self.destination_root = appdir
@@ -10,7 +10,7 @@ module Diglossa
10
10
 
11
11
  def initialize(app_dir) #, config_path = nil)
12
12
  self.app_dir = File.expand_path(app_dir) + '/'
13
- @warns = {file:[], size:[]}
13
+ @warns = {file:[], size:[], fn:[]}
14
14
  @counter = []
15
15
  #load_couchapprc
16
16
  end
@@ -24,7 +24,55 @@ module Diglossa
24
24
  doc
25
25
  end
26
26
 
27
- def build root, push=false
27
+ def readable path
28
+ fn = File.expand_path(File.join(app_dir, path))
29
+ #File.readable?("#{fn}.json") ? "#{fn}.json" : File.readable?("#{fn}.yml") ? "#{fn}.yml" : File.readable?(fn) ? fn : false
30
+ puts "app_dir: #{app_dir}"
31
+ puts "readable: #{fn}"
32
+ File.readable?(fn) ? fn : false
33
+ end
34
+
35
+ def build_blog path
36
+ readable_file = readable path
37
+ return false unless readable_file
38
+ doc = {type:"blog", body:[], more:[]}
39
+ time = Time.new
40
+ date = time.strftime("%d-%m-%Y")
41
+ doc[:date] = date
42
+ uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, "#{path}-#{date}"
43
+ doc[:_id] = uuid.to_s
44
+ head = true
45
+ body = false
46
+ lines = File.readlines readable_file
47
+ lines.each do |line|
48
+ line.strip!
49
+ next if line.empty?
50
+ if head && line.start_with?("---")
51
+ head = false
52
+ body = true
53
+ next
54
+ end
55
+ if head
56
+ parts = line.split(":")
57
+ key = parts[0].to_sym
58
+ val = parts[1..-1].join(":")
59
+ doc[key] = val
60
+ next
61
+ end
62
+ body ? doc[:body].push(line) : doc[:more].push(line)
63
+ body = false if body && line.start_with?("---")
64
+
65
+ end
66
+ doc
67
+ end
68
+
69
+ def build_json path
70
+ readable_file = readable path
71
+ return false unless readable_file
72
+ JSON.parse(File.read(readable_file))
73
+ end
74
+
75
+ def build_book root, push=false
28
76
  remote = Diglossa::Remote.new(app_dir)
29
77
  data_dir = remote.config["data"]
30
78
  #puts "locales #{remote.config["locales"]}"
@@ -34,11 +82,13 @@ module Diglossa
34
82
  doc = fullname ? YAML.load_file(fullname) : "no .json or .yml file at #{root}"
35
83
  @nics = doc["authors"]
36
84
  @rpp = {}
37
- @dbauthors = remote.author(doc["authors"])
85
+ @dbauthors = remote.author(doc["authors"]) rescue(return false) # return("no authors from server")
86
+ return false unless dbauthors
38
87
  @author_nic = root.split("/")[1].downcase
39
88
  #lang = root.split('/').first.downcase
40
89
  @locale = "ru"
41
90
  title = root.split("/").last # .gsub("_", " ")
91
+ title = false
42
92
  if push == "book"
43
93
  jsru = {isFolder:true, expand: true, children:[]}
44
94
  jsen = {isFolder:true, expand: true, children:[]}
@@ -47,13 +97,20 @@ module Diglossa
47
97
  end
48
98
  @locale = "en"
49
99
  traverse jsen, doc["tree"], root, title
50
- [{type:"book", url:root.to_url, jstree:jsru, rpp:rpp, locale:"ru"},
51
- {type:"book", url:root.to_url, jstree:jsen, rpp:rpp, locale:"en"}]
52
- elsif push == "docs"
100
+ # traverse jsen, doc["tree"], root, title do |path|
101
+ # parallels path # cause of rpp, alas
102
+ # end
103
+ ru = jsru[:title] ? {type:"book", url:root.to_url, jstree:jsru, rpp:rpp, locale:"ru"} : nil
104
+ en = jsen[:title] ? {type:"book", url:root.to_url, jstree:jsen, rpp:rpp, locale:"en"} : nil
105
+ # [{type:"book", url:root.to_url, jstree:jsru, rpp:rpp, locale:"ru"},
106
+ # {type:"book", url:root.to_url, jstree:jsen, rpp:rpp, locale:"en"}]
107
+ [ru, en]
108
+ elsif push == "texts"
53
109
  jsru = {url:root.to_url, isFolder:true, expand: true, children:[]}
54
110
  traverse jsru, doc["tree"], root, title do |path|
55
- parallels path, true
111
+ parallels(path, true)
56
112
  end
113
+ return "texts pushed"
57
114
  elsif push == "warns"
58
115
  jsru = {url:root.to_url, isFolder:true, expand: true, children:[]}
59
116
  traverse jsru, doc["tree"], root, title do |path|
@@ -61,6 +118,12 @@ module Diglossa
61
118
  end
62
119
  warns
63
120
  end
121
+ #return true
122
+ end
123
+
124
+ def build_book_urls root
125
+ books = build_book root, "book"
126
+ books[0][:rpp].keys
64
127
  end
65
128
 
66
129
  private
@@ -72,39 +135,63 @@ module Diglossa
72
135
  return if File.directory?(dpath)
73
136
  @counter = []
74
137
  docs = []
138
+ coms = []
75
139
  nics.each do |nic|
76
140
  author = dbauthors.find{|a|a["nic"] == nic}
77
141
  fpath = "#{dpath}.#{nic}"
78
- unless File.exist?(fpath)
142
+ unless File.readable?(fpath)
79
143
  warns[:file].push fpath
80
144
  next
81
145
  end
82
- docs += paragraphs(fpath, path.to_url, nic, author["lang"], push)
146
+ docobj, comobj = paragraphs(fpath, path.to_url, nic, author["lang"])
147
+ docs += docobj
148
+ coms += comobj if comobj
83
149
  end
84
150
  if push
85
- puts "pushing #{docs.size} - #{path}"
86
- remote.texts_push path.to_url, nics, docs
151
+ comsize = coms ? coms.size : 0
152
+ puts "pushing path #{path} docs #{docs.size} coms #{comsize}"
153
+ remote.push_texts path.to_url, docs
154
+ remote.push_coms path.to_url, coms
87
155
  end
88
156
  # some stupid heuristique for rpp
89
157
  vol = docs.inject(0){|vol,doc| vol + doc[:text].size}
90
158
  rows_per_page = vol == 0 ? 25 : (10000*(docs.size)/vol).round
91
- rpp[path.to_url] = rows_per_page #.to_s
159
+ rpp[path.to_url] = rows_per_page
92
160
 
93
161
  if (nics.size != counter.size) || (counter.uniq.size != 1)
94
162
  warns[:size].push "#{path} - #{counter.inspect}"
95
163
  end
96
164
  end
97
165
 
98
- def paragraphs fpath, url, nic, lang, push
166
+ def paragraphs fpath, url, nic, lang
99
167
  docs = []
100
168
  lines = File.readlines fpath
101
169
  counter.push lines.size
102
170
  lines.each do |line|
103
171
  line.gsub!(/\s+/, " ").strip! #.gsub!("*", " *").gsub!(" /", "/")
104
172
  next if line.empty?
105
- docs << {type:'text', url:url, nic:nic, lang:lang, text:line}
173
+ docs << {type:'text', url:url, nic:nic, lang:lang, text:line}
106
174
  end
107
175
  docs.each_with_index.map{|doc, index| doc[:pos] = index; doc}
176
+ return [docs] unless File.readable?("#{fpath}-com")
177
+ coms = []
178
+ comlines = File.readlines "#{fpath}-com"
179
+ comlines.each do |line|
180
+ line.gsub!(/\s+/, " ").strip!
181
+ x, anchor, comment = line.split(/(\*\d*) /)
182
+ next unless anchor
183
+ #puts "#{line.inspect}" unless anchor
184
+ #puts "a: #{anchor} => l: #{line}"
185
+ re_anchor = Regexp.new anchor.sub("*","\\*"), true
186
+ par = docs.detect{|doc| doc[:text].match(re_anchor)}
187
+ if par
188
+ pos = par[:pos]
189
+ coms << {type:'comment', url:url, nic:nic, lang:lang, pos:pos, anchor:anchor, text:comment}
190
+ else
191
+ warns[:fn] << "#{anchor} -> #{fpath}"
192
+ end
193
+ end
194
+ [docs, coms]
108
195
  end
109
196
 
110
197
  def parse_nics narrow = true, nics = nil
@@ -124,11 +211,14 @@ module Diglossa
124
211
  case doc
125
212
  when Hash
126
213
  hash = {}
127
- if doc["title"] == title
214
+ #if doc["title"].gsub(" ","_") == title
215
+ unless title
128
216
  hash = jstree
129
217
  @nics = doc["authors"] if doc["authors"]
130
218
  hash["nics"] = parse_nics false
131
- hash["title"] = doc[locale]
219
+ title = doc[locale]
220
+ return unless title
221
+ hash[:title] = title
132
222
  else
133
223
  path += "/#{doc["title"].gsub(" ","_")}"
134
224
  title = doc[locale]
@@ -136,7 +226,7 @@ module Diglossa
136
226
  authors = parse_nics nics
137
227
  dir = doc["children"].nil?
138
228
  hash = dir ? {url: path.to_url, title: title, nics: authors} : {url: path.to_url, title: title, isFolder: true, expand: true, children:[]}
139
- jstree[:children].push hash unless doc["title"] == title
229
+ jstree[:children].push hash #unless doc["title"] == title
140
230
  end
141
231
  traverse(hash, doc["children"], path, title, &blk)
142
232
  when Array
@@ -146,42 +236,29 @@ module Diglossa
146
236
  end
147
237
  end
148
238
 
149
- # def print_warns
150
- # unless warns_file.empty?
151
- # puts "NO FILE: " # тут непонятка - при отключении paragraphs выводятся warnings, что не нужно
152
- # pp warns_file
153
- # end
154
- # unless warns_size.empty?
155
- # puts "NON EQUAL SIZES: "
156
- # pp warns_size
157
- # end
158
- # end
159
-
160
-
161
239
 
162
-
163
- def json fname # это для блога
164
- #
165
- document = {}
166
- puts "building DOC fname: #{fname}"
167
- puts "APDIR.self #{self.app_dir}"
168
- puts "APDIR #{app_dir}"
169
- path = File.expand_path(File.join(app_dir, fname))
170
- puts "path #{path}"
171
- uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, "#{fname}"
172
- puts "_ID = #{path} - #{uuid}"
173
- lines = File.readlines path
174
- lines.reject!{|c|c.empty? || c == "\n"}
175
- document[:_id] = uuid.to_s
176
- document[:title] = lines.shift.strip
177
- document[:tags] = lines.shift.strip.split(/[[:punct:]]| /).reject!{|c|c.empty?}
178
- #markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
179
- #body = markdown.render lines.join("\n")
180
- document[:body] = "body"
181
- puts "----------"
182
- pp document
183
- document
184
- end
240
+ # def json fname # это для блога
241
+ # #
242
+ # document = {}
243
+ # puts "building DOC fname: #{fname}"
244
+ # puts "APDIR.self #{self.app_dir}"
245
+ # puts "APDIR #{app_dir}"
246
+ # path = File.expand_path(File.join(app_dir, fname))
247
+ # puts "path #{path}"
248
+ # uuid = UUIDTools::UUID.sha1_create UUIDTools::UUID_DNS_NAMESPACE, "#{fname}"
249
+ # puts "_ID = #{path} - #{uuid}"
250
+ # lines = File.readlines path
251
+ # lines.reject!{|c|c.empty? || c == "\n"}
252
+ # document[:_id] = uuid.to_s
253
+ # document[:title] = lines.shift.strip
254
+ # document[:tags] = lines.shift.strip.split(/[[:punct:]]| /).reject!{|c|c.empty?}
255
+ # #markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
256
+ # #body = markdown.render lines.join("\n")
257
+ # document[:body] = "body"
258
+ # puts "----------"
259
+ # pp document
260
+ # document
261
+ # end
185
262
 
186
263
 
187
264
  end
@@ -25,7 +25,6 @@ module Diglossa
25
25
  # end
26
26
 
27
27
  def load_couchapprc
28
- # тут есть теперь "data-dir", но она нужна в parse, а не здесь. Как загружать один раз эту хрень?
29
28
  @config ||= {}
30
29
  @config = JSON.parse(File.read(File.join(app_dir, '.couchapprc')))
31
30
  @config['couchapprc'] = JSON.parse(File.read(File.join(app_dir, '.couchapprc')))
@@ -41,10 +40,22 @@ module Diglossa
41
40
  end
42
41
  end
43
42
 
43
+ def get_id id
44
+ path = "#{db_url}/#{id}?include_docs=true"
45
+ response = RestClient.get path, :content_type => :json, :accept => :json # rescue nil
46
+ return "no _id #{id}" unless response.code == 200
47
+ result = JSON.parse(response.body)
48
+ response.code == 200 ? result : nil
49
+ end
50
+
44
51
  def author(nic = "abelard")
52
+ # FIXME: для dbauthors нужен отдельный метод?
53
+ # gem needs authors info for building book-tree
45
54
  nics = nic.kind_of?(Array) ? nic : [nic]
46
- path = "#{db_url}/_design/diglossa.coffee/_view/byAuthor?include_docs=true"
47
- response = RestClient.post path, {"keys"=> nics}.to_json, :content_type => :json, :accept => :json
55
+ #path = "#{db_url}/_design/diglossa.coffee/_view/byAuthor?include_docs=true"
56
+ path = "http://diglossa.ru:5984/diglossa/_design/diglossa.coffee/_view/byAuthor?include_docs=true"
57
+ response = RestClient.post path, {"keys"=> nics}.to_json, :content_type => :json, :accept => :json rescue nil
58
+ return "no connection to diglossa.ru" unless response
48
59
  return "no authors with nics #{nics}" unless response.code == 200
49
60
  authors = JSON.parse(response.body)["rows"].map{|r|r['doc']}
50
61
  #pp authors
@@ -53,9 +64,12 @@ module Diglossa
53
64
 
54
65
  def push_docs docs
55
66
  docs = docs.kind_of?(Array) ? docs : [docs]
56
- # http://stackoverflow.com/questions/4435538/ruby-rest-client-make-it-never-timeout
57
- json = RestClient.post "#{db_url}/_bulk_docs", {"docs" => docs}.to_json, :content_type => :json, :accept => :json
58
- JSON.parse(json)
67
+ docs.each_slice(1000) do |chunk|
68
+ json =RestClient.post "#{db_url}/_bulk_docs", {"docs" => chunk}.to_json, :content_type => :json, :accept => :json
69
+ JSON.parse(json)
70
+ puts "pushed #{chunk.size}"
71
+ end
72
+ true
59
73
  end
60
74
 
61
75
  def get_book url
@@ -77,46 +91,70 @@ module Diglossa
77
91
  book["_rev"] = dbbooks[index]["_rev"]
78
92
  end
79
93
  end
80
- #pp books
81
94
  push_docs books
82
95
  end
83
96
 
84
- def texts_get url
97
+ def get_texts url
85
98
  response = RestClient.get("#{db_url}/_design/diglossa.coffee/_view/byUrl?key=%22#{url}%22&include_docs=true")
86
99
  JSON.parse(response)['rows'].map{|r|r['doc']} || []
87
100
  end
88
101
 
89
- def texts_delete url
90
- dbdocs = texts_get url
102
+ def del_texts url
103
+ dbdocs = get_texts url
91
104
  return if dbdocs.empty?
92
105
  dbdocs.each{|doc|doc["_deleted"] = true}
93
106
  push_docs dbdocs
94
107
  end
95
108
 
96
- def texts_push url, nics, docs
97
- dbdocs = texts_get url
109
+ def push_texts url, docs
110
+ dbdocs = get_texts url
98
111
  if dbdocs.size == docs.size
99
112
  docs.each_with_index do |doc, index|
100
113
  doc["_id"] = dbdocs[index]["_id"]
101
114
  doc["_rev"] = dbdocs[index]["_rev"]
102
115
  end
103
116
  else
104
- texts_delete url
117
+ del_texts url
105
118
  end
106
119
  push_docs docs
107
120
  end
108
121
 
109
- def seeds(name = "authors", push = false)
110
- path = "#{db_url}/_design/diglossa.coffee/_view/byAuthor?include_docs=true"
111
- response = RestClient.get "#{db_url}/_design/diglossa.coffee/_view/byAuthor?key=%22#{path.to_url}%22&include_docs=true", :content_type => :json, :accept => :json
112
- #JSON.parse( RestClient.get( "#{Diglossa::DBD}/_design/diglossa.coffee/_view/byAuthor?include_docs=true"))['rows'].map{|r|r['doc']} rescue nil
113
- response = RestClient.post path, {"keys"=> nics}.to_json, :content_type => :json, :accept => :json
114
- return "no authors with nics #{nics}" unless response.code == 200
115
- authors = JSON.parse(response.body)["rows"].map{|r|r['doc']}
116
- #pp authors
117
- response.code == 200 ? authors : nil
122
+ def get_coms url
123
+ response = RestClient.get("#{db_url}/_design/diglossa.coffee/_view/comsByUrl?key=%22#{url}%22&include_docs=true")
124
+ JSON.parse(response)['rows'].map{|r|r['doc']} || []
125
+ end
126
+
127
+ def del_coms url
128
+ dbdocs = get_coms url
129
+ return if dbdocs.empty?
130
+ dbdocs.each{|doc|doc["_deleted"] = true}
131
+ push_docs dbdocs
118
132
  end
119
133
 
134
+ def push_coms url, docs
135
+ dbdocs = get_coms url
136
+ if dbdocs.size == docs.size
137
+ docs.each_with_index do |doc, index|
138
+ doc["_id"] = dbdocs[index]["_id"]
139
+ doc["_rev"] = dbdocs[index]["_rev"]
140
+ end
141
+ else
142
+ del_coms url
143
+ end
144
+ push_docs docs
145
+ end
146
+
147
+ # def seeds(name = "authors", push = false)
148
+ # path = "#{db_url}/_design/diglossa.coffee/_view/byAuthor?include_docs=true"
149
+ # response = RestClient.get "#{db_url}/_design/diglossa.coffee/_view/byAuthor?key=%22#{path.to_url}%22&include_docs=true", :content_type => :json, :accept => :json
150
+ # #JSON.parse( RestClient.get( "#{Diglossa::DBD}/_design/diglossa.coffee/_view/byAuthor?include_docs=true"))['rows'].map{|r|r['doc']} rescue nil
151
+ # response = RestClient.post path, {"keys"=> nics}.to_json, :content_type => :json, :accept => :json
152
+ # return "no authors with nics #{nics}" unless response.code == 200
153
+ # authors = JSON.parse(response.body)["rows"].map{|r|r['doc']}
154
+ # #pp authors
155
+ # response.code == 200 ? authors : nil
156
+ # end
157
+
120
158
 
121
159
  end
122
160
  end
@@ -1,3 +1,3 @@
1
1
  module Diglossa
2
- VERSION = "0.2.24"
2
+ VERSION = "0.2.27"
3
3
  end
data/lib/diglossa.rb CHANGED
@@ -9,5 +9,6 @@ end
9
9
 
10
10
  require "diglossa/classext"
11
11
  require 'diglossa/cli'
12
+ #require 'diglossa/author'
12
13
  require 'diglossa/remote'
13
14
  require 'diglossa/parse'
data/nginx-last.conf ADDED
@@ -0,0 +1,201 @@
1
+ worker_processes 10;
2
+
3
+ #user michael;
4
+
5
+ error_log /var/log/nginx/error.log;
6
+
7
+ events {
8
+ worker_connections 1024;
9
+ }
10
+
11
+ http {
12
+ proxy_temp_path /var/spool/nginx/tmp/proxy;
13
+ fastcgi_temp_path /var/spool/nginx/tmp/fastcgi;
14
+ client_body_temp_path /var/spool/nginx/tmp/client;
15
+
16
+ include /etc/nginx/mime.types;
17
+ default_type application/octet-stream;
18
+
19
+ sendfile on;
20
+
21
+ gzip on;
22
+ #types_hash_bucket_size 64;
23
+
24
+ # text/html don't need to be defined there, it always compressed
25
+ gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml;
26
+ #gzip_types text/css text/xml application/x-javascript application/atom+xml;
27
+
28
+ # gzip_comp_level 9;
29
+
30
+
31
+
32
+ server {
33
+ #listen localhost:80;
34
+ #isten 127.0.0.1:80;
35
+ #listen ru.dig.loc:80;
36
+ #server_name ru.dig.loc en.dig.loc dev.dig.loc;
37
+ listen 195.54.209.42:80;
38
+ server_name ru.diglossa.org en.diglossa.org;
39
+
40
+ #rewrite ^/js/(.*)$ /js/$1 last;
41
+ rewrite ^/js/(.*)$ /diglossa/_design/diglossa.coffee/js/$1 last;
42
+ rewrite ^/diglossa/(.*)$ /diglossa/$1 last;
43
+ rewrite ^/css/(.*)$ /diglossa/_design/diglossa.coffee/css/$1 last;
44
+ rewrite ^/templates/(.*)$ /diglossa/_design/diglossa.coffee/templates/$1 last;
45
+ rewrite ^/_view/(.*)$ /diglossa/_design/diglossa.coffee/_view/$1 last;
46
+ rewrite ^/(.*)$ /diglossa/_design/diglossa.coffee/_list/index/byUrl?key=%22$1%22&include_docs=true last;
47
+
48
+ location / {
49
+ proxy_pass http://127.0.0.1:5984;
50
+ #proxy_redirect default;
51
+ proxy_redirect off;
52
+ #proxy_set_header Accept-Encoding "";
53
+ proxy_set_header Host $host;
54
+ proxy_set_header X-Real-IP $remote_addr;
55
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
56
+ }
57
+ charset utf-8;
58
+ access_log /var/log/nginx/diglossa.log;
59
+ }
60
+
61
+
62
+
63
+
64
+
65
+ # MAIN
66
+ server {
67
+ listen 195.54.209.42:80;
68
+ server_name ru1.diglossa.org en1.diglossa.org;
69
+
70
+ # location ~* ^.+\.(ogg|gz){
71
+ # root /home/michael/web/diglossa.media/;
72
+ # }
73
+ # location ~* \.js$ {
74
+ # # # Some basic cache-control for static files to be sent to the browser
75
+ # expires max;
76
+ # add_header Pragma public;
77
+ # add_header Cache-Control "public, must-revalidate, proxy-revalidate";
78
+ # root /home/michael/web/socadimo/diglossa.coffee;
79
+ # }
80
+ # #
81
+ location / {
82
+ proxy_pass http://127.0.0.1:5984;
83
+ #proxy_redirect default;
84
+ proxy_set_header Accept-Encoding "";
85
+ proxy_set_header Host $host;
86
+ proxy_set_header X-Real-IP $remote_addr;
87
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
88
+ proxy_redirect off;
89
+ }
90
+ charset utf-8;
91
+ access_log /var/log/nginx/diglossa.log;
92
+ }
93
+
94
+
95
+ # DEVEL
96
+ server {
97
+ listen 195.54.209.42:80;
98
+ server_name dev.diglossa.org;
99
+
100
+ # location ~* ^.+\.(ogg|gz){
101
+ # root /home/michael/web/diglossa.media/;
102
+ # }
103
+ # location ~* \.js$ {
104
+ # # # Some basic cache-control for static files to be sent to the browser
105
+ # expires max;
106
+ # add_header Pragma public;
107
+ # add_header Cache-Control "public, must-revalidate, proxy-revalidate";
108
+ # root /home/michael/web/diglossa.coffee;
109
+ # }
110
+ # #
111
+ location / {
112
+ proxy_pass http://127.0.0.1:5984;
113
+ #proxy_redirect default;
114
+ proxy_set_header Accept-Encoding "";
115
+ proxy_set_header Host $host;
116
+ proxy_set_header X-Real-IP $remote_addr;
117
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
118
+ proxy_redirect off;
119
+ }
120
+ charset utf-8;
121
+ access_log /var/log/nginx/diglossa-coffee.log;
122
+ }
123
+
124
+
125
+ # server {
126
+ # listen 195.54.209.42:80;
127
+ # server_name diglossa.org www.diglossa.org;
128
+ # location /robots.txt {
129
+ # #alias /;
130
+ # #alias http://127.0.0.1:5984/diglossa/_design/diglossa/robots.txt;
131
+ # #root /diglossa/_design/diglossa;
132
+ # #root /;
133
+ # #rewrite ^/robots.txt$ /diglossa/_design/diglossa/robots.txt last;
134
+ # proxy_pass http://127.0.0.1:5984/diglossa/_design/diglossa/robots.txt;
135
+ # #proxy_redirect default;
136
+ # proxy_redirect off;
137
+ # #proxy_set_header Host $host;
138
+ # #proxy_set_header X-Real-IP $remote_addr;
139
+ # }
140
+ # location / {
141
+ # rewrite ^/(.*)$ http://en.diglossa.org/$1 permanent;
142
+ # }
143
+ # }
144
+
145
+ server {
146
+ listen 195.54.209.42:80;
147
+ server_name diglossa.ru www.diglossa.ru;
148
+ rewrite ^/(.*)$ http://ru.diglossa.org/$1 permanent;
149
+ location / {
150
+ }
151
+ }
152
+ server {
153
+ listen 195.54.209.42:80;
154
+ server_name diglossa.org www.diglossa.org;
155
+ rewrite ^/(.*)$ http://en.diglossa.org/$1 permanent;
156
+ location / {
157
+ }
158
+ }
159
+
160
+
161
+ server {
162
+ listen 195.54.209.42:5984;
163
+ server_name diglossa.ru;
164
+
165
+ location / {
166
+ proxy_pass http://127.0.0.1:5984/;
167
+ proxy_redirect off;
168
+ }
169
+
170
+ access_log /var/log/nginx/morpheus.log;
171
+ }
172
+
173
+
174
+ server {
175
+ listen 195.54.209.42:9001;
176
+ server_name diglossa.ru;
177
+
178
+ location / {
179
+ proxy_pass http://127.0.0.1:9001/;
180
+ #proxy_pass http://localhost:9001;
181
+ proxy_redirect default;
182
+ #proxy_redirect off;
183
+ }
184
+ charset utf-8;
185
+ access_log /var/log/nginx/morpheus.log;
186
+ }
187
+
188
+ # server {
189
+ # listen 195.54.209.42:9001;
190
+ # server_name diglossa.ru;
191
+
192
+ # location / {
193
+ # proxy_pass http://127.0.0.1:9001/;
194
+ # proxy_redirect off;
195
+ # }
196
+ # access_log /var/log/nginx/morpheus.log;
197
+ # }
198
+
199
+
200
+
201
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diglossa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.27
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-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: addressable
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
126
142
  - !ruby/object:Gem::Dependency
127
143
  name: thor
128
144
  requirement: !ruby/object:Gem::Requirement
@@ -169,8 +185,10 @@ files:
169
185
  - README.md
170
186
  - Rakefile
171
187
  - bin/dg
188
+ - bin/dg-author
172
189
  - diglossa.gemspec
173
190
  - lib/diglossa.rb
191
+ - lib/diglossa/author.rb
174
192
  - lib/diglossa/classext.rb
175
193
  - lib/diglossa/cli.rb
176
194
  - lib/diglossa/parse.rb
@@ -179,6 +197,7 @@ files:
179
197
  - lib/diglossa/templates/blog/04-02-2013-blog
180
198
  - lib/diglossa/templates/couchapprc.erb
181
199
  - lib/diglossa/version.rb
200
+ - nginx-last.conf
182
201
  - spec/spec_helper.rb
183
202
  homepage: ''
184
203
  licenses: []