areilayout 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da2de1a78d300f504b18d5d9a04e2979cad7d1dc
4
- data.tar.gz: 1f526dc6e99517d29e498afd1ddb55d6847355ba
3
+ metadata.gz: f08ee3a0a6db49d543582012c59a667968187ff5
4
+ data.tar.gz: 8cf95b8250870b82e1c8fdc7fb6759311dc773bf
5
5
  SHA512:
6
- metadata.gz: ccfc4587d847cbea3fc0a8481e9d2a2cb6e57032b33d2f232ef0b987bf77f0409d06d92a21d5de2ad8678ccf5dc2c2c291b9fa891b7468a4dfa7bbf66299e425
7
- data.tar.gz: e8a4fd25d7fb3c2d2392268dc02a417d1bf606325fe641b34714811787ad69c7f8cf7c6171da3a54b519933789553fa744cd5bfd411d71f1029f1c8c93a9e96d
6
+ metadata.gz: b27e9fb160eea90d8c36d4f62dea69b526cdede13affc2d4320c8b6453104f644764bfcb246dfad22ac2a8762c1d1f167a1e5ce1e1eb8fb01a7c73ffef74dfb2
7
+ data.tar.gz: 860e30fc3a21ea4beada2ef61f7be77d4b50e953b21326a66552301171195838ca350ec56551498c38419d97463fcf89ea4f8de82858d554ab278c507d9ae969
data/.rspec CHANGED
File without changes
@@ -1,9 +1,12 @@
1
1
  require "areilayout/version"
2
+ require "areilayout/utils"
3
+
2
4
  require "thor"
3
5
  require "rubygems"
4
6
  require "active_record"
5
7
  require "optparse"
6
8
  require "open-uri"
9
+ require "yaml"
7
10
 
8
11
  module Areilayout
9
12
 
@@ -25,7 +28,7 @@ module Areilayout
25
28
  true
26
29
 
27
30
  rescue => e
28
- p_error(e.message)
31
+ Utils.p_error(e.message)
29
32
  end
30
33
  end
31
34
 
@@ -38,11 +41,11 @@ module Areilayout
38
41
 
39
42
  establish_database
40
43
 
41
- dl && copy && setup && rmdir
44
+ dl && copy && setup && Utils.rmdir(@layout_name)
42
45
  true
43
46
 
44
47
  rescue => e
45
- p_error(e.message)
48
+ Utils.p_error(e.message)
46
49
  end
47
50
  end
48
51
 
@@ -68,8 +71,6 @@ private
68
71
  end
69
72
  Zip::File.open(filename) do |zip|
70
73
  zip.each do |entry|
71
- #puts "entry #{entry.to_s}"
72
- #zip.extract(entry, "#{dest_path}/#{entry.to_s}") { true }
73
74
  zip.extract(entry, "#{Dir.tmpdir}/#{@layout_name}/#{entry.to_s}") { true }
74
75
  end
75
76
  end
@@ -80,22 +81,17 @@ private
80
81
  @source_path = File.dirname(File.expand_path(index_file[0]))
81
82
  end
82
83
 
83
- def rmdir
84
- FileUtils.remove_entry("#{Dir.tmpdir}/#{@layout_name}")
85
- end
86
-
87
84
  def copy
88
85
  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)
86
+ FileUtils.mkdir_p(@dest_path) and Utils.p_info("mkdir #{@dest_path}") unless Dir.exist?(@dest_path)
90
87
  FileUtils.copy_entry(@source_path, @dest_path, {:verbose => true})
91
88
  end
92
89
 
93
90
  def setup
94
91
  contents = Pathname("#{@dest_path}/index.html").read(:encoding => Encoding::UTF_8)
95
- /<head>((\n|.)*)<\/head>/ =~ contents
96
- head = $1
97
- /<body.*>((\n|.)*)<\/body>/ =~ contents
98
- body = $1
92
+
93
+ head = Utils.tagclip(contents, "head")[1]
94
+ body = Utils.tagclip(contents, "body")[1]
99
95
 
100
96
  dir_list = []
101
97
  Dir.glob("#{@dest_path}/*").each do |filename|
@@ -106,38 +102,31 @@ private
106
102
  head.gsub!("=\"#{dirname}/", "=\"/_themes/#{@layout_name}/#{dirname}/")
107
103
  body.gsub!("=\"#{dirname}/", "=\"/_themes/#{@layout_name}/#{dirname}/")
108
104
  end
109
- create_layout(head, body)
105
+
106
+ raise "#{@layout_name} is already exist." unless CmsLayout.where(title: @layout_name).blank?
107
+ CmsLayout.new.save_layout(@layout_name, head, body)
108
+
109
+ set_piece(contents)
110
110
  end
111
111
 
112
- def create_layout(head, body)
113
- @layout = Layout.new
114
- @layout.concept_id = 1
115
- @layout.site_id = 1
116
- @layout.state = "public"
117
- @layout.name = @layout_name
118
- @layout.title = @layout_name
119
- @layout.head = head
120
- @layout.body = body
121
- # @layout.in_creator = {'group_id' => 2, 'user_id' => 1}
122
- @layout.save!
112
+ def set_piece(contents)
113
+ %w(header footer).each do |tag|
114
+ data = {}
115
+ data["body"] = Utils.tagclip(contents, tag)[0]
116
+ unless data["body"].blank?
117
+ Utils.p_info("Successfully registered piece [#{@layout_name}-#{tag}]") if CmsPiece.new.save_piece(data, "#{@layout_name}-#{tag}")
118
+ end
119
+ end
123
120
  end
124
-
121
+
125
122
  def establish_database
126
- require "yaml"
127
123
  config = YAML.load_file("#{@app_root}/config/database.yml")
128
124
  ActiveRecord::Base.establish_connection(config["production"])
129
125
  end
130
126
 
131
- def p_error(msg)
132
- puts "ERROR: #{msg}"
133
- false and return
134
- end
135
-
136
- def p_info(msg)
137
- puts "INFO: #{msg}"
138
- end
139
-
140
127
  end
141
128
 
142
- require 'areilayout/layout'
129
+ require "areilayout/cms_layout"
130
+ require "areilayout/cms_piece"
131
+
143
132
  end
@@ -0,0 +1,20 @@
1
+ module Areilayout
2
+
3
+ class CmsLayout < ActiveRecord::Base
4
+
5
+ def save_layout(layout_name, head, body)
6
+
7
+ @layout = CmsLayout.new
8
+ @layout.concept_id = 1
9
+ @layout.site_id = 1
10
+ @layout.state = "public"
11
+ @layout.name = layout_name
12
+ @layout.title = layout_name
13
+ @layout.head = head
14
+ @layout.body = body
15
+ # @layout.in_creator = {'group_id' => 2, 'user_id' => 1}
16
+ @layout.save!
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,40 @@
1
+ module Areilayout
2
+
3
+ class CmsPiece < ActiveRecord::Base
4
+
5
+ def save_piece(data, title)
6
+
7
+ return false if data.blank?
8
+
9
+ check_data(data, title)
10
+
11
+ return false unless CmsPiece.where(title: data["title"]).blank?
12
+
13
+ @piece = CmsPiece.new
14
+ @piece.concept_id = data["concept_id"]
15
+ @piece.site_id = data["site_id"]
16
+ @piece.state = data["state"]
17
+ @piece.model = data["model"]
18
+ @piece.name = data["name"]
19
+ @piece.title = data["title"]
20
+ @piece.view_title = data["view_title"]
21
+ @piece.body = data["body"]
22
+ @piece.save!
23
+
24
+ end
25
+
26
+ private
27
+ def check_data(data, title)
28
+ data["concept_id"] ||= 1
29
+ data["site_id"] ||= 1
30
+ data["state"] ||= "public"
31
+ data["model"] ||= "Cms::Free"
32
+ data["name"] ||= title
33
+ data["title"] ||= title
34
+ data["view_title"] ||= title
35
+ data
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,25 @@
1
+ module Areilayout
2
+
3
+ class Utils
4
+
5
+ def self.p_error(msg)
6
+ puts "ERROR: #{msg}"
7
+ false and return
8
+ end
9
+
10
+ def self.p_info(msg)
11
+ puts "INFO: #{msg}"
12
+ end
13
+
14
+ def self.rmdir(layout_name)
15
+ FileUtils.remove_entry("#{Dir.tmpdir}/#{layout_name}")
16
+ end
17
+
18
+ def self.tagclip(contents, tag)
19
+ /<#{tag}.*>((\n|.)*)<\/#{tag}>/ =~ contents
20
+ return [$&, $1]
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Areilayout
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -17,7 +17,15 @@ describe Areilayout do
17
17
  expect(@ret).to eq false
18
18
  end
19
19
 
20
+ it 'has error if lauout is already exist' do
21
+ @ret = Areilayout::Config.new.get(@src_path, @layout_name)
22
+ @ret = Areilayout::Config.new.get(@src_path, @layout_name)
23
+ expect(@ret).to eq false
24
+ end
25
+
20
26
  it 'is successfully get template & setup layout' do
27
+ Areilayout::CmsLayout.where(title: @layout_name).destroy_all
28
+
21
29
  @ret = Areilayout::Config.new.get(@src_path, @layout_name)
22
30
  expect(@ret).to eq true
23
31
 
@@ -46,7 +46,14 @@ describe Areilayout do
46
46
  expect(@ret).to eq false
47
47
  end
48
48
 
49
+ it 'has error if lauout is already exist' do
50
+ @ret = Areilayout::Config.new.get(@src_path, @layout_name)
51
+ @ret = Areilayout::Config.new.get(@src_path, @layout_name)
52
+ expect(@ret).to eq false
53
+ end
54
+
49
55
  it 'is successfully setup layout' do
56
+ Areilayout::CmsLayout.where(title: @layout_name).destroy_all
50
57
  #@ret = Areilayout::Config.new.set({p: "#{@src_path}", n: "#{@layout_name}"})
51
58
  @ret = Areilayout::Config.new.set(@src_path, @layout_name)
52
59
  expect(@ret).to eq true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: areilayout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - cobachie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -132,7 +132,9 @@ files:
132
132
  - areilayout.gemspec
133
133
  - bin/areilayout
134
134
  - lib/areilayout.rb
135
- - lib/areilayout/layout.rb
135
+ - lib/areilayout/cms_layout.rb
136
+ - lib/areilayout/cms_piece.rb
137
+ - lib/areilayout/utils.rb
136
138
  - lib/areilayout/version.rb
137
139
  - spec/areilayout_get_spec.rb
138
140
  - spec/areilayout_spec.rb
@@ -1,7 +0,0 @@
1
- module Areilayout
2
-
3
- class Layout < ActiveRecord::Base
4
- self.table_name = 'cms_layouts'
5
- end
6
-
7
- end