repoaccessor 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c83898680ee4af27afe897f9a7d57dc2fa872a52
4
- data.tar.gz: f0f9539685529a563ba02c486741be6aa003602f
3
+ metadata.gz: 51103cd85124144ccf57adf8e02a097fce7650e4
4
+ data.tar.gz: 3bf88d761ff1683fd00d979c1b2b94947e74b26c
5
5
  SHA512:
6
- metadata.gz: d12ef35d1a7b5e0031903e8e643b3ee8c7b5a1676ed9923709fe55651771b381553c34d35cd885a596a2bb57e41455b1ccedbaed17fd13fc8d9275efd842b026
7
- data.tar.gz: d1c1b22e3c68c72338e0027581270e8957accada006cb93b6867fe4c8bdae0b982a0daf0c361fa1ea559857f194b40a934786326641c5c60a97693522e377df3
6
+ metadata.gz: 6ad0847bddbf60e5b758f9ea5f3dfbdd0a809e842a8dc5da78622fbdc2f1e6c71e2c5762d7783f950d7c76eb988845f69518a98cfa9d6109aa21bc3ead8738e9
7
+ data.tar.gz: 4ed943e96229403849a5eddc7e1744569e34edd404629f674cce633c6ff04871161e19b85469cbf2243e15d4f32e31905e77b2525c225f0be4571ddde778786e
data/README.md CHANGED
@@ -22,8 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ```
26
+
27
+ require "repoaccessor"
28
+
29
+ Repoaccessor::checkout("usrname","password","repo-url","path/to/working-copy") # success:0
30
+ p Repoaccessor::inspect_repo("path/to/working-copy") #json format
26
31
 
32
+
33
+ ```
27
34
  ## Development
28
35
 
