areilayout 0.0.1

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: 8f032df62ef0b4fd5cc4b2fb354a8c7552d3456c
4
+ data.tar.gz: 5574044b6dafb535af5ba18443c34be937a3cf2f
5
+ SHA512:
6
+ metadata.gz: 5e4bd386cb7cb6b5d1aac77922f8c11222aca220b6d8b5ebf0cf3b6244457522e200dab22bbf4f88168f4e282d19a64ad0619257d7e1b8737e8c715476136b09
7
+ data.tar.gz: 5a270ffe11f217011d65273205580064eb13f0d98151d4555c721b754822ffdc0dc2285d956064fc3f8c5fb7c0abac8b5858f8af8275c1fa27854cc7688bf638
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in areilayout.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Areilayout
2
+
3
+ [ZOMEKI](http://arei.jp/)の標準レイアウトを設定します.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'areilayout'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install areilayout
18
+
19
+ ## Usage
20
+
21
+ #### 1.Change directory
22
+
23
+ $ cd RAILS_ROOT
24
+
25
+ #### 2.Type code below
26
+
27
+ $ areilayout set -n LAYOUT_NAME -p SOURCE_PATH
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/areilayout/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'areilayout/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "areilayout"
8
+ spec.version = Areilayout::VERSION
9
+ spec.authors = ["cobachie"]
10
+ spec.email = ["chie.kobayashi@avasys.jp"]
11
+ spec.summary = %q{Write a short summary. Required.}
12
+ spec.description = %q{Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'thor', '~> 0.18', '>= 0.18.1'
22
+ spec.add_runtime_dependency 'activerecord'
23
+ spec.add_runtime_dependency 'mysql2'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
data/bin/areilayout ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "areilayout"
4
+ require "optparse"
5
+
6
+ params = {}
7
+ OptionParser.new { |opt|
8
+ opt.on('-p path') {|v| params[:path] = v }
9
+ opt.on('-n name') {|v| params[:name] = v }
10
+ }.parse!(ARGV)
11
+
12
+ Areilayout::Config.start([:set, params[:path], params[:name]])
@@ -0,0 +1,3 @@
1
+ module Areilayout
2
+ VERSION = "0.0.1"
3
+ end
data/lib/areilayout.rb ADDED
@@ -0,0 +1,123 @@
1
+ require "areilayout/version"
2
+ require "thor"
3
+ require "rubygems"
4
+ require "active_record"
5
+ require "optparse"
6
+
7
+ module Areilayout
8
+
9
+ class Config < Thor
10
+ default_command :set
11
+
12
+ desc "", ""
13
+ def set(source_path, layout_name)
14
+ begin
15
+ raise "Option is missing." if source_path.blank? || layout_name.blank?
16
+
17
+ 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}"
23
+
24
+ establish_database
25
+
26
+ copy
27
+
28
+ setup
29
+
30
+ rescue => e
31
+ p_error(e.message)
32
+ end
33
+ end
34
+
35
+ private
36
+ def copy
37
+
38
+ FileUtils.mkdir_p(@dest_path) and p_info("mkdir #{@dest_path}") unless Dir.exist?(@dest_path)
39
+
40
+ FileUtils.copy_entry(@source_path, @dest_path, {:verbose => true})
41
+
42
+ end
43
+
44
+ def setup
45
+
46
+ raise "[index.html] is not exist." unless File.exist?("#{@dest_path}/index.html")
47
+
48
+ contents = Pathname("#{@dest_path}/index.html").read(:encoding => Encoding::UTF_8)
49
+ /<head>((\n|.)*)<\/head>/ =~ contents
50
+ head = $1
51
+ /<body.*>((\n|.)*)<\/body>/ =~ contents
52
+ body = $1
53
+
54
+ dir_list = []
55
+ Dir.glob("#{@dest_path}/*").each do |filename|
56
+ dir_list << filename.split("/").last if File.directory?(filename)
57
+ end
58
+
59
+ dir_list.each do |dirname|
60
+ head.gsub!("=\"#{dirname}/", "=\"_themes/#{@layout_name}/#{dirname}/")
61
+ body.gsub!("=\"#{dirname}/", "=\"_themes/#{@layout_name}/#{dirname}/")
62
+ end
63
+
64
+ create_layout(head, body)
65
+
66
+ update_node
67
+
68
+ true
69
+ end
70
+
71
+ def create_layout(head, body)
72
+ @layout = Layout.new
73
+ @layout.concept_id = 1
74
+ @layout.site_id = 1
75
+ @layout.state = "public"
76
+ @layout.name = @layout_name
77
+ @layout.title = @layout_name
78
+ @layout.head = head
79
+ @layout.body = body
80
+ # @layout.in_creator = {'group_id' => 2, 'user_id' => 1}
81
+ @layout.save!
82
+ end
83
+
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
97
+ end
98
+
99
+ def p_error(msg)
100
+ puts "ERROR: #{msg}"
101
+ false and return
102
+ end
103
+
104
+ def p_info(msg)
105
+ puts "INFO: #{msg}"
106
+ end
107
+
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
+ 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
123
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Areilayout do
4
+
5
+ before do
6
+ @src_path = "/var/share/html/bootstrap-3.1.1-dist"
7
+ @layout_name = "bootstrap"
8
+ @dest_dir = "/var/share/arei/sites/00/00/00/01/00000001/public/_themes"
9
+ Dir.chdir("/var/share/arei")
10
+ end
11
+
12
+ it 'has a version number' do
13
+ expect(Areilayout::VERSION).not_to be nil
14
+ end
15
+
16
+ #it 'has error if invalid optoion' do
17
+ # #@ret = Areilayout::Config.new.set({a: "#{@src_path}", b: "#{@layout_name}"})
18
+ # @ret = Areilayout::Config.new.set(@src_path, @layout_name)
19
+ # expect(@ret).to eq false
20
+ #end
21
+
22
+ it 'has error if option is misshing' do
23
+ #@ret = Areilayout::Config.new.set({a: nil, b: nil})
24
+ @ret = Areilayout::Config.new.set(nil, nil)
25
+ expect(@ret).to eq false
26
+ end
27
+
28
+ it 'has error if source directory is not exist' do
29
+ #@ret = Areilayout::Config.new.set({p: "/var/share/html/test", n: "#{@layout_name}"})
30
+ @ret = Areilayout::Config.new.set("/var/share/html/test", @layout_name)
31
+ expect(@ret).to eq false
32
+ end
33
+
34
+ it 'has error if current directory is not RAILS_ROOT' do
35
+ Dir.chdir("/var/share/arei/tmp")
36
+ #@ret = Areilayout::Config.new.set({p: "#{@src_path}", n: "#{@layout_name}"})
37
+ @ret = Areilayout::Config.new.set(@src_path, @layout_name)
38
+ expect(@ret).to eq false
39
+ end
40
+
41
+ it 'has error if index.html is not exist under destination path' do
42
+ #@ret = Areilayout::Config.new.set({p: "/var/share/html/vintage/", n: "#{@layout_name}"})
43
+ dest_path = "#{@dest_dir}/#{@layout_name}"
44
+ FileUtils.remove_dir(dest_path) if Dir.exist?(dest_path)
45
+ @ret = Areilayout::Config.new.set("/var/share/html/vintage/", @layout_name)
46
+ expect(@ret).to eq false
47
+ end
48
+
49
+ it 'is successfully setup layout' do
50
+ #@ret = Areilayout::Config.new.set({p: "#{@src_path}", n: "#{@layout_name}"})
51
+ @ret = Areilayout::Config.new.set(@src_path, @layout_name)
52
+ expect(@ret).to eq true
53
+ end
54
+
55
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'areilayout'