tcms 0.9.1 → 0.9.3

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: 4fb365b173a996cbde60604babc913c56ada8eae
4
- data.tar.gz: c108119027212708cec9913e7e2dc763daec11cc
3
+ metadata.gz: 4792b187d7993510df0ecdfda818d64c4b41c507
4
+ data.tar.gz: 63719cb502d163b9c9f8c374d9eed425b91255f8
5
5
  SHA512:
6
- metadata.gz: b14ead2367a951fb0c0971e8dd83f762da0ed557c5a33666a8faa92960c9af40d30110392426dc7ccb50094e8088eb64bd749c1b474e8168de7539e2d33e8adc
7
- data.tar.gz: 87e984fa0d42991d7f32c7ce7b3e2f78655532791c8ad7140a8b52471aaa6df791d04af3793dbecdfd3087ba8f16e3aad5de557b28c01308e6b0c1cbefaf69b0
6
+ metadata.gz: 4024cfa0b32436d6c1aa696e97ec1d32cb90b4264fd95cadd35e55d1940a708773b61efa858ccbd642d26683dd355e3e95dedcf32e757ea0f1237e7b9980621f
7
+ data.tar.gz: d851245f17d399c5d30f007b9a54eeac800ad75a1a7d8a7d64095792cd349bd53868f32f0d713a9f767ffaf5eadee072f9400c348b22f2116af0f8e2d546f9c0
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in tcms.gemspec
4
4
  gem 'rest_client'
5
+ gem 'sinatra'
data/bin/tcms CHANGED
@@ -9,11 +9,6 @@ rescue
9
9
  require "tcms"
10
10
  end
11
11
 
12
- #减少
13
- #unless File.exist?('project.yml')
14
- # puts '未创建配置文件,请输入 tcms -create 来创建配置'
15
- # exit
16
- #end
17
12
 
18
13
  options = {}
19
14
  opt = OptionParser.new do |opts|
@@ -26,6 +21,13 @@ opt = OptionParser.new do |opts|
26
21
  options[:type] = type
27
22
  options[:action] = :build
28
23
  end
24
+
25
+ opts.on('-c','--create','创建配置文件') do |type|
26
+ options[:action] = :create
27
+ end
28
+ opts.on('-s',"--server",'呼起本地服务') do
29
+ options[:action] = :server
30
+ end
29
31
  opts.on('-h','--help','帮助文档') do |n|
30
32
  puts opts
31
33
  puts '更多参考,请访问-http://wiki.cms.tencent-cloud.com/mars.html'
@@ -42,4 +44,14 @@ when :deploy
42
44
  end
43
45
  when :build
44
46
  Tcms::build_project(options[:type])
47
+ when :create
48
+ Tcms::create_project
49
+ when :server
50
+ puts '启动服务,如果失败,请用高级权限运行:ruby server.local'
51
+ begin
52
+ `ruby server.local`
53
+ rescue
54
+ end
55
+ else
56
+ puts opt
45
57
  end
data/lib/tcms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tcms
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.3"
3
3
  end
data/lib/tcms.rb CHANGED
@@ -2,6 +2,7 @@ require 'yaml'
2
2
  require 'rest_client'
3
3
  require 'rake'
4
4
  require 'pathname'
5
+ require 'json'
5
6
 
6
7
  begin
7
8
  tcms_lib_path = Pathname.new(File.dirname(__FILE__)).realpath.to_s
@@ -107,13 +108,61 @@ module Tcms
107
108
  return
108
109
  end
109
110
 
111
+
110
112
  project = self.read_config_file PROJECT_FILE
113
+
114
+ config_file = project["templates"]["folder"]+"/config.js"
115
+
116
+ @template_config = Hash.new
117
+
118
+ if File.exist? config_file
119
+ puts "读取模版配置文件#{config_file}.."
120
+ config_content = File.read(config_file,:encoding=>"UTF-8")
121
+ @template_config = JSON.parse config_content.gsub(/'/,'"')
122
+ end
123
+
124
+ @template_config.each do |key,value|
125
+ if value.respond_to? :has_key? and value.has_key? "_data_from_url"
126
+ puts "获取献上接口数据#{value}.."
127
+ response = RestClient.get value["_data_from_url"],{:accept=>:json}
128
+ @template_config[key] = JSON.parse(response)
129
+
130
+ if @template_config[key].is_a?(Hash)
131
+ if @template_config[key].has_key? 'code'
132
+ @template_config[key] = @template_config[key]["data"]
133
+ end
134
+ end
135
+ end
136
+ end
137
+
111
138
  FileList.new(project['templates']['folder']+'/**/*').each do |f|
112
139
  result = f.match(/\/(\w+).html?\.erb/)
113
140
  if result
114
- publisher = Tcms::Publisher.new(result[1],{"title"=>"aa"},project)
141
+ publisher = Tcms::Publisher.new(result[1],@template_config,project)
115
142
  publisher.render(type)
116
143
  end
117
144
  end
118
145
  end
146
+
147
+ def self.create_project
148
+ template_folder = Pathname.new(File.dirname(__FILE__)).realpath.parent.to_s+"/template"
149
+ if File.exist? 'project.yml'
150
+ puts '已存在配置文件project.yml'
151
+ else
152
+ puts '创建配置文件成功!-project.yml'
153
+ content = File.read(template_folder+"/project.yml.edit",:encoding=>"UTF-8")
154
+ pro_file = File.new('project.yml',"w+")
155
+ pro_file.puts content
156
+ pro_file.close
157
+ end
158
+
159
+ unless File.exist? "server.local"
160
+ server_content = File.read(template_folder+'/server.local',:encoding=>"UTF-8")
161
+ server_file = File.new("server.local","w+")
162
+ server_file.puts server_content
163
+ server_file.close
164
+ File.chmod(0755,'server.local')
165
+ end
166
+
167
+ end
119
168
  end
@@ -0,0 +1,17 @@
1
+ project_name: {YOUR_PROJECT_NAME}
2
+ version : 1.0
3
+ encoding : UTF-8
4
+ assets:
5
+ channel : {频道,类似news,pingjs等,非必须,配置了site=mat1后,需要配置频道}
6
+ site : {mat1 素材暂时都在mat1}
7
+ remotepath : {远程文件夹remote/path/}
8
+ folder : {本地文件夹publish/assets}
9
+ pages:
10
+ site : {页面发布频道,如http://news.qq.com/xx}
11
+ remotepath : {页面远程目录/xx/path}
12
+ folder: {页面本地目录:publish}
13
+ templates :
14
+ folder : {模版文件夹:templates}
15
+ scripts:
16
+ folder : {编辑脚本文件夹:assets/scripts}
17
+
@@ -1,8 +1,6 @@
1
- require 'sinatra'
2
- require 'json'
3
- set :bind,'0.0.0.0'
4
- set :port,'80'
5
- set :root, File.dirname(__FILE__)
6
- set :public_folder, File.dirname(__FILE__)
7
-
8
-
1
+ require 'sinatra'
2
+ require 'json'
3
+ set :bind,'0.0.0.0'
4
+ set :port,'80'
5
+ set :root, File.dirname(__FILE__)
6
+ set :public_folder, File.dirname(__FILE__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'bertwang'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,7 +55,8 @@ files:
55
55
  - lib/tcms/helper.rb
56
56
  - lib/tcms/publisher.rb
57
57
  - lib/tcms/version.rb
58
- - server
58
+ - template/project.yml.edit
59
+ - template/server.local
59
60
  homepage: http://dxtool.cms.tencent-cloud.com/
60
61
  licenses:
61
62
  - MIT