areilayout 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/areilayout.gemspec +1 -0
- data/bin/areilayout +1 -1
- data/lib/areilayout/layout.rb +7 -0
- data/lib/areilayout/version.rb +1 -1
- data/lib/areilayout.rb +69 -49
- data/spec/areilayout_get_spec.rb +33 -0
- data/spec/areilayout_spec.rb +1 -1
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da2de1a78d300f504b18d5d9a04e2979cad7d1dc
|
4
|
+
data.tar.gz: 1f526dc6e99517d29e498afd1ddb55d6847355ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccfc4587d847cbea3fc0a8481e9d2a2cb6e57032b33d2f232ef0b987bf77f0409d06d92a21d5de2ad8678ccf5dc2c2c291b9fa891b7468a4dfa7bbf66299e425
|
7
|
+
data.tar.gz: e8a4fd25d7fb3c2d2392268dc02a417d1bf606325fe641b34714811787ad69c7f8cf7c6171da3a54b519933789553fa744cd5bfd411d71f1029f1c8c93a9e96d
|
data/areilayout.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency 'thor', '~> 0.18', '>= 0.18.1'
|
22
22
|
spec.add_runtime_dependency 'activerecord'
|
23
23
|
spec.add_runtime_dependency 'mysql2'
|
24
|
+
spec.add_runtime_dependency 'rubyzip'
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
27
|
spec.add_development_dependency "rake"
|
data/bin/areilayout
CHANGED
data/lib/areilayout/version.rb
CHANGED
data/lib/areilayout.rb
CHANGED
@@ -3,48 +3,94 @@ require "thor"
|
|
3
3
|
require "rubygems"
|
4
4
|
require "active_record"
|
5
5
|
require "optparse"
|
6
|
+
require "open-uri"
|
6
7
|
|
7
8
|
module Areilayout
|
8
9
|
|
9
10
|
class Config < Thor
|
10
|
-
default_command :set
|
11
|
-
|
11
|
+
#default_command :set
|
12
|
+
|
12
13
|
desc "", ""
|
13
14
|
def set(source_path, layout_name)
|
14
15
|
begin
|
15
16
|
raise "Option is missing." if source_path.blank? || layout_name.blank?
|
16
17
|
|
17
18
|
raise "Directory is not exist." unless Dir.exist?(source_path)
|
18
|
-
|
19
|
-
|
20
|
-
@layout_name = layout_name
|
21
|
-
@app_root = Dir.getwd #=> should be RAILS_ROOT
|
22
|
-
@dest_path = "#{@app_root}/sites/00/00/00/01/00000001/public/_themes/#{@layout_name}"
|
19
|
+
|
20
|
+
init(source_path, layout_name)
|
23
21
|
|
24
22
|
establish_database
|
23
|
+
|
24
|
+
copy && setup
|
25
|
+
true
|
26
|
+
|
27
|
+
rescue => e
|
28
|
+
p_error(e.message)
|
29
|
+
end
|
30
|
+
end
|
25
31
|
|
26
|
-
|
32
|
+
desc "", ""
|
33
|
+
def get(source_path, layout_name)
|
34
|
+
begin
|
35
|
+
raise "Option is missing." if source_path.blank? || layout_name.blank?
|
27
36
|
|
28
|
-
|
37
|
+
init(source_path, layout_name)
|
38
|
+
|
39
|
+
establish_database
|
40
|
+
|
41
|
+
dl && copy && setup && rmdir
|
42
|
+
true
|
29
43
|
|
30
44
|
rescue => e
|
31
45
|
p_error(e.message)
|
32
46
|
end
|
33
47
|
end
|
34
48
|
|
35
|
-
|
36
|
-
def
|
37
|
-
|
38
|
-
|
49
|
+
private
|
50
|
+
def init(source_path, layout_name)
|
51
|
+
@source_path = source_path
|
52
|
+
@layout_name = layout_name
|
53
|
+
@app_root = Dir.getwd #=> RAILS_ROOT
|
54
|
+
@dest_path = "#{@app_root}/sites/00/00/00/01/00000001/public/_themes/#{@layout_name}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def dl
|
58
|
+
require "zip"
|
59
|
+
require "tempfile"
|
39
60
|
|
61
|
+
filename = "#{Dir.tmpdir}/#{File.basename(@source_path)}"
|
62
|
+
unless File.exist?(filename)
|
63
|
+
open(filename, 'wb') do |file|
|
64
|
+
open(URI.parse(@source_path)) do |data|
|
65
|
+
file.write(data.read)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
Zip::File.open(filename) do |zip|
|
70
|
+
zip.each do |entry|
|
71
|
+
#puts "entry #{entry.to_s}"
|
72
|
+
#zip.extract(entry, "#{dest_path}/#{entry.to_s}") { true }
|
73
|
+
zip.extract(entry, "#{Dir.tmpdir}/#{@layout_name}/#{entry.to_s}") { true }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
Dir.chdir "#{Dir.tmpdir}/#{@layout_name}"
|
78
|
+
index_file = Dir.glob("**/index.html")
|
79
|
+
raise "index.html is not exist." if index_file.blank?
|
80
|
+
@source_path = File.dirname(File.expand_path(index_file[0]))
|
81
|
+
end
|
82
|
+
|
83
|
+
def rmdir
|
84
|
+
FileUtils.remove_entry("#{Dir.tmpdir}/#{@layout_name}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def copy
|
88
|
+
raise "index.html is not exist." unless File.exist?("#{@source_path}/index.html")
|
89
|
+
FileUtils.mkdir_p(@dest_path) and p_info("mkdir #{@dest_path}") unless Dir.exist?(@dest_path)
|
40
90
|
FileUtils.copy_entry(@source_path, @dest_path, {:verbose => true})
|
41
|
-
|
42
91
|
end
|
43
92
|
|
44
93
|
def setup
|
45
|
-
|
46
|
-
raise "[index.html] is not exist." unless File.exist?("#{@dest_path}/index.html")
|
47
|
-
|
48
94
|
contents = Pathname("#{@dest_path}/index.html").read(:encoding => Encoding::UTF_8)
|
49
95
|
/<head>((\n|.)*)<\/head>/ =~ contents
|
50
96
|
head = $1
|
@@ -60,12 +106,7 @@ module Areilayout
|
|
60
106
|
head.gsub!("=\"#{dirname}/", "=\"/_themes/#{@layout_name}/#{dirname}/")
|
61
107
|
body.gsub!("=\"#{dirname}/", "=\"/_themes/#{@layout_name}/#{dirname}/")
|
62
108
|
end
|
63
|
-
|
64
109
|
create_layout(head, body)
|
65
|
-
|
66
|
-
#update_node
|
67
|
-
|
68
|
-
true
|
69
110
|
end
|
70
111
|
|
71
112
|
def create_layout(head, body)
|
@@ -81,19 +122,10 @@ module Areilayout
|
|
81
122
|
@layout.save!
|
82
123
|
end
|
83
124
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def p_usage
|
91
|
-
puts <<-EOL
|
92
|
-
Usage: areilayout set [options]
|
93
|
-
-p
|
94
|
-
-n
|
95
|
-
EOL
|
96
|
-
false
|
125
|
+
def establish_database
|
126
|
+
require "yaml"
|
127
|
+
config = YAML.load_file("#{@app_root}/config/database.yml")
|
128
|
+
ActiveRecord::Base.establish_connection(config["production"])
|
97
129
|
end
|
98
130
|
|
99
131
|
def p_error(msg)
|
@@ -105,19 +137,7 @@ Usage: areilayout set [options]
|
|
105
137
|
puts "INFO: #{msg}"
|
106
138
|
end
|
107
139
|
|
108
|
-
def establish_database
|
109
|
-
require "yaml"
|
110
|
-
config = YAML.load_file("#{@app_root}/config/database.yml")
|
111
|
-
ActiveRecord::Base.establish_connection(config["production"])
|
112
|
-
end
|
113
|
-
|
114
140
|
end
|
115
|
-
|
116
|
-
|
117
|
-
self.table_name = 'cms_layouts'
|
118
|
-
end
|
119
|
-
|
120
|
-
class Node < ActiveRecord::Base
|
121
|
-
self.table_name = 'cms_nodes'
|
122
|
-
end
|
141
|
+
|
142
|
+
require 'areilayout/layout'
|
123
143
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Areilayout do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@src_path = "http://download.html5xcss3.com/fanktlk/templatesmonster/webstudio.zip"
|
7
|
+
@layout_name = "webstudio"
|
8
|
+
@dest_dir = "/var/share/zomeki/sites/00/00/00/01/00000001/public/_themes"
|
9
|
+
Dir.chdir("/var/share/zomeki")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has error if index.html is not exist in templates' do
|
13
|
+
@src_path = "http://download.html5xcss3.com/fanktlk/templatesmonster/petclinic.zip"
|
14
|
+
@layout_name = "petclinic"
|
15
|
+
|
16
|
+
@ret = Areilayout::Config.new.get(@src_path, @layout_name)
|
17
|
+
expect(@ret).to eq false
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'is successfully get template & setup layout' do
|
21
|
+
@ret = Areilayout::Config.new.get(@src_path, @layout_name)
|
22
|
+
expect(@ret).to eq true
|
23
|
+
|
24
|
+
filename = "#{Dir.tmpdir}/#{File.basename(@src_path)}"
|
25
|
+
expect(File.exist?(filename)).to eq true
|
26
|
+
|
27
|
+
#Dir.chdir "#{Dir.tmpdir}/#{@layout_name}"
|
28
|
+
#index_file = Dir.glob("**/index.html")
|
29
|
+
#expect(File.exist?(File.expand_path(index_file[0]))).to eq true
|
30
|
+
expect(File.exist?("#{Dir.tmpdir}/#{@layout_name}")).to eq false
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/spec/areilayout_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: areilayout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cobachie
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - '>='
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rubyzip
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: bundler
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +132,9 @@ files:
|
|
118
132
|
- areilayout.gemspec
|
119
133
|
- bin/areilayout
|
120
134
|
- lib/areilayout.rb
|
135
|
+
- lib/areilayout/layout.rb
|
121
136
|
- lib/areilayout/version.rb
|
137
|
+
- spec/areilayout_get_spec.rb
|
122
138
|
- spec/areilayout_spec.rb
|
123
139
|
- spec/spec_helper.rb
|
124
140
|
- templates/bootstrap-3.1.1-dist/css/bootstrap-theme.css
|
@@ -159,5 +175,6 @@ signing_key:
|
|
159
175
|
specification_version: 4
|
160
176
|
summary: Write a short summary. Required.
|
161
177
|
test_files:
|
178
|
+
- spec/areilayout_get_spec.rb
|
162
179
|
- spec/areilayout_spec.rb
|
163
180
|
- spec/spec_helper.rb
|