iatelier 0.4.2 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f94966b5b6ce1b3d0b4af8888299efb172adee30e761b22c592835ede26f2c05
4
- data.tar.gz: 6046973762b56a161dd5c90900a0585314e0e9d4eecd8214c3af6d68d254dd55
3
+ metadata.gz: ef11774e93cc025d29decaaedba45986d004be469934d60057f3f063bec3958c
4
+ data.tar.gz: 0f6369bfee5d09084dfb0a49db2c17bd34ef21053ae609fe4a993794bc38853c
5
5
  SHA512:
6
- metadata.gz: ef014861440252ece14e446912eee57018443e6df287b862a26b1353ee6adad3672fcf3f30f5e258db8e7e71b2e93446f91ae23fea2c61c6572d283b3e651034
7
- data.tar.gz: b02d2da7679f89bf8c58d1940d9f12fa094c1e0ed336bbab717c17a8cebcdb735c74c089c4733aaf24b54235144546fc90dab86d7546154924464bf708f5c9f8
6
+ metadata.gz: bb3d0d71d911f5735a11e1f2a281a3f28fea9796d6d538e6c71b0bf0f5b86e22e6643627c7d8864c8cff1695ee3f4a704086ed5c6f2bd9789f86666f34ae9c0f
7
+ data.tar.gz: 1224abfc23f59ebd076f1fa55714ad991d43e9ea385b47f2699174ba9cf04db795c6814c71dcd162484ac5a140b8764bbb53c577b8df4f97659d4911d21cac98
@@ -40,4 +40,5 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency "rspec", "~> 3.9"
41
41
  spec.add_development_dependency "hanami", "~> 1.3"
42
42
  spec.add_runtime_dependency "redcarpet", "~>3.5"
43
+ spec.add_runtime_dependency "mime-types", "~>3.3"
43
44
  end
@@ -4,10 +4,12 @@ module Iatelier
4
4
  module DbConnector
5
5
  def set_database database
6
6
  tmp_config = ActiveRecord::Base.connection_config
7
- tmp_config[:database] = database
8
- ActiveRecord::Base.establish_connection tmp_config
7
+ if !database.nil?
8
+ tmp_config[:database] = database
9
+ ActiveRecord::Base.establish_connection tmp_config
10
+ end
9
11
  end
10
12
  end
11
13
  end
12
14
  end
13
- end
15
+ end
@@ -4,11 +4,46 @@ module Iatelier
4
4
  class Create
5
5
  include Iatelier::Action
6
6
  include Iatelier::Controllers::Books::DbConnector
7
+ expose :book, :book_type, :database, :errors
7
8
  def call(params)
8
- self.set_database params[:database]
9
+ # [optional] setting the database
10
+ @database = params.get(:database)
11
+ self.set_database @database
12
+
13
+ #
9
14
  @book = Object.const_get(params[:book_type].capitalize).new
10
- @book.save
11
- @book.create(params)
15
+ @book.namespace = database
16
+
17
+ # p 'starting everything'
18
+ @book.dimensions.each do |dimension|
19
+ method_name = 'setup_' + dimension
20
+ action = @book.public_send(method_name.to_sym, params)
21
+ p 'what is the status = ' + action.valid?.to_s
22
+ if !action.valid?
23
+ puts 'the error is ' + action.errors.messages.to_s
24
+ @errors = action.errors.messages
25
+ self.status = 422
26
+ return 'caught an error!'
27
+ end
28
+ end
29
+
30
+ @book.save
31
+
32
+ @book.dimensions.each do |dimension|
33
+ action = @book.public_send(dimension.to_sym)
34
+ if !action.save
35
+ @errors = action.errors.messages
36
+ self.status = 422
37
+ return 'caught an error!'
38
+ end
39
+ end
40
+
41
+ @book.sync_keywords params
42
+ @book.sync_individuals params
43
+ @book.sync_content params
44
+ @book.store_attachment params
45
+
46
+ redirect_to '/iatelier/' + @database + '/' + params[:book_type]
12
47
  end
13
48
  end
14
49
  end
@@ -6,10 +6,13 @@ module Iatelier
6
6
  include Iatelier::Controllers::Books::DbConnector
7
7
  expose :book, :database
8
8
  def call(params)
9
- @database = params[:database]
10
- self.set_database database
9
+ # [optional] setting the database
10
+ @database = params.get(:database)
11
+ self.set_database @database
12
+
13
+ #
11
14
  @book = Object.const_get(params[:book_type].capitalize).find(params[:id])
12
- @book.namespace = @database
15
+ @book.namespace = @database
13
16
  end
14
17
  end
15
18
  end
@@ -4,10 +4,17 @@ module Iatelier
4
4
  class Manage
5
5
  include Iatelier::Action
6
6
  include Iatelier::Controllers::Books::DbConnector
7
- expose :books
7
+ expose :books, :uri
8
8
  def call(params)
9
- self.set_database params[:database]
10
- @books = Object.const_get(params[:book_type].capitalize).all
9
+ # [optional] setting the database
10
+ @database = params.get(:database)
11
+ self.set_database @database
12
+
13
+ #
14
+ @books = Object.const_get(params[:book_type].capitalize).includes(:timestamp).all.order("timestamps.publish desc")
15
+
16
+ #
17
+ @uri = '/iatelier/' + @database + '/' + params[:book_type] + '/'
11
18
  end
12
19
  end
13
20
  end
@@ -6,8 +6,10 @@ module Iatelier
6
6
  include Iatelier::Controllers::Books::DbConnector
7
7
  expose :book, :book_type, :database
8
8
  def call(params)
9
- @database = params[:database]
10
- self.set_database database
9
+ # [optional] setting the database
10
+ @database = params.get(:database)
11
+ self.set_database @database
12
+
11
13
  @book_type = params[:book_type].capitalize;
12
14
  @book = Object.const_get(@book_type).new
13
15
  @book.namespace = @database
@@ -15,4 +17,4 @@ module Iatelier
15
17
  end
16
18
  end
17
19
  end
18
- end
20
+ end
@@ -4,12 +4,35 @@ module Iatelier
4
4
  class Update
5
5
  include Iatelier::Action
6
6
  include Iatelier::Controllers::Books::DbConnector
7
+ expose :book, :database, :errors
7
8
  def call(params)
8
- self.set_database params[:database]
9
+ # [optional] setting the database
10
+ @database = params.get(:database)
11
+ self.set_database @database
12
+
13
+ # setting up the book
9
14
  @book = Object.const_get(params[:book_type].capitalize).find(params[:id])
10
- @book.revise(params)
11
- @book.save
12
- self.body = @book.save.to_json
15
+ @book.namespace = @database
16
+
17
+ @book.dimensions.each do |dimension|
18
+ if @book.public_send(dimension.to_sym)
19
+ method_name = 'revise_' + dimension
20
+ else
21
+ method_name = 'setup_' + dimension
22
+ end
23
+ @book.public_send(method_name.to_sym, params)
24
+ end
25
+ @book.dimensions.each do |dimension|
26
+ action = @book.public_send(dimension.to_sym)
27
+ if !action.save
28
+ @errors = action.errors.messages
29
+ self.status = 422
30
+ end
31
+ end
32
+ @book.sync_keywords params
33
+ @book.sync_individuals params
34
+ @book.sync_content params
35
+ @book.store_attachment params
13
36
  end
14
37
  end
15
38
  end
@@ -5,10 +5,6 @@ class Book < ActiveRecord::Base
5
5
  DIMENSIONS = []
6
6
  GROUPINGS = []
7
7
  ROLES = []
8
-
9
- @content_raw = ''
10
-
11
- @namespace = nil
12
8
 
13
9
  has_one :title, as: :titleable, class_name: 'Dimensions::Title'
14
10
  has_one :slug, as: :slugable, class_name: 'Dimensions::Slug'
@@ -22,23 +18,22 @@ class Book < ActiveRecord::Base
22
18
 
23
19
  has_many :peopleables, as: :peopleable, dependent: :destroy
24
20
  has_many :peoples, through: :peopleables
25
-
21
+
26
22
  has_many :bundleables, as: :bundleable, dependent: :destroy
27
23
  has_many :bundles, through: :bundleables
28
-
24
+
29
25
  accepts_nested_attributes_for :title, :slug, :subtitle, :description, :thumbnail, :timestamp
30
26
  validates_associated :slug
31
-
27
+
32
28
  attr_accessor :namespace
33
29
 
34
-
35
30
  def kind
36
31
  self.class.to_s
37
32
  end
38
33
  def uniq
39
34
  self.class.to_s + self.id.to_s
40
35
  end
41
-
36
+
42
37
  def dimensions
43
38
  self.class::DIMENSIONS
44
39
  end
@@ -53,66 +48,24 @@ class Book < ActiveRecord::Base
53
48
  @query = '`peopleables`.`role` = "' + requested_role.to_s + '"'
54
49
  self.peoples.includes(:peopleables).where(@query)
55
50
  end
56
-
51
+
57
52
  def content_raw
58
- puts 'trying to open content'
59
53
  unless self.id.nil?
60
- puts 'id passed'
61
54
  path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s + '/main.md'
62
- puts 'path is set to ' + path
55
+ puts 'triving to retrive the content from the path = ' + path.to_s
63
56
  if File.exists? path
64
- puts 'reading content'
65
- @content = File.open(path).read
57
+ return File.open(path).read
66
58
  else
67
- @content = nil
59
+ return nil
68
60
  end
69
61
  else
70
- @content = nil
62
+ return nil
71
63
  end
72
64
  end
73
-
65
+
74
66
  def content
75
67
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
76
- markdown.render(self.content_raw)
77
- end
78
-
79
- # def initialized
80
- # super()
81
- # puts "content of the dimension: \n"
82
- # puts dimensions.inspect
83
- # dimensions.each do |dimension|
84
- # reference = dimension + able
85
- # hasone dimension.to_sym as: reference.to_sym
86
- # end
87
- # end
88
-
89
- def create params
90
- puts 'these are the stuff were going to add:' + dimensions.to_s
91
- dimensions.each do |dimension|
92
- method_name = 'setup_' + dimension
93
- self.public_send(method_name.to_sym, params)
94
- end
95
- self.save
96
- sync_keywords params
97
- sync_individuals params
98
- sync_content params
99
- end
100
-
101
- def revise params
102
- dimensions.each do |dimension|
103
- if self.public_send(dimension.to_sym)
104
- method_name = 'revise_' + dimension
105
- else
106
- method_name = 'setup_' + dimension
107
- end
108
- self.public_send(method_name.to_sym, params)
109
- end
110
- dimensions.each do |dimension|
111
- self.public_send(dimension.to_sym).save
112
- end
113
- sync_keywords params
114
- sync_individuals params
115
- sync_content params
68
+ return markdown.render(content_raw.to_s.force_encoding(Encoding::UTF_8))
116
69
  end
117
70
 
118
71
  def sync_keywords params
@@ -172,31 +125,38 @@ class Book < ActiveRecord::Base
172
125
  end
173
126
 
174
127
  def setup_title params
175
- self.build_title({value: params[:title]})
128
+ return self.build_title({value: params[:title]})
176
129
  end
177
130
  def revise_title params
178
- self.title.update(value: params[:title])
131
+ return self.title.update(value: params[:title])
179
132
  end
180
-
133
+
181
134
  def setup_subtitle params
182
- self.build_subtitle({value: params[:subtitle]})
135
+ return self.build_subtitle({value: params[:subtitle]})
183
136
  end
184
137
  def revise_subtitle params
185
- self.subtitle.update(value: params[:subtitle])
138
+ return self.subtitle.update(value: params[:subtitle])
186
139
  end
187
140
 
188
141
  def setup_slug params
189
- self.build_slug({value: params[:slug]})
142
+ return self.build_slug({value: params[:slug]})
190
143
  end
191
144
  def revise_slug params
192
- self.slug.update(value: params[:slug])
145
+ return self.slug.update(value: params[:slug])
146
+ end
147
+
148
+ def setup_description params
149
+ self.build_description({value: params[:description]})
193
150
  end
194
-
151
+ def revise_description params
152
+ self.description.update(value: params[:description])
153
+ end
154
+
195
155
  def setup_thumbnail params
196
156
  end
197
157
  def revise_thumbnail params
198
158
  end
199
-
159
+
200
160
  def setup_timestamp params
201
161
  puts 'setting up timestamp'
202
162
  self.build_timestamp({
@@ -219,10 +179,9 @@ class Book < ActiveRecord::Base
219
179
  self.setup_timestamp params
220
180
  end
221
181
  end
222
-
182
+
223
183
  def sync_content params
224
- puts 'we are trying to sync the content = ' + params[:content]
225
- path = Iatelier.configuration.storage_dir + params[:database].to_s + self.class.name.downcase + '/' + self.id.to_s
184
+ path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s
226
185
  Dir.mkdir(path) unless File.exists?(path)
227
186
  File.open(path + '/main.md', 'w+') do |file|
228
187
  file.puts params[:content]
@@ -232,4 +191,18 @@ class Book < ActiveRecord::Base
232
191
  self.save
233
192
  puts self.loc.to_s
234
193
  end
235
- end
194
+
195
+ def store_attachment params
196
+ path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s + '/'
197
+ if !params.get(:file).nil?
198
+ Dir.mkdir(path) unless File.exists?(path)
199
+ File.open(path + params[:file][:filename], 'wb') do |file|
200
+ file.write params[:file][:tempfile].read
201
+ end
202
+ end
203
+ end
204
+ def get_asset params
205
+ path = Iatelier.configuration.storage_dir + @namespace.to_s + self.class.name.downcase + '/' + self.id.to_s + '/'
206
+ return File.open(path + params[:asset], 'r')
207
+ end
208
+ end
@@ -1,4 +1,10 @@
1
1
  .panel-edit
2
+ - if @locals.include?(:errors)
3
+ .form-box
4
+ .os-form-group
5
+ - errors.each do |value, key|
6
+ %p= value
7
+ %p= key
2
8
  .form-box
3
9
  .os-form-group
4
10
  -if book.dimensions.include? 'title'
@@ -16,6 +22,9 @@
16
22
  -if book.dimensions.include? 'description'
17
23
  %label.label Description
18
24
  %input{:class => "form-control pure-input-1", :name => "description", :type => "text", :placeholder => "Description", :value => book.description.try(:value)}
25
+ .os-form-group
26
+ %label.label Attachments
27
+ %input{:type => 'file', :id => 'file', :name => 'file'}
19
28
  .form-box
20
29
  %label Text
21
30
  %br
@@ -31,4 +40,3 @@
31
40
  = render :partial => 'grouping/bundles'
32
41
  .form-box
33
42
  = render :partial => 'dimension/timestamp'
34
-
@@ -1,5 +1,4 @@
1
1
  %div
2
- .todo adding errors here!
3
2
  %form{:class => "atelier-main-form pure-form pure-form-aligned", :action => "/iatelier/#{database}/#{book.class.name.downcase}/#{book.id}", :method => "POST", :enctype => "multipart/form-data"}
4
3
  .form-actions
5
4
  <button type="submit" class="btn btn-default">Edit</button>
@@ -8,5 +8,7 @@
8
8
  - books.each do |book|
9
9
  %tr
10
10
  %td= book.id
11
- %td= book.title.value
11
+ %td
12
+ %a{href: uri + book.id.to_s + '/edit' }
13
+ = book.title.value
12
14
  %td= book.slug.try(:value)
@@ -1,6 +1,5 @@
1
1
  %div
2
- .todo adding errors here!
3
2
  %form{:class => "atelier-main-form pure-form pure-form-aligned", :action => "/iatelier/#{database}/#{book.class.name.downcase}/#{book.id}", :method => "POST", :enctype => "multipart/form-data"}
4
3
  .form-actions
5
4
  <button type="submit" class="btn btn-default">Create</button>
6
- = render :partial => 'engine'
5
+ = render :partial => 'engine'
@@ -1,3 +1,3 @@
1
1
  module Iatelier
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -3,6 +3,7 @@ module Iatelier
3
3
  module Books
4
4
  class Create
5
5
  include Iatelier::View
6
+ template 'books/new'
6
7
  end
7
8
  end
8
9
  end
@@ -3,6 +3,9 @@ module Iatelier
3
3
  module Books
4
4
  class Manage
5
5
  include Iatelier::View
6
+ def uri
7
+ raw locals[:uri]
8
+ end
6
9
  end
7
10
  end
8
11
  end
@@ -3,6 +3,7 @@ module Iatelier
3
3
  module Books
4
4
  class Update
5
5
  include Iatelier::View
6
+ template 'books/edit'
6
7
  end
7
8
  end
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iatelier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captain Husayn Pinguin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-26 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mime-types
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
83
97
  description: iAtelier, a simple, yet powerful CMS engine for Hanami
84
98
  email:
85
99
  - captainhusaynpinguin@galacticvisions.xyz
@@ -141,7 +155,6 @@ files:
141
155
  - lib/iatelier/templates/books/grouping/_peoples.html.haml
142
156
  - lib/iatelier/templates/books/manage.html.haml
143
157
  - lib/iatelier/templates/books/new.html.haml
144
- - lib/iatelier/templates/books/update.html.haml
145
158
  - lib/iatelier/version.rb
146
159
  - lib/iatelier/views/application_layout.rb
147
160
  - lib/iatelier/views/books/create.rb