29
36
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake true` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,5 +1,5 @@
1
1
 
2
- require "repoaccessor/version"
2
+ require "repoaccessor"
3
3
 
4
4
 
5
5
  module Repoaccessor
@@ -52,7 +52,7 @@ module Repoaccessor
52
52
  proj_name[0]
53
53
  end
54
54
  elsif @platform == "android"
55
-
55
+ #TODO: 需要通过目录操作,找到对应的工程.
56
56
  else
57
57
  "unkonwn"
58
58
  end
@@ -74,7 +74,7 @@ module Repoaccessor
74
74
  resource_file_paths.each { |file|
75
75
  file_hash = {}
76
76
  file_hash[:lang] = File.basename(file,".*")
77
- file_hash[:kv_pairs] = XMLParser::parse(file).to_hash
77
+ file_hash[:kv_pairs] = XMLParser::parse(file).to_hash(:with_comments => with_comments)
78
78
  @resources_files << file_hash
79
79
  }
80
80
  else
@@ -21,6 +21,7 @@ module Repoaccessor
21
21
  end
22
22
 
23
23
  def bundle_paths
24
+ #TODO: 这里根据platform改一下 iOS和android找不同的目录
24
25
  Dir.chdir(@rootpath)
25
26
  paths = []
26
27
  Dir.glob(File.join("**", "*.bundle")) { |file|
@@ -1,5 +1,92 @@
1
+ # require "repoaccessor"
1
2
 
2
- require "yaml"
3
- require "json"
3
+ # Repoaccessor::checkout("lj94409","qwpoplko12..","http://svnhz.alipay.net/svn/ios-phone-mobilecommon/branches/cp_daily_project_489839_20151008_ios-phone-mobilecommon","Users/Jason/Documents/Jason/9-3mobile-common")
4
+ # p Repoaccessor::inspect_repo("Users/Jason/Documents/Jason/9-3mobile-common")
5
+
6
+
7
+ # require "rexml/document"
8
+
9
+ # class KV_pair
10
+ # attr_accessor :key
11
+ # attr_accessor :value
12
+ # attr_accessor :comment
13
+
14
+ # def initialize(key,value,comment)
15
+ # @key = key
16
+ # @value = value
17
+ # @comment = comment
18
+ # end
19
+
20
+
21
+ # def to_hash
22
+ # {
23
+ # :key => @key,
24
+ # :value => @value,
25
+ # :comment => @comment
26
+ # }
27
+
28
+ # end
29
+
30
+ # end
31
+
32
+
33
+ # class XMLFile
34
+ # attr_accessor :kv_pairs
35
+
36
+ # def initialize
37
+ # @kv_pairs = []
38
+ # end
39
+
40
+ # def key_values
41
+ # #TODO
42
+ # end
43
+
44
+ # def keys
45
+ # @kv_pairs.each { |e|
46
+
47
+ # }
48
+ # end
49
+
50
+ # def values
51
+ # #TODO
52
+ # end
53
+
54
+ # def to_hash(args={})
55
+ # with_comments = args[:with_comments].nil? ? true : args[:with_comments]
56
+ # build_hash { |hash, pair|
57
+ # hash_value = with_comments ? { pair.value => pair.comment } : pair.value
58
+ # hash[pair.key] = hash_value
59
+ # }
60
+ # end
61
+
62
+ # def to_json
63
+ # #TODO
64
+ # end
65
+
66
+ # def build_hash(&block)
67
+ # hash = {}
68
+ # @kv_pairs.each do |pair|
69
+ # yield hash, pair
70
+ # end
71
+ # hash
72
+ # end
73
+
74
+ # end
75
+
76
+
77
+
78
+
79
+ # # file = File.new("/Users/Jason/Downloads/share_2/api/res/values-en/strings-en.xml")
80
+ # # doc = REXML::Document.new file
81
+ # xmlfile = XMLFile.new()
82
+ # resourcefile = File.new("/Users/Jason/Downloads/share_2/api/res/values-en/strings-en.xml")
83
+ # doc = REXML::Document.new resourcefile
84
+ # doc.elements.each("resources/string") { |e|
85
+ # key = e.attributes["name"]
86
+ # value = e.text
87
+ # kv = KV_pair.new(key,value,"")
88
+ # xmlfile.kv_pairs << kv
89
+ # }
90
+ # p xmlfile.to_hash(:with_comments => false)
4
91
 
5
92
 
@@ -1,3 +1,3 @@
1
1
  module Repoaccessor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,32 @@
1
1
 
2
2
  module Repoaccessor
3
3
 
4
+ require "json"
5
+
6
+ class KV_pair
7
+ attr_accessor :key
8
+ attr_accessor :value
9
+ attr_accessor :comment
10
+
11
+ def initialize(key,value,comment)
12
+ @key = key
13
+ @value = value
14
+ @comment = comment
15
+ end
16
+
17
+
18
+ def to_hash
19
+ {
20
+ :key => @key,
21
+ :value => @value,
22
+ :comment => @comment
23
+ }
24
+
25
+ end
26
+
27
+ end
28
+
29
+
4
30
  class XMLFile
5
31
  attr_accessor :kv_pairs
6
32
 
@@ -9,24 +35,36 @@ module Repoaccessor
9
35
  end
10
36
 
11
37
  def key_values
12
- #TODO
38
+ #TODO:不影响主功能
13
39
  end
14
40
 
15
41
  def keys
16
- #TODO
42
+ #TODO:不影响主功能
17
43
  end
18
44
 
19
45
  def values
20
- #TODO
46
+ #TODO:不影响主功能
21
47
  end
22
48
 
23
- def to_hash
24
- #TODO
49
+ def to_hash(args={})
50
+ with_comments = args[:with_comments].nil? ? true : args[:with_comments]
51
+ build_hash { |hash, pair|
52
+ hash_value = with_comments ? { pair.value => pair.comment } : pair.value
53
+ hash[pair.key] = hash_value
54
+ }
25
55
  end
26
56
 
27
57
  def to_json
28
- #TODO
58
+ self.to_hash(:with_comments => false).to_json
29
59
  end
60
+
61
+ def build_hash(&block)
62
+ hash = {}
63
+ @kv_pairs.each do |pair|
64
+ yield hash, pair
65
+ end
66
+ hash
67
+ end
30
68
 
31
69
  end
32
70
 
@@ -1,12 +1,22 @@
1
1
 
2
2
 
3
3
  module Repoaccessor
4
+ require "rexml/document"
4
5
  require "repoaccessor/xmlfile"
5
6
 
6
7
  class XMLParser
7
8
  #returning an XMLFile object , with to_hash to_json method.
8
9
  def self.parse(file)
9
- raise "Not implemented yet ..."
10
+ xmlfile = XMLFile.new()
11
+ resourcefile = File.new(file)
12
+ doc = REXML::Document.new resourcefile
13
+ doc.elements.each("resources/string") { |e|
14
+ key = e.attributes["name"]
15
+ value = e.text
16
+ kv = KV_pair.new(key,value,"")
17
+ xmkfile.kv_pairs << kv
18
+ }
19
+ xmlfile
10
20
  end
11
21
  end
12
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repoaccessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 卡迩
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler