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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4fe8cdf0de69687376216298815460652c061da
4
- data.tar.gz: f393191800c356c81552e8e0232dc7c500161fff
3
+ metadata.gz: da2de1a78d300f504b18d5d9a04e2979cad7d1dc
4
+ data.tar.gz: 1f526dc6e99517d29e498afd1ddb55d6847355ba
5
5
  SHA512:
6
- metadata.gz: ef061d64d0440cb74153c1a91bda547e1771a967f9624ce8fc9d0594677cd81038c33d8229fc654c14d0548203804587f1867a80ce768553f6f10370bf253aa9
7
- data.tar.gz: 30dc81baeea0a2a377df3639437eaaf120b6b5ba1606b53e09ecd7937b2c60f8cad07b0bc955dcae4944f5184e6ad51d2c929c9021160112788549e577b6072c
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
@@ -9,4 +9,4 @@ OptionParser.new { |opt|
9
9
  opt.on('-n name') {|v| params[:name] = v }
10
10
  }.parse!(ARGV)
11
11
 
12
- Areilayout::Config.start([:set, params[:path], params[:name]])
12
+ Areilayout::Config.start([ARGV[0], params[:path], params[:name]])
@@ -0,0 +1,7 @@
1
+ module Areilayout
2
+
3
+ class Layout < ActiveRecord::Base
4
+ self.table_name = 'cms_layouts'
5
+ end
6
+
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Areilayout
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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
- @source_path = source_path
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
- copy
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
- setup
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
- private
36
- def copy
37
-
38
- FileUtils.mkdir_p(@dest_path) and p_info("mkdir #{@dest_path}") unless Dir.exist?(@dest_path)
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 update_node
85
- @node = Node.find(2)
86
- @node.layout_id = @layout.id
87
- @node.save!
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
- class Layout < ActiveRecord::Base
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
@@ -51,5 +51,5 @@ describe Areilayout do
51
51
  @ret = Areilayout::Config.new.set(@src_path, @layout_name)
52
52
  expect(@ret).to eq true
53
53
  end
54
-
54
+
55
55
  end
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.2
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