struggle 2.4.4 → 2.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/struggle.rb +2 -2
- data/lib/struggle/concerns/model_extend.rb +47 -0
- data/lib/struggle/tfile.rb +42 -10
- metadata +3 -3
- data/lib/struggle/concerns/timestamps_format.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68c73cd94c1c59fa35c654b3a8e34e1eebadc85848c4a824d0bfea84c28f3b4a
|
4
|
+
data.tar.gz: 7c9d858424575dd1a3941fc789be19bdd49ecd771d4b0db23cc2c982626914c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48b6d35fabde53bdecc7be29a4922929faf808207420099b3bbf51c10193847f77daa2f45d6c77adb28abed8ab45feb74545b36a1878158c3533dda834dc1154
|
7
|
+
data.tar.gz: 8ea213b12d513422f7ff181c40d0f7e01b99a709072fbdecb42ce4b476dfc07ec2d33dfd5ae5d25739d2fb88a709ac2e23320eb97eb9499cbf829b81ec332dd0
|
data/lib/struggle.rb
CHANGED
@@ -20,7 +20,7 @@ require 'struggle/concerns/string_extend'
|
|
20
20
|
require 'struggle/concerns/int_extend'
|
21
21
|
require 'struggle/concerns/decimal_extend'
|
22
22
|
require 'struggle/concerns/time_extend'
|
23
|
-
require 'struggle/concerns/
|
23
|
+
require 'struggle/concerns/model_extend'
|
24
24
|
require "struggle/ftp_tool"
|
25
25
|
require "struggle/translate"
|
26
26
|
require "struggle/zip_tool"
|
@@ -28,7 +28,7 @@ require 'struggle/sql'
|
|
28
28
|
require 'struggle/backup'
|
29
29
|
require 'pay/jd_gateway'
|
30
30
|
|
31
|
-
ActiveRecord::Base.send :include, Struggle::
|
31
|
+
ActiveRecord::Base.send :include, Struggle::ModelExtend
|
32
32
|
String.send :include, Struggle::StringExtend
|
33
33
|
Integer.send :include, Struggle::IntExtend
|
34
34
|
Numeric.send :include, Struggle::DecimalExtend
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
module Struggle
|
3
|
+
module ModelExtend
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# created_at updated_at 删除 '+0800'
|
8
|
+
# 删除集合中的created_at和updated_at的'+0800'
|
9
|
+
scope :to_hash, -> do
|
10
|
+
objs = []
|
11
|
+
each do |obj|
|
12
|
+
objs << obj.to_hash
|
13
|
+
end
|
14
|
+
objs
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
obj = self.serializable_hash
|
19
|
+
obj.each do |k, v|
|
20
|
+
if v.class == ActiveSupport::TimeWithZone
|
21
|
+
obj[k] = v.localtime.to_s(:db)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
obj
|
25
|
+
end
|
26
|
+
|
27
|
+
def upload_crop_image(field, image, x, y, w, h)
|
28
|
+
filepath = "uploads/#{self.class.table_name}/#{Time.now.to_date.strftime("%Y%m%d")}"
|
29
|
+
file = Struggle::Tfile.imagecropupload(image, "#{Rails.root}/public/#{filepath}/","jpg|bmp|gif|ico|pcx|jpeg|tif|png", 0, 2000, x, y, w, h)
|
30
|
+
self[field.to_sym] = file[:state] ? "#{filepath}/#{file[:result]}" : ""
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_image(field)
|
34
|
+
unless self[field.to_sym].blank?
|
35
|
+
begin
|
36
|
+
File.delete("#{Rails.root}/public/#{self[field.to_sym]}")
|
37
|
+
rescue
|
38
|
+
puts "#{$!}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/struggle/tfile.rb
CHANGED
@@ -51,22 +51,21 @@ module Struggle
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def Tfile.getname(filestream, filepath)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
filepath+filestream.original_filename
|
54
|
+
file_for = Tfile.file_format(filestream.original_filename)
|
55
|
+
filename = Digest::SHA1.hexdigest(SecureRandom.urlsafe_base64.to_s)<<file_for
|
56
|
+
file = filepath+filename
|
57
|
+
while File.exist?(file) do
|
58
|
+
filename = Digest::SHA1.hexdigest(SecureRandom.urlsafe_base64.to_s)<<file_for
|
59
|
+
file = filepath+filename
|
60
|
+
end
|
61
|
+
filename
|
63
62
|
end
|
64
63
|
|
65
64
|
def Tfile.file_format(filename)
|
66
65
|
/\.[^\.]+$/.match(filename)[0]
|
67
66
|
end
|
68
67
|
|
69
|
-
def Tfile.imageupload(imgfile, filepath="", rule="jpg|jpeg", minsize=0, maxsize=2000, w=0, h=0)
|
68
|
+
def Tfile.imageupload(imgfile, filepath="", rule="jpg|bmp|gif|ico|pcx|jpeg|tif|png", minsize=0, maxsize=2000, w=0, h=0)
|
70
69
|
result = Tfile.rule_validata(imgfile, rule, minsize, maxsize)
|
71
70
|
if result[:state]
|
72
71
|
sname = Tfile.getname(imgfile, filepath)
|
@@ -102,5 +101,38 @@ module Struggle
|
|
102
101
|
newimg = img.resize_to_fill(w, h)
|
103
102
|
newimg.write(imagepath)
|
104
103
|
end
|
104
|
+
|
105
|
+
def Tfile.imagecropupload(imgfile, filepath="", rule="jpg|bmp|gif|ico|pcx|jpeg|tif|png", minsize=0, maxsize=2000, x=0, y=0, w=0, h=0)
|
106
|
+
result = Tfile.rule_validata(imgfile, rule, minsize, maxsize)
|
107
|
+
if result[:state]
|
108
|
+
sname = Tfile.getname(imgfile, filepath)
|
109
|
+
begin
|
110
|
+
unless Dir::exist?(filepath)
|
111
|
+
unless system("mkdir -p #{filepath}")
|
112
|
+
return {state: false, result: "目录创建失败,请于管理员联系"}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
File.open(filepath+sname, "wb") do |f|
|
116
|
+
f.write(imgfile.read)
|
117
|
+
end
|
118
|
+
Tfile.crop(filepath + sname, x, y, w, h)
|
119
|
+
return {state: true, result: sname}
|
120
|
+
rescue
|
121
|
+
return {state: false, result: "写入图片失败:#{$!}"}
|
122
|
+
end
|
123
|
+
else
|
124
|
+
return {state: false, result: result[:message]}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def Tfile.crop(imagepath, x, y, w, h)
|
129
|
+
img = Magick::Image.read(imagepath)[0]
|
130
|
+
if w==0 || h==0
|
131
|
+
w=img.columns
|
132
|
+
h=img.rows
|
133
|
+
end
|
134
|
+
newimg = img.crop(x, y, w, h)
|
135
|
+
newimg.write(imagepath)
|
136
|
+
end
|
105
137
|
end
|
106
138
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: struggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lean
|
@@ -100,9 +100,9 @@ files:
|
|
100
100
|
- lib/struggle/code.rb
|
101
101
|
- lib/struggle/concerns/decimal_extend.rb
|
102
102
|
- lib/struggle/concerns/int_extend.rb
|
103
|
+
- lib/struggle/concerns/model_extend.rb
|
103
104
|
- lib/struggle/concerns/string_extend.rb
|
104
105
|
- lib/struggle/concerns/time_extend.rb
|
105
|
-
- lib/struggle/concerns/timestamps_format.rb
|
106
106
|
- lib/struggle/font/ARIALNBI.TTF
|
107
107
|
- lib/struggle/font/font.ttf
|
108
108
|
- lib/struggle/ftp_tool.rb
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
|
-
rubygems_version: 3.0.
|
141
|
+
rubygems_version: 3.0.3
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: struggle!
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
module Struggle
|
3
|
-
module TimestampsFormat
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
# created_at updated_at 删除 '+0800'
|
8
|
-
# 删除集合中的created_at和updated_at的'+0800'
|
9
|
-
scope :to_hash, -> do
|
10
|
-
objs = []
|
11
|
-
each do |obj|
|
12
|
-
objs << obj.to_hash
|
13
|
-
end
|
14
|
-
objs
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_hash
|
18
|
-
obj = self.serializable_hash
|
19
|
-
obj.each do |k, v|
|
20
|
-
if v.class == ActiveSupport::TimeWithZone
|
21
|
-
obj[k] = v.localtime.to_s(:db)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
obj
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module ClassMethods
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|