acms_ruby 0.1.0
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/acms_ruby.gemspec +30 -0
- data/bin/acms +60 -0
- data/lib/acms_ruby.rb +21 -0
- data/lib/acms_ruby/active_record.rb +28 -0
- data/lib/acms_ruby/config.rb +41 -0
- data/lib/acms_ruby/factories.rb +69 -0
- data/lib/acms_ruby/models/blog.rb +30 -0
- data/lib/acms_ruby/models/category.rb +18 -0
- data/lib/acms_ruby/models/column.rb +39 -0
- data/lib/acms_ruby/models/entry.rb +41 -0
- data/lib/acms_ruby/models/field.rb +16 -0
- data/lib/acms_ruby/models/field_group.rb +35 -0
- data/lib/acms_ruby/models/field_select_methods.rb +50 -0
- data/lib/acms_ruby/models/form.rb +10 -0
- data/lib/acms_ruby/models/image.rb +26 -0
- data/lib/acms_ruby/models/image_field.rb +42 -0
- data/lib/acms_ruby/models/user.rb +13 -0
- data/lib/acms_ruby/version.rb +3 -0
- data/spec/database.sample.yml +8 -0
- data/spec/models/blog_spec.rb +53 -0
- data/spec/models/category_spec.rb +10 -0
- data/spec/models/column_spec.rb +25 -0
- data/spec/models/entry_spec.rb +24 -0
- data/spec/schema.sql +725 -0
- data/spec/spec_helper.rb +24 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13f02134a9fbeb82a0aabc5c06db3ac3cecc60aa
|
4
|
+
data.tar.gz: 9aaf1de55dbad942300f1553c3b05fdd112ebbce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cabd7a0d45de46e45e09aaf64d8258befcd0b55467f527cff21ab8258815c9600d532dff02c10f7743363ab6acc195d434c86789b4fce99bebf5398583a0dedc
|
7
|
+
data.tar.gz: 46e68c28d32d28b64d4949f9b69aceb408e9c829aae1bd5ac41e64daa46601bdfee9ac1beba06b815b518b90212f92d64047f89865f04155cb757ba2fdd23515
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 takashi.akagi
|
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,31 @@
|
|
1
|
+
# AcmsRuby
|
2
|
+
|
3
|
+
a-blog cms のデータを ActiveRecord オブジェクトとして操作したい人へ
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'acms_ruby'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install acms_ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
操作したい a-blog cms がインストールされているディレクトリに移動して、以下のコマンドを実行
|
22
|
+
|
23
|
+
$ acms
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/acms_ruby.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acms_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acms_ruby"
|
8
|
+
spec.version = AcmsRuby::VERSION
|
9
|
+
spec.authors = ["Orange System Co.", "akagi takashi"]
|
10
|
+
spec.email = ["nisyu@mac.com"]
|
11
|
+
spec.description = %q{a-blog cms をrubyで操作したい}
|
12
|
+
spec.summary = %q{acms_ruby}
|
13
|
+
spec.homepage = "https://github.com/majosystems/acms_ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.required_ruby_version = '>= 1.9'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_dependency "activerecord"
|
26
|
+
spec.add_dependency "composite_primary_keys"
|
27
|
+
spec.add_dependency "pry"
|
28
|
+
spec.add_dependency "factory_girl"
|
29
|
+
spec.add_dependency "mysql2"
|
30
|
+
end
|
data/bin/acms
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# (c)2013 Orange System Co., akagi takashi
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'acms_ruby'
|
7
|
+
require "pathname"
|
8
|
+
require "pry"
|
9
|
+
|
10
|
+
module AcmsRuby
|
11
|
+
extend self
|
12
|
+
|
13
|
+
def run(*argv)
|
14
|
+
load_config
|
15
|
+
set_database_config
|
16
|
+
start
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
print <<EOS
|
21
|
+
|
22
|
+
acms_ruby ver.#{AcmsRuby::VERSION}
|
23
|
+
|
24
|
+
EOS
|
25
|
+
pry
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def set_database_config
|
30
|
+
settings = {
|
31
|
+
adapter: "mysql2",
|
32
|
+
host: @config.database_host,
|
33
|
+
username: @config.database_user,
|
34
|
+
password: @config.database_password,
|
35
|
+
database: @config.database_name,
|
36
|
+
}
|
37
|
+
if @config.database_port.to_i > 0
|
38
|
+
settings[:port] = @config.database_port.to_i
|
39
|
+
else
|
40
|
+
settings[:socket] = @config.database_port
|
41
|
+
settings[:socket] ||= ENV['ACMS_SOCKET']
|
42
|
+
end
|
43
|
+
ActiveRecord::Base.establish_connection(settings)
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_config
|
47
|
+
config_file = default_config_file
|
48
|
+
unless File.exist? config_file
|
49
|
+
print "Config file '#{config_file}' not found.\n"
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
@config = AcmsRuby::Config.new(open(config_file).read)
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_config_file
|
56
|
+
Pathname.new("config.server.php").expand_path.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
AcmsRuby.run *ARGV
|
data/lib/acms_ruby.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "factory_girl"
|
3
|
+
require "acms_ruby/version"
|
4
|
+
require "acms_ruby/config"
|
5
|
+
require "acms_ruby/active_record"
|
6
|
+
require "acms_ruby/models/field_select_methods"
|
7
|
+
require "acms_ruby/models/field_group"
|
8
|
+
require "acms_ruby/models/image"
|
9
|
+
require "acms_ruby/models/image_field"
|
10
|
+
require "acms_ruby/models/user"
|
11
|
+
require "acms_ruby/models/entry"
|
12
|
+
require "acms_ruby/models/blog"
|
13
|
+
require "acms_ruby/models/category"
|
14
|
+
require "acms_ruby/models/form"
|
15
|
+
require "acms_ruby/models/field"
|
16
|
+
require "acms_ruby/models/column"
|
17
|
+
require "acms_ruby/factories"
|
18
|
+
|
19
|
+
module AcmsRuby
|
20
|
+
# no
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "active_record"
|
3
|
+
require "composite_primary_keys"
|
4
|
+
|
5
|
+
module AcmsRuby
|
6
|
+
class ARBase < ActiveRecord::Base
|
7
|
+
self.abstract_class = true
|
8
|
+
|
9
|
+
def self.create_methods(names, prefix)
|
10
|
+
names.each do |name|
|
11
|
+
define_method(name) do
|
12
|
+
send("#{prefix}_#{name}")
|
13
|
+
end
|
14
|
+
define_method(name+"=") do |v|
|
15
|
+
send("#{prefix}_#{name}=", v)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.next_id
|
21
|
+
self.all.map(&:id).max.to_i + 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def next_id
|
25
|
+
self.class.next_id
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
ActiveRecord::Base.default_timezone = :local
|
3
|
+
ActiveRecord::Base.time_zone_aware_attributes = false
|
4
|
+
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
|
5
|
+
ActiveRecord::Base.table_name_prefix = 'acms_'
|
6
|
+
ActiveRecord::Base.pluralize_table_names = false
|
7
|
+
|
8
|
+
module AcmsRuby
|
9
|
+
class Config
|
10
|
+
def initialize(text)
|
11
|
+
@php_str = text
|
12
|
+
parse
|
13
|
+
end
|
14
|
+
|
15
|
+
def database_host
|
16
|
+
@data[:DB_HOST]
|
17
|
+
end
|
18
|
+
def database_name
|
19
|
+
@data[:DB_NAME]
|
20
|
+
end
|
21
|
+
def database_user
|
22
|
+
@data[:DB_USER]
|
23
|
+
end
|
24
|
+
def database_password
|
25
|
+
@data[:DB_PASS]
|
26
|
+
end
|
27
|
+
def database_port
|
28
|
+
@data[:DB_PORT]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def parse
|
33
|
+
@data = {}
|
34
|
+
@php_str.each_line do |line|
|
35
|
+
if line =~ /define\(.*\'(.+)\'.+\'(.+)\'.*\)/
|
36
|
+
@data[$1.to_sym] = $2
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
FactoryGirl.define do
|
3
|
+
factory :blog, class: AcmsRuby::Blog do
|
4
|
+
blog_id { AcmsRuby::Blog.next_id }
|
5
|
+
blog_code "blog_code"
|
6
|
+
blog_name "blog name"
|
7
|
+
blog_parent 0
|
8
|
+
blog_sort 0
|
9
|
+
blog_left 1
|
10
|
+
blog_right 1
|
11
|
+
blog_domain 'localhost'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
FactoryGirl.define do
|
16
|
+
factory :category, class: AcmsRuby::Category do
|
17
|
+
category_id { AcmsRuby::Category.next_id }
|
18
|
+
category_code "category_code"
|
19
|
+
category_name "category name"
|
20
|
+
category_scope "local"
|
21
|
+
category_parent 0
|
22
|
+
category_sort 1
|
23
|
+
category_left 1
|
24
|
+
category_right 1
|
25
|
+
category_blog_id 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
FactoryGirl.define do
|
30
|
+
factory :column, class: AcmsRuby::Column do
|
31
|
+
column_id { AcmsRuby::Column.next_id }
|
32
|
+
column_sort 1
|
33
|
+
column_align "center"
|
34
|
+
column_type "text"
|
35
|
+
column_attr ""
|
36
|
+
column_group ""
|
37
|
+
column_size ""
|
38
|
+
column_field_1 "hogehoge"
|
39
|
+
column_field_2 ""
|
40
|
+
column_field_3 ""
|
41
|
+
column_field_4 ""
|
42
|
+
column_field_5 ""
|
43
|
+
column_field_6 ""
|
44
|
+
column_field_7 ""
|
45
|
+
column_field_8 ""
|
46
|
+
column_entry_id 1
|
47
|
+
column_blog_id 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
FactoryGirl.define do
|
52
|
+
factory :entry, class: AcmsRuby::Entry do
|
53
|
+
entry_id { AcmsRuby::Entry.next_id }
|
54
|
+
entry_code "entry_code"
|
55
|
+
entry_form_status ""
|
56
|
+
entry_sort 1
|
57
|
+
entry_user_sort 1
|
58
|
+
entry_category_sort 1
|
59
|
+
entry_link ""
|
60
|
+
entry_current_rev_id 0
|
61
|
+
entry_last_update_user_id 0
|
62
|
+
entry_hash ""
|
63
|
+
entry_user_id 1
|
64
|
+
entry_form_id 0
|
65
|
+
entry_blog_id 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module AcmsRuby
|
3
|
+
class Blog < AcmsRuby::ARBase
|
4
|
+
include AcmsRuby::FieldSelectMethods
|
5
|
+
|
6
|
+
scope :closes, -> { where(blog_status: :close) }
|
7
|
+
scope :opens, -> { where(blog_status: :open) }
|
8
|
+
|
9
|
+
belongs_to :parent, class_name: 'Blog', foreign_key: :blog_parent
|
10
|
+
|
11
|
+
has_many :origin_categories, class_name: 'Category', foreign_key: :category_blog_id
|
12
|
+
has_many :entries, class_name: 'Entry', foreign_key: :entry_blog_id
|
13
|
+
has_many :fields, class_name: 'Field', foreign_key: :field_bid
|
14
|
+
has_many :users, class_name: 'User', foreign_key: :user_blog_id
|
15
|
+
has_many :all_blog_fields, class_name: 'Field', foreign_key: :field_blog_id
|
16
|
+
|
17
|
+
create_methods ['code','status','name','domain','generated_datetime'], 'blog'
|
18
|
+
|
19
|
+
def categories
|
20
|
+
return origin_categories unless parent
|
21
|
+
parent.global_categories + origin_categories
|
22
|
+
end
|
23
|
+
|
24
|
+
def global_categories
|
25
|
+
g_cates = origin_categories.where category_scope: :global
|
26
|
+
return g_cates unless parent
|
27
|
+
parent.global_categories + g_cates
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module AcmsRuby
|
3
|
+
class Category < AcmsRuby::ARBase
|
4
|
+
include AcmsRuby::FieldSelectMethods
|
5
|
+
|
6
|
+
scope :closes, -> { where(entry_status: :close) }
|
7
|
+
scope :opens, -> { where(entry_status: :open) }
|
8
|
+
|
9
|
+
belongs_to :parent, class_name: 'Category', foreign_key: :category_parent
|
10
|
+
belongs_to :blog, class_name: 'Blog', foreign_key: :category_blog_id
|
11
|
+
|
12
|
+
has_many :categories, class_name: 'Category', foreign_key: :category_parent
|
13
|
+
has_many :entries, class_name: 'Entry', foreign_key: :entry_category_id
|
14
|
+
has_many :fields, class_name: 'Field', foreign_key: :field_cid
|
15
|
+
|
16
|
+
create_methods ['code','status','name'], 'category'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module AcmsRuby
|
3
|
+
class Column < AcmsRuby::ARBase
|
4
|
+
ACMS_UNIT_TEXT_DELIMITER = ':acms_unit_text_delimiter:'
|
5
|
+
|
6
|
+
include AcmsRuby::FieldSelectMethods
|
7
|
+
|
8
|
+
default_scope -> { order(:column_sort) }
|
9
|
+
scope :texts, -> { where(column_type: :text) }
|
10
|
+
|
11
|
+
belongs_to :entry, class_name: 'Entry', foreign_key: :column_entry_id
|
12
|
+
belongs_to :blog, class_name: 'Blog', foreign_key: :column_blog_id
|
13
|
+
|
14
|
+
create_methods ['sort','align','type','attr','group','size','field_1','field_2','field_3','field_4','field_5','field_6','field_7','field_8'], 'column'
|
15
|
+
|
16
|
+
def text(sel=nil)
|
17
|
+
return nil if type != 'text'
|
18
|
+
sel ||= 0
|
19
|
+
texts[sel]
|
20
|
+
end
|
21
|
+
|
22
|
+
def texts
|
23
|
+
return nil if type != 'text'
|
24
|
+
field_1.split(ACMS_UNIT_TEXT_DELIMITER)
|
25
|
+
end
|
26
|
+
|
27
|
+
def html
|
28
|
+
case type
|
29
|
+
when 'text'
|
30
|
+
"<#{field_2}>#{text}</#{field_2}>"
|
31
|
+
when 'image'
|
32
|
+
"<img src=\"#{field_2}\" />"
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|