templatit 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92b477282774250cafa6b92d040668cec83840f8
4
+ data.tar.gz: 2c8adc9b3e0d6b098006b8cf7c2816893329535f
5
+ SHA512:
6
+ metadata.gz: 84cfb33118c34f7d7c581efab509e498d77fe28ed2902186c03a7170115987655cb1fa184926c1c31b9ef956adf7fbf150b3cfcd822eecdb3c5add867d1db7b2
7
+ data.tar.gz: de47de42a89ca22dca30acadf17c5df1b4906f332c6580f6e9e19ae320d00be073384161debc7bcf09889fe10b9b29df25a69f9fb0bdfc2a5586c229114f25ec
data/bin/templatit ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'templatit'
4
+ Templatit.run(ARGV[0])
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <build>
4
+ <string name="UMENG_APPKEY">qqqq</string>
5
+ <string name="UMENG_CHANNEL">qqqq</string>
6
+ </build>
7
+ <config>
8
+ <string name="client_conf_http_host">qqqq</string>
9
+ <string name="client_conf_push_host">qqqq</string>
10
+ </config>
11
+ <strings>
12
+ <string name="app_name">qqqq</string>
13
+ <string name="tab_chat">qqqq</string>
14
+ <string name="top_right_start_conversation">qqqq</string>
15
+ <string name="mx_share_message_success_stay">qqqq</string>
16
+ <string name="mx_share_message_unsupport">qqqq</string>
17
+ </strings>
18
+ </resources>
@@ -0,0 +1,104 @@
1
+ # -*- coding:utf-8 -*-
2
+ require 'nokogiri'
3
+ require 'erb'
4
+ require 'rexml/document'
5
+ require 'pathname'
6
+ include REXML
7
+
8
+
9
+
10
+
11
+ def get_tags(directory)
12
+ puts Pathname.new(__FILE__).realpath
13
+ all_in_one_config_file = File.join(File.dirname(__FILE__), "android.xml")
14
+ @doc = Nokogiri::XML(File.open(all_in_one_config_file))
15
+ @doc.xpath("//"+directory+"//string")
16
+ #this return nodes
17
+ end
18
+
19
+ def get_pairs()
20
+ puts Pathname.new(__FILE__).realpath
21
+ all_in_one_config_file = File.join(File.dirname(__FILE__), "android.xml")
22
+ xmlfile = File.new(all_in_one_config_file)
23
+ xmldoc = Document.new(xmlfile)
24
+ pairs = {}
25
+ xmldoc.elements.each('/resources/build/string') do |e|
26
+ #pairs.store(e.attributes['name'],e.text)
27
+ k=e.attributes['name']
28
+ v=e.text
29
+ pairs.store(k,v)
30
+ end
31
+ # pairs.each do |key,value|
32
+ # puts key
33
+ # puts value
34
+ # end
35
+ pairs
36
+ end
37
+
38
+ def get_template(directory)
39
+ case directory
40
+ when 'config'
41
+ %{
42
+
43
+ <?xml version="1.0" encoding="utf-8"?>
44
+ <resources>
45
+ <% for @result_node in @pairs %>
46
+ <%= @result_node %><% end %>
47
+ <string name="client_server_grant_type">password</string>
48
+
49
+ <string name="client_show_sliding">true</string>
50
+ <string name="client_show_handle">true</string>
51
+ <string name="client_show_ext_network">true</string>
52
+ <string name="client_show_contact_ocu">true</string>
53
+ <string name="client_show_contact_company">true</string>
54
+ <string name="client_show_mail">false</string>
55
+ <string name="client_show_scan">true</string>
56
+ <!-- control encrypt the cell phone number -->
57
+ <!--
58
+ <string name="client_encrypt_cellphone">3,7</string>
59
+ -->
60
+ <string name="client_conf_sdcard_root">/minxing_ylx</string>
61
+ <string name="client_conf_query_robot_url">http://183.6.158.5:8197/empvoice/machine/mob/query.do?mxLayout=0</string>
62
+ <string name="client_conf_consultant_url">http://183.6.158.5:8197/empvoice/expert/mob/info.do?mxLayout=0</string>
63
+ <string name="client_conf_share_knowledge_url">http://183.6.158.5:8197/empvoice/knowledge/mob/edit.do?mxLayout=0</string>
64
+ <string name="client_app_center_force_refresh">true</string>
65
+ <string name="client_water_mark_enable">true</string>
66
+ </resources>
67
+
68
+ }
69
+ when 'strings'
70
+ %{<resources>
71
+ <% for @result_node in @pairs %>
72
+ <%= @result_node %><% end %>
73
+ </resources>
74
+ }
75
+ when 'build'
76
+ %{<% @pairs.each do |key,value| %><%= key %>:<%= value%>
77
+ <% end %>}
78
+ end
79
+ end
80
+
81
+ class ConfigXML
82
+ include ERB::Util
83
+ attr_accessor :pairs, :template, :date
84
+
85
+ def initialize(pairs, template)
86
+ @pairs = pairs
87
+ puts pairs
88
+ @template = template
89
+ end
90
+
91
+ def render()
92
+ ERB.new(@template).result(binding)
93
+ end
94
+
95
+ def save(file)
96
+ File.open(file, "w+") do |f|
97
+ f.write(render)
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+
104
+
data/lib/templatit.rb ADDED
@@ -0,0 +1,18 @@
1
+ class Templatit
2
+ require 'templatit/xml_update'
3
+ def self.run(system_type)
4
+ case system_type
5
+ when 'a'
6
+ puts "=====generating====="
7
+ current_directory = Dir.pwd
8
+ #current_directory = File.dirname(__FILE__)
9
+ xml_generated = ConfigXML.new(get_tags('config'), get_template('config'))
10
+ xml_generated.save(File.join(current_directory + '/res/values', 'config.xml'))
11
+ xml_generated = ConfigXML.new(get_tags('strings'), get_template('strings'))
12
+ xml_generated.save(File.join(current_directory + '/res/values', 'strings.xml'))
13
+ yaml_generated = ConfigXML.new(get_pairs, get_template('build'))
14
+ yaml_generated.save(File.join(current_directory + '/', 'build.yaml'))
15
+ when 'i'
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: templatit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Jackal Cooper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: gem to generate Android and iOS config files
14
+ email: jackalcooper@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - bin/templatit
20
+ - lib/templatit.rb
21
+ - lib/templatit/android.xml
22
+ - lib/templatit/xml_update.rb
23
+ homepage: http://jackalcooper.heroku.com
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.5.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Jackal's first gem
47
+ test_files: []
48
+ has_rdoc: