Class: Diglossa::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/diglossa/parse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_dir) ⇒ Parse

, config_path = nil)



11
12
13
14
15
16
# File 'lib/diglossa/parse.rb', line 11

def initialize(app_dir) #, config_path = nil)
  self.app_dir = File.expand_path(app_dir) + '/'
  @warns = {file:[], size:[]}
  @counter = []
  #load_couchapprc
end

Instance Attribute Details

#app_dirObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def app_dir
  @app_dir
end

#author_nicObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def author_nic
  @author_nic
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/diglossa/parse.rb', line 9

def config
  @config
end

#counterObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def counter
  @counter
end

#dbauthorsObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def dbauthors
  @dbauthors
end

#documentObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def document
  @document
end

#filepathsObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def filepaths
  @filepaths
end

#localeObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def locale
  @locale
end

#nicsObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def nics
  @nics
end

#rootObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def root
  @root
end

#rppObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def rpp
  @rpp
end

#warnsObject

, :config_path, :revision



8
9
10
# File 'lib/diglossa/parse.rb', line 8

def warns
  @warns
end

Instance Method Details

#build(root, push = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/diglossa/parse.rb', line 28

def build root, push=false
  # FIXME: Lib to .diglossarc
  fn = File.expand_path(File.join(Diglossa::Lib, root))
  fullname = File.exist?("#{fn}.json") ? "#{fn}.json" : File.exist?("#{fn}.yml") ? "#{fn}.yml" : false
  return nil unless fullname
  doc = fullname ? YAML.load_file(fullname) : "no .json or .yml file at #{root}"
  @nics = doc["authors"]
  remote = Diglossa::Remote.new(app_dir)
  #puts "locales #{remote.config["locales"]}"
  @rpp = {}
  @dbauthors = remote.author(doc["authors"])
  @author_nic = root.split("/")[1].downcase
  #lang = root.split('/').first.downcase
  @locale = "ru"
  title = root.split("/").last # .gsub("_", " ")
  if push == "book"
    jsru = {isFolder:true, expand: true, children:[]}
    jsen = {isFolder:true, expand: true, children:[]}
    traverse jsru, doc["tree"], root, title do |path|
      parallels path # cause of rpp, alas
    end
    @locale = "en"
    traverse jsen, doc["tree"], root, title
    [{type:"book", url:root.to_url, jstree:jsru, rpp:rpp, locale:"ru"},
    {type:"book", url:root.to_url, jstree:jsen, rpp:rpp, locale:"en"}]
  elsif push == "docs"
    jsru = {url:root.to_url, isFolder:true, expand: true, children:[]}
    traverse jsru, doc["tree"], root, title do |path|
      parallels path, true
    end
  elsif push == "warns"
    jsru = {url:root.to_url, isFolder:true, expand: true, children:[]}
    traverse jsru, doc["tree"], root, title do |path|
      parallels path
    end
    warns
  end
end

#parse_author(nic) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/diglossa/parse.rb', line 18

def parse_author(nic)
  # FIXME: поправить название, это чтение файла
  fn = File.expand_path(File.join(app_dir, nic))
  fullname = "#{fn}.json"
  return nil unless File.exist?(fullname)
  doc = YAML.load_file fullname
  doc
end