ezframe 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/asset/html/index.html +1 -0
- data/asset/js/ezframe.js +49 -20
- data/exe/check_column_yml +64 -0
- data/exe/create_table +7 -4
- data/exe/dbmigrate +65 -14
- data/ezframe.gemspec +10 -11
- data/lib/ezframe.rb +2 -1
- data/lib/ezframe/auth.rb +33 -28
- data/lib/ezframe/column_set.rb +261 -97
- data/lib/ezframe/column_type.rb +207 -63
- data/lib/ezframe/config.rb +20 -3
- data/lib/ezframe/controller.rb +19 -16
- data/lib/ezframe/database.rb +162 -50
- data/lib/ezframe/editor.rb +7 -7
- data/lib/ezframe/ht.rb +21 -16
- data/lib/ezframe/html.rb +20 -19
- data/lib/ezframe/japanese_utils.rb +10 -0
- data/lib/ezframe/jquery-ui.rb +29 -0
- data/lib/ezframe/loader.rb +4 -4
- data/lib/ezframe/logger.rb +39 -0
- data/lib/ezframe/materialize.rb +5 -8
- data/lib/ezframe/message.rb +1 -1
- data/lib/ezframe/page_base.rb +27 -18
- data/lib/ezframe/route.rb +26 -28
- data/lib/ezframe/template.rb +2 -2
- data/lib/ezframe/util.rb +4 -6
- data/lib/ezframe/version.rb +1 -1
- metadata +32 -44
- data/asset/js/materialize.min.js +0 -6
- data/asset/js/mymaterialize.js +0 -38
- data/lib/ezframe/model.rb +0 -52
data/lib/ezframe/html.rb
CHANGED
@@ -12,22 +12,29 @@ module Ezframe
|
|
12
12
|
|
13
13
|
tag = ht_h[:tag]
|
14
14
|
case tag
|
15
|
-
when "
|
16
|
-
|
15
|
+
when "textarea"
|
16
|
+
textarea(ht_h)
|
17
17
|
when "select"
|
18
18
|
return select(ht_h) if ht_h[:item]
|
19
19
|
when "icon"
|
20
20
|
tag = "i"
|
21
21
|
end
|
22
22
|
tag = ht_h[:tag]
|
23
|
-
|
24
|
-
if
|
25
|
-
|
23
|
+
error_box = ""
|
24
|
+
if %w[input select textarea].include?(tag)
|
25
|
+
error_box = "<div id=\"error-box-#{ht_h[:name]}\" class=\"error-box hide\"></div>"
|
26
26
|
end
|
27
|
-
|
27
|
+
opt_s, child_s = join_attribute(ht_h)
|
28
|
+
if !child_s.strip.empty? || !%w[img input hr br meta].include?(tag)
|
29
|
+
start_tag = [ht_h[:tag], opt_s].compact.join(" ").strip
|
30
|
+
return "<#{start_tag}>#{child_s}</#{ht_h[:tag]}>"+error_box
|
31
|
+
end
|
32
|
+
tag_content = [ ht_h[:tag], opt_s ].compact.join(" ")
|
33
|
+
return "<#{tag_content}/>"+error_box
|
28
34
|
end
|
29
35
|
|
30
|
-
|
36
|
+
# attributeの連結文字列化
|
37
|
+
def join_attribute(attrs)
|
31
38
|
child_s = ""
|
32
39
|
opt_a = attrs.map do |k, v|
|
33
40
|
case k
|
@@ -52,16 +59,10 @@ module Ezframe
|
|
52
59
|
[opt_a.compact.join(" "), child_s]
|
53
60
|
end
|
54
61
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if /(\d+)\s*[x\*]\s*(\d+)/ =~ size
|
60
|
-
ht_h[:cols], ht_h[:rows] = $1, $2
|
61
|
-
ht_h.delete(:size)
|
62
|
-
end
|
63
|
-
ht_h[:tag] = "textarea"
|
64
|
-
ht_h[:child] = ht_h[:value]
|
62
|
+
def textarea(ht_h)
|
63
|
+
value = ht_h[:value]
|
64
|
+
if value
|
65
|
+
ht_h[:child] = value
|
65
66
|
ht_h.delete(:value)
|
66
67
|
end
|
67
68
|
end
|
@@ -78,7 +79,7 @@ module Ezframe
|
|
78
79
|
h[:selected] = "selected" if selected
|
79
80
|
end
|
80
81
|
h[:child] = v
|
81
|
-
#
|
82
|
+
# Logger.info "select: hash: k=#{k}, v=#{v}, value=#{ht_h[:value]}"
|
82
83
|
if ht_h[:value] && ht_h[:value].to_s == k.to_s
|
83
84
|
h[:selected] = "selected"
|
84
85
|
end
|
@@ -90,7 +91,7 @@ module Ezframe
|
|
90
91
|
if %w[selected default].include?(v[2])
|
91
92
|
h[:selected] = "selected"
|
92
93
|
end
|
93
|
-
#
|
94
|
+
# Logger.info "select: array: v=#{v}, value=#{ht_h[:value]}"
|
94
95
|
if ht_h[:value] && ht_h[:value].to_s == v[0].to_s
|
95
96
|
h[:selected] = "selected"
|
96
97
|
end
|
@@ -41,5 +41,15 @@ class Japanese
|
|
41
41
|
return nil unless wday
|
42
42
|
return %w(日 月 火 水 木 金 土)[wday]
|
43
43
|
end
|
44
|
+
|
45
|
+
def to_datetime_str(tm)
|
46
|
+
return nil unless tm
|
47
|
+
return "%d年%2d月%2d日 %2d:%02d:%02d" %[ tm.year, tm.mon, tm.mday, tm.hour, tm.min, tm.sec ]
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_date_str(tm)
|
51
|
+
return nil unless tm
|
52
|
+
return "%d年%2d月%2d日" %[ tm.year, tm.mon, tm.mday]
|
53
|
+
end
|
44
54
|
end
|
45
55
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ezframe
|
2
|
+
class Jquery
|
3
|
+
class << self
|
4
|
+
def into_html_header
|
5
|
+
css_a = Config[:extra_css_list].map {|file| "<link href=\"#{file}\" rel=\"stylesheet\">\n" }
|
6
|
+
js_a = Config[:extra_js_list].map {|file| "<script src=\"#{file}\"></script>\n" }
|
7
|
+
|
8
|
+
css_files = Dir["./asset/css/*.css"]||[]
|
9
|
+
css_a += css_files.map do |file|
|
10
|
+
file.gsub!("./asset", "")
|
11
|
+
"<link href=\"#{file}\" rel=\"stylesheet\">\n"
|
12
|
+
end
|
13
|
+
js_files = Dir["./asset/js/*.js"]||[]
|
14
|
+
js_a += js_files.map do |file|
|
15
|
+
file.gsub!("./asset", "")
|
16
|
+
"<script src=\"#{file}\"></script>\n"
|
17
|
+
end
|
18
|
+
(css_a+js_a).join
|
19
|
+
end
|
20
|
+
|
21
|
+
def into_bottom_of_body
|
22
|
+
""
|
23
|
+
end
|
24
|
+
|
25
|
+
def convert(ht_h)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/ezframe/loader.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if File.exist?("
|
4
|
-
require "#{Dir.pwd}/
|
3
|
+
if File.exist?("page/common.rb")
|
4
|
+
require "#{Dir.pwd}/page/common.rb"
|
5
5
|
end
|
6
|
-
Dir["
|
6
|
+
Dir["model/*.rb"].sort.each do |file|
|
7
7
|
require "#{Dir.pwd}/#{file}"
|
8
8
|
end
|
9
|
-
Dir["
|
9
|
+
Dir["page/*.rb"].sort.each do |file|
|
10
10
|
require "#{Dir.pwd}/#{file}"
|
11
11
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Ezframe
|
2
|
+
class Logger
|
3
|
+
class << self
|
4
|
+
@instance = nil
|
5
|
+
|
6
|
+
def writer(level="", msg)
|
7
|
+
unless @instance
|
8
|
+
@instance = File.open("log/#{ENV['RACK_ENV']||'development'}.log", "a+")
|
9
|
+
@instance.sync = true
|
10
|
+
end
|
11
|
+
@instance.puts "#{Time.now.to_s}:#{level.upcase}:#{msg}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def level=(lv)
|
15
|
+
@level = lv
|
16
|
+
end
|
17
|
+
|
18
|
+
def info(msg)
|
19
|
+
writer("info", msg)
|
20
|
+
end
|
21
|
+
|
22
|
+
def debug(msg)
|
23
|
+
writer("debug", msg)
|
24
|
+
end
|
25
|
+
|
26
|
+
def warn(msg)
|
27
|
+
writer("warn", msg)
|
28
|
+
end
|
29
|
+
|
30
|
+
def error(msg)
|
31
|
+
writer("debug", msg)
|
32
|
+
end
|
33
|
+
|
34
|
+
def <<(msg)
|
35
|
+
writer("", msg)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ezframe/materialize.rb
CHANGED
@@ -8,12 +8,12 @@ module Ezframe
|
|
8
8
|
js_a = Config[:extra_js_list].map {|file| "<script src=\"#{file}\"></script>\n" }
|
9
9
|
|
10
10
|
css_files = Dir["./asset/css/*.css"]||[]
|
11
|
-
css_a += css_files.map do |file|
|
11
|
+
css_a += css_files.sort.map do |file|
|
12
12
|
file.gsub!("./asset", "")
|
13
13
|
"<link href=\"#{file}\" rel=\"stylesheet\">\n"
|
14
14
|
end
|
15
15
|
js_files = Dir["./asset/js/*.js"]||[]
|
16
|
-
js_a += js_files.map do |file|
|
16
|
+
js_a += js_files.sort.map do |file|
|
17
17
|
file.gsub!("./asset", "")
|
18
18
|
"<script src=\"#{file}\"></script>\n"
|
19
19
|
end
|
@@ -32,13 +32,10 @@ module Ezframe
|
|
32
32
|
new_h = ht_h.map { |v| convert(v) }
|
33
33
|
elsif ht_h.is_a?(Hash)
|
34
34
|
unless ht_h[:tag]
|
35
|
-
|
35
|
+
Logger.info("convert: no tag: #{ht_h.inspect}")
|
36
36
|
return nil
|
37
37
|
end
|
38
38
|
case ht_h[:tag].to_sym
|
39
|
-
# when :input, :select
|
40
|
-
# new_h = input(ht_h) if "hidden" != ht_h[:type]
|
41
|
-
# return new_h
|
42
39
|
when :checkbox
|
43
40
|
return checkbox(ht_h)
|
44
41
|
when :radio
|
@@ -57,8 +54,8 @@ module Ezframe
|
|
57
54
|
|
58
55
|
def icon(ht_h)
|
59
56
|
new_h = ht_h.clone
|
60
|
-
|
61
|
-
new_h.add_class(
|
57
|
+
Logger.info "[warn] no name attribute for icon ht_h: #{ht_h.inspect}" unless new_h[:name]
|
58
|
+
new_h.add_class(%w[material-icons align-icon])
|
62
59
|
new_h.update({ tag: "i", child: ht_h[:name] })
|
63
60
|
new_h.delete(:name)
|
64
61
|
return new_h
|
data/lib/ezframe/message.rb
CHANGED
data/lib/ezframe/page_base.rb
CHANGED
@@ -6,7 +6,11 @@ require_relative "util"
|
|
6
6
|
|
7
7
|
module Ezframe
|
8
8
|
class PageBase
|
9
|
-
|
9
|
+
# class << self
|
10
|
+
# attr_accessor :auth
|
11
|
+
# end
|
12
|
+
|
13
|
+
attr_accessor :request
|
10
14
|
|
11
15
|
def initialize(request = nil)
|
12
16
|
@class_snake = class_to_snake(self.class)
|
@@ -21,20 +25,16 @@ module Ezframe
|
|
21
25
|
# Rackのrequestを代入し、関連するインスタンス変数を定義
|
22
26
|
def set_request(request)
|
23
27
|
@request = request
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
# mylog "[WARN] column_set is not defined: #{@class_snake}" unless @column_set
|
28
|
-
if @column_set
|
29
|
-
@dataset = @column_set.dataset
|
30
|
-
end
|
28
|
+
@column_set = ColumnSets.get(@class_snake)
|
29
|
+
@dataset = DB.dataset(@class_snake)
|
30
|
+
Logger.debug "column_set is not defined: #{@class_snake}" unless @column_set
|
31
31
|
@params = parse_query_string(request.env["QUERY_STRING"])
|
32
32
|
@params.update(request.params)
|
33
|
-
|
33
|
+
# Logger.info "set_request: params=#{@params.inspect}" if @params.length > 0
|
34
34
|
# @id, @key = @params[:id], @params[:key]
|
35
35
|
@env = @request.env
|
36
36
|
@session = @env["rack.session"]
|
37
|
-
|
37
|
+
|
38
38
|
if %w[POST PUT].include?(request.request_method)
|
39
39
|
body = @request.body.read
|
40
40
|
if request.content_type.index("json")
|
@@ -42,25 +42,30 @@ module Ezframe
|
|
42
42
|
else
|
43
43
|
@parsed_body = parse_query_string(body)
|
44
44
|
end
|
45
|
-
#
|
45
|
+
# Logger.info "parsed_body=#{@parsed_body.inspect}"
|
46
46
|
@event = @parsed_body[:event] || {}
|
47
|
+
@form = @event[:form]
|
48
|
+
|
49
|
+
# Logger.info "event=#{@event}"
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
53
|
# routeから基本URLを生成
|
51
54
|
def make_base_url(id = nil)
|
52
55
|
path = Route::get_path(@class_snake)
|
53
|
-
params = @request.env["url_params"]
|
56
|
+
params = @request.env["url_params"] || {}
|
57
|
+
# Logger.info "make_base_url: params=#{params}"
|
54
58
|
# params[@class_snake.to_sym] = id
|
55
59
|
path_s = path.map do |pa|
|
56
60
|
if pa == @class_snake.to_sym && id
|
57
61
|
"#{pa}/#{id}"
|
58
|
-
elsif params[
|
59
|
-
"#{pa}/#{params[
|
62
|
+
elsif params[pa.to_sym]
|
63
|
+
"#{pa}/#{params[pa.to_sym]}"
|
60
64
|
else
|
61
65
|
pa
|
62
66
|
end
|
63
67
|
end.join("/")
|
68
|
+
# Logger.info "path_s=#{path_s}"
|
64
69
|
return "/#{path_s}"
|
65
70
|
end
|
66
71
|
|
@@ -71,7 +76,7 @@ module Ezframe
|
|
71
76
|
into_html_header: Materialize.into_html_header,
|
72
77
|
into_bottom_of_body: Materialize.into_bottom_of_body,
|
73
78
|
}
|
74
|
-
Template.
|
79
|
+
Template.fill_from_file("template/base.html", args)
|
75
80
|
end
|
76
81
|
|
77
82
|
def parse_json_body(body)
|
@@ -79,15 +84,19 @@ module Ezframe
|
|
79
84
|
begin
|
80
85
|
json = JSON.parse(body)
|
81
86
|
rescue => e
|
82
|
-
|
87
|
+
Logger.info "ERROR: #{e.class}:#{e.message}\n#{e.backtrace}"
|
83
88
|
return nil
|
84
89
|
end
|
85
90
|
json = json.recursively_symbolize_keys if json.is_a?(Hash) || json.is_a?(Array)
|
86
91
|
return json
|
87
92
|
end
|
88
93
|
|
94
|
+
def session
|
95
|
+
return @request.env['rack.session']
|
96
|
+
end
|
97
|
+
|
89
98
|
def warden
|
90
|
-
@request.env["warden"]
|
99
|
+
return @request.env["warden"]
|
91
100
|
end
|
92
101
|
|
93
102
|
def login?
|
@@ -95,7 +104,7 @@ module Ezframe
|
|
95
104
|
end
|
96
105
|
|
97
106
|
def user
|
98
|
-
warden.user
|
107
|
+
return warden.user
|
99
108
|
end
|
100
109
|
end
|
101
110
|
end
|
data/lib/ezframe/route.rb
CHANGED
@@ -6,6 +6,7 @@ module Ezframe
|
|
6
6
|
route_h ||= Config[:route].deep_dup
|
7
7
|
# puts "config=#{Config[:route]}, route_h=#{route_h}"
|
8
8
|
args = {}
|
9
|
+
opts = {}
|
9
10
|
class_a = []
|
10
11
|
# p path_parts
|
11
12
|
if path_parts.empty?
|
@@ -21,28 +22,34 @@ module Ezframe
|
|
21
22
|
while path_parts.length > 0
|
22
23
|
part = path_parts.shift
|
23
24
|
# break if part.empty?
|
24
|
-
#
|
25
|
+
# Logger.info "part=#{part}, route_h=#{route_h.inspect}"
|
25
26
|
if route_h.has_key?(part.to_sym)
|
26
|
-
#
|
27
|
+
# Logger.info "has_route: #{part}"
|
27
28
|
class_a.push(part)
|
28
29
|
if path_parts[0].to_i > 0
|
29
30
|
args[part.to_sym] = val = path_parts.shift
|
30
|
-
#
|
31
|
+
# Logger.info "value: part=#{part}, val=#{val}"
|
31
32
|
end
|
32
33
|
route_h = route_h[part.to_sym]
|
33
34
|
break if route_h.nil?
|
34
|
-
|
35
|
+
opts = {}
|
36
|
+
route_h.keys.compact.each do |rkey|
|
37
|
+
if rkey =~ /option_(\w+)/
|
38
|
+
opt_key = $1
|
39
|
+
opts[opt_key.to_sym] = route_h[rkey]
|
40
|
+
end
|
41
|
+
end
|
35
42
|
else
|
36
43
|
# routeに無ければ、メソッドを探す
|
37
|
-
#
|
44
|
+
# Logger.info "no_route: #{part}"
|
38
45
|
klass = get_class(class_a[-1])
|
39
46
|
return [ 404 ] unless klass
|
40
47
|
instance = klass.new
|
41
48
|
method_name = make_method_name(part, request.request_method)
|
42
49
|
if instance.respond_to?(method_name)
|
43
|
-
return [instance, method_name, args]
|
50
|
+
return [instance, method_name, args, opts]
|
44
51
|
else
|
45
|
-
|
52
|
+
Logger.info "undefined method: #{klass}.#{method_name}: full path=#{request.path_info}"
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
@@ -56,10 +63,10 @@ module Ezframe
|
|
56
63
|
part = "default"
|
57
64
|
end
|
58
65
|
method_name = make_method_name(part, request.request_method)
|
59
|
-
#
|
66
|
+
#Logger.info "method_name=#{method_name}"
|
60
67
|
instance = klass.new
|
61
68
|
if instance.respond_to?(method_name)
|
62
|
-
return [instance, method_name, args]
|
69
|
+
return [instance, method_name, args, opts]
|
63
70
|
end
|
64
71
|
return [ 404 ]
|
65
72
|
end
|
@@ -67,21 +74,23 @@ module Ezframe
|
|
67
74
|
# ページクラスの階層を辿る
|
68
75
|
def get_path(class_snake, route_h = nil)
|
69
76
|
route_h = Config[:route] unless route_h
|
77
|
+
# Logger.info "get_path: route_h=#{route_h}"
|
70
78
|
@get_path_found_it = nil
|
71
|
-
|
79
|
+
route =_scan_route(class_snake, route_h.deep_dup)
|
80
|
+
return route.reverse if route
|
81
|
+
return nil
|
72
82
|
end
|
73
83
|
|
74
84
|
# targetに対応する名称のクラスまでの経路を返す
|
75
|
-
def
|
76
|
-
# puts "scan_route: target=#{target}, route_h=#{route_h}"
|
85
|
+
def _scan_route(target, route_h)
|
77
86
|
if route_h.keys.include?(target.to_sym)
|
78
87
|
@get_path_found_it = true
|
79
88
|
return [ target ]
|
80
89
|
else
|
81
90
|
route_h.each do |k, v|
|
82
|
-
next if k
|
91
|
+
next if k.to_s =~ /^option_/
|
83
92
|
if v.is_a?(Hash)
|
84
|
-
a =
|
93
|
+
a = _scan_route(target, v)
|
85
94
|
if @get_path_found_it
|
86
95
|
a.push(k)
|
87
96
|
return a
|
@@ -97,11 +106,11 @@ module Ezframe
|
|
97
106
|
end
|
98
107
|
|
99
108
|
def get_class(keys)
|
100
|
-
|
109
|
+
# Logger.info "get_class: #{keys.inspect}"
|
101
110
|
return nil unless keys
|
102
111
|
keys = [ keys ] if keys.is_a?(String)
|
103
|
-
klass = (%w[Ezframe] + keys.map { |k| k.to_camel }).join("::")
|
104
|
-
#
|
112
|
+
klass = (%w[Ezframe] + keys.map { |k| k.to_s.to_camel }).join("::")
|
113
|
+
# Logger.info "get_class: #{klass}"
|
105
114
|
if Object.const_defined?(klass)
|
106
115
|
return Object.const_get(klass)
|
107
116
|
else
|
@@ -109,17 +118,6 @@ module Ezframe
|
|
109
118
|
end
|
110
119
|
return nil
|
111
120
|
end
|
112
|
-
|
113
|
-
def find_file(target)
|
114
|
-
Find.find("./asset").each do |file|
|
115
|
-
path_a = file.split("/")
|
116
|
-
if path_a[-1] == target
|
117
|
-
suffix = "." + target.split(".")[-1]
|
118
|
-
return [200, { "Content-Type" => Rack::Mime.mime_type(suffix) }, [File.open(file, &:read)]]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
return [ 404 ]
|
122
|
-
end
|
123
121
|
end
|
124
122
|
end
|
125
123
|
end
|