lalala 4.0.0.dev.94 → 4.0.0.dev.107

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/lalala/modules/grid.module.js +146 -13
  3. data/app/assets/stylesheets/lalala/base/_variables.css.scss +1 -0
  4. data/app/assets/stylesheets/lalala/components/_buttons.css.scss +3 -3
  5. data/app/assets/stylesheets/lalala/components/_forms.css.scss +27 -2
  6. data/app/assets/stylesheets/lalala/lib/_jquery-ui.css.scss +14 -629
  7. data/app/assets/stylesheets/lalala/modules/_footer.css.scss +1 -0
  8. data/app/assets/stylesheets/lalala/modules/_grid.css.scss +96 -1
  9. data/app/models/lalala/abstract_asset.rb +20 -0
  10. data/app/models/lalala/file_asset.rb +3 -0
  11. data/app/models/lalala/image_asset.rb +3 -0
  12. data/lalala-assets.gemspec +1 -1
  13. data/lib/formtastic/inputs/grid_input.rb +29 -4
  14. data/lib/formtastic/inputs/single_file_input.rb +34 -0
  15. data/lib/generators/lalala/install/install_generator.rb +12 -0
  16. data/lib/generators/lalala/install/templates/migrations/4_create_assets.rb +23 -0
  17. data/lib/generators/lalala/install/templates/models/file_asset.rb +2 -0
  18. data/lib/generators/lalala/install/templates/models/image_asset.rb +2 -0
  19. data/lib/generators/lalala/install/templates/uploaders/file_uploader.rb +2 -0
  20. data/lib/generators/lalala/install/templates/uploaders/image_uploader.rb +11 -0
  21. data/lib/lalala/engine.rb +7 -0
  22. data/lib/lalala/ext_active_record/assets.rb +25 -0
  23. data/lib/lalala/ext_active_record.rb +1 -0
  24. data/lib/lalala/ext_rack/multiple_file_upload_support.rb +46 -0
  25. data/lib/lalala/ext_rack.rb +1 -0
  26. data/lib/lalala/uploaders/file.rb +19 -0
  27. data/lib/lalala/uploaders/image.rb +5 -17
  28. data/lib/lalala/uploaders.rb +1 -0
  29. data/lib/lalala/utils/{intall_template.rb → install_template.rb} +0 -0
  30. data/lib/lalala/version.rb +1 -1
  31. data/lib/lalala.rb +1 -0
  32. data/lib/tasks/lalala_tasks.rake +12 -4
  33. data/test/dummy/app/uploaders/file_uploader.rb +2 -0
  34. data/test/dummy/app/uploaders/image_uploader.rb +2 -0
  35. metadata +19 -22
  36. data/app/assets/images/.DS_Store +0 -0
  37. data/app/assets/images/lalala/jquery-ui/animated-overlay.gif +0 -0
  38. data/app/assets/images/lalala/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  39. data/app/assets/images/lalala/jquery-ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  40. data/app/assets/images/lalala/jquery-ui/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  41. data/app/assets/images/lalala/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  42. data/app/assets/images/lalala/jquery-ui/ui-bg_glass_75_dadada_1x400.png +0 -0
  43. data/app/assets/images/lalala/jquery-ui/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  44. data/app/assets/images/lalala/jquery-ui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  45. data/app/assets/images/lalala/jquery-ui/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  46. data/app/assets/images/lalala/jquery-ui/ui-icons_222222_256x240.png +0 -0
  47. data/app/assets/images/lalala/jquery-ui/ui-icons_2e83ff_256x240.png +0 -0
  48. data/app/assets/images/lalala/jquery-ui/ui-icons_454545_256x240.png +0 -0
  49. data/app/assets/images/lalala/jquery-ui/ui-icons_888888_256x240.png +0 -0
  50. data/app/assets/images/lalala/jquery-ui/ui-icons_cd0a0a_256x240.png +0 -0
  51. data/app/assets/images/lalala/users/.DS_Store +0 -0
  52. data/app/assets/javascripts/.DS_Store +0 -0
  53. data/app/assets/stylesheets/.DS_Store +0 -0
  54. data/app/assets/stylesheets/lalala/lib/.DS_Store +0 -0
@@ -6,11 +6,20 @@
6
6
  */
7
7
 
8
8
  .mod-grid {
9
+ border: 1px solid #ddd;
10
+ padding: 18px;
11
+
12
+ @include border-radius(5px);
13
+
9
14
  .images,
10
- .input-fields {
15
+ .actions {
11
16
  overflow: hidden;
12
17
  }
13
18
 
19
+ .images {
20
+ padding-top: 10px - 3px;
21
+ }
22
+
14
23
  // [row]
15
24
  li {
16
25
  float: left;
@@ -53,6 +62,14 @@
53
62
  z-index: 1;
54
63
  }
55
64
 
65
+ // [row].edit-block
66
+ li.edit-block {
67
+ clear: both;
68
+ height: auto;
69
+ min-height: 100px;
70
+ width: 100%;
71
+ }
72
+
56
73
  // label
57
74
  li label {
58
75
  @include border-radius(2px);
@@ -72,4 +89,82 @@
72
89
  z-index: 2;
73
90
  }
74
91
 
92
+ // attributes
93
+ li .attributes { display: none; position: relative }
94
+ li.edit-block .attributes { display: block }
95
+
96
+ li .attributes input,
97
+ li .attributes textarea {
98
+ margin-bottom: 6px;
99
+ margin-left: 115px;
100
+ resize: none;
101
+ width: 300px;
102
+ }
103
+
104
+ li .attributes textarea {
105
+ height: 100px !important;
106
+ }
107
+
108
+ li .attributes .close-button {
109
+ color: #c5c5c5;
110
+ cursor: pointer;
111
+ display: inline-block;
112
+ font-size: 18px;
113
+ padding: 4px 6px;
114
+ position: absolute;
115
+ right: 0;
116
+ top: -4px;
117
+
118
+ &:hover { color: $black }
119
+ }
120
+
121
+ //
122
+ // Actions
123
+ //
124
+ .actions {
125
+ & > div {
126
+ float: left;
127
+ }
128
+
129
+ input[type="file"] {
130
+ display: none;
131
+ }
132
+
133
+ .button {
134
+ background: $button_green;
135
+ color: white;
136
+ cursor: pointer;
137
+ float: left;
138
+ font-size: 10px;
139
+ font-weight: 600;
140
+ margin-bottom: 3px;
141
+ margin-right: 7px;
142
+ padding: 7px 9px 6px;
143
+ text-transform: uppercase;
144
+
145
+ @include border-radius(3px);
146
+ }
147
+
148
+ .button.unavailable {
149
+ background-color: #ddd !important;
150
+ cursor: default;
151
+ }
152
+
153
+ .button[rel="edit"] { background-color: $button_yellow; }
154
+ .button[rel="destroy"] { background-color: $button_red; }
155
+
156
+ .files-description {
157
+ color: #999;
158
+ display: none;
159
+ font-size: 9px;
160
+ height: 23px;
161
+ letter-spacing: 1px;
162
+ line-height: 25px;
163
+ margin-right: 12px;
164
+ overflow: hidden;
165
+ text-transform: uppercase;
166
+ }
167
+ }
168
+
169
+
75
170
  }
@@ -0,0 +1,20 @@
1
+ class Lalala::AbstractAsset < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ self.table_name = "assets"
4
+
5
+ attr_accessible :asset, :title, :caption
6
+ translates :title, :caption
7
+ Lalala::AbstractAsset::Translation.table_name = 'asset_translations'
8
+
9
+ belongs_to :asset_owner, polymorphic: true
10
+
11
+ def self.extension_white_list
12
+ list = if self.uploaders and self.uploaders[:asset]
13
+ self.uploaders[:asset].new.extension_white_list
14
+ end
15
+
16
+ list = list || []
17
+ list.map { |e| ".#{e}" }.join(",")
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ class Lalala::FileAsset < Lalala::AbstractAsset
2
+ mount_uploader :asset, ::FileUploader
3
+ end
@@ -0,0 +1,3 @@
1
+ class Lalala::ImageAsset < Lalala::AbstractAsset
2
+ mount_uploader :asset, ::ImageUploader
3
+ end
@@ -32,7 +32,7 @@ Gem::Specification.new do |gem|
32
32
  gem.add_runtime_dependency 'coffee-script-source', '= 1.4.0'
33
33
  gem.add_runtime_dependency 'compass', '= 0.13.alpha.0'
34
34
  gem.add_runtime_dependency 'compass-rails', '= 1.0.3'
35
- gem.add_runtime_dependency 'sass', '= 3.2.7'
35
+ gem.add_runtime_dependency 'sass', '= 3.2.8'
36
36
  gem.add_runtime_dependency 'sass-rails', '= 3.2.6'
37
37
  gem.add_runtime_dependency 'sprockets-commonjs', '= 0.0.5'
38
38
  gem.add_runtime_dependency 'uglifier', '= 1.3.0'
@@ -5,21 +5,46 @@ class Formtastic::Inputs::GridInput
5
5
  object = builder.object
6
6
  assets = object.send(method)
7
7
 
8
+ image_model_class = object.class.reflect_on_association(method).class_name.constantize
9
+ image_attributes = image_model_class.accessible_attributes.to_a
10
+ image_attributes.select! { |x| x.size > 0 and x != "asset" }
11
+
8
12
  ul = template.content_tag :ul do
9
13
  html = template.raw("")
10
14
 
11
- assets.each do |asset|
15
+ assets.each_with_index do |asset, idx|
12
16
  html += template.content_tag :li do
13
17
  builder.fields_for(method, asset) do |f|
14
- thumbnail_html = template.image_tag f.object.asset.thumb.url
15
- template.link_to thumbnail_html, f.object.asset.url
18
+ thumbnail_html = template.image_tag f.object.asset.lalala_thumb.url
19
+ asset_html = template.raw("")
20
+ asset_html << template.link_to(thumbnail_html, f.object.asset.url)
21
+ asset_html << template.content_tag(:div, { class: "attributes" }) do
22
+ inputs = image_attributes.map do |ia|
23
+ if image_model_class.columns_hash[ia]
24
+ column_type = image_model_class.columns_hash[ia].type
25
+ elsif image_model_class.translation_class.columns_hash[ia]
26
+ column_type = image_model_class.translation_class.columns_hash[ia].type
27
+ end
28
+
29
+ case column_type
30
+ when :string then f.text_field(ia.to_sym, placeholder: ia)
31
+ when :text then f.text_area(ia.to_sym, placeholder: ia)
32
+ when :boolean then f.check_box(ia.to_sym)
33
+ end
34
+ end
35
+
36
+ template.raw(inputs.join) + template.content_tag(
37
+ :a, template.raw("&#10005;"), class: "close-button"
38
+ )
39
+ end
40
+ asset_html
16
41
  end
17
42
  end
18
43
  end
19
44
 
20
45
  html += template.content_tag :li do
21
46
  builder.fields_for(method, assets.build) do |f|
22
- f.file_field :asset
47
+ f.file_field :asset, multiple: true, accept: image_model_class.extension_white_list
23
48
  end
24
49
  end
25
50
 
@@ -0,0 +1,34 @@
1
+ class Formtastic::Inputs::SingleFileInput
2
+ include Formtastic::Inputs::Base
3
+
4
+ def to_html
5
+ object = builder.object
6
+ model_instance = object.send(method)
7
+ model_class = object.class.reflect_on_association(method).klass
8
+
9
+ html = template.raw("")
10
+ html << template.content_tag(:label, method.to_s.humanize, class: "label")
11
+ html << builder.fields_for(method, model_class.new) do |f|
12
+ f.file_field :asset, accept: model_class.extension_white_list
13
+ end
14
+
15
+ if model_instance
16
+ html << template.content_tag(:div, class: "file-description") do
17
+ filename = model_instance.asset.file.try(:filename)
18
+ f_html = template.raw("")
19
+
20
+ if model_class.to_s.include?("Image")
21
+ f_html << template.content_tag(:img, "", src: model_instance.asset.lalala_thumb.url)
22
+ end
23
+
24
+ if filename
25
+ f_html << template.content_tag(:span, filename)
26
+ end
27
+
28
+ f_html
29
+ end
30
+ end
31
+
32
+ input_wrapping { html }
33
+ end
34
+ end
@@ -30,6 +30,12 @@ module Lalala
30
30
  template 'errors_controller.rb', 'app/controllers/errors_controller.rb'
31
31
  end
32
32
 
33
+ def setup_models
34
+ empty_directory "app/models"
35
+ copy_file "models/file_asset.rb", "app/models/file_asset.rb"
36
+ copy_file "models/image_asset.rb", "app/models/image_asset.rb"
37
+ end
38
+
33
39
  def setup_pages
34
40
  empty_directory "app/pages"
35
41
  template 'application_page.rb', 'app/pages/application_page.rb'
@@ -48,6 +54,12 @@ module Lalala
48
54
  end
49
55
  end
50
56
 
57
+ def setup_uploaders
58
+ empty_directory "app/uploaders"
59
+ copy_file "uploaders/file.rb", "app/uploaders/file.rb"
60
+ copy_file "uploaders/image.rb", "app/uploaders/image.rb"
61
+ end
62
+
51
63
  def create_assets
52
64
  generate "lalala:assets"
53
65
  end
@@ -0,0 +1,23 @@
1
+ class CreateAssets < ActiveRecord::Migration
2
+ def up
3
+ create_table :assets do |t|
4
+ t.string :asset # carrierwave file mount
5
+ t.string :type
6
+
7
+ t.references :asset_owner, polymorphic: true
8
+ t.string :asset_owner_section
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :assets, [:asset_owner_id, :asset_owner_type, :asset_owner_section], name: 'asset_owner_idx'
14
+
15
+ ImageAsset.create_translation_table! title: :string, caption: :text
16
+ end
17
+
18
+ def down
19
+ drop_table :assets
20
+
21
+ ImageAsset.drop_translation_table!
22
+ end
23
+ end
@@ -0,0 +1,2 @@
1
+ class FileAsset < Lalala::FileAsset
2
+ end
@@ -0,0 +1,2 @@
1
+ class ImageAsset < Lalala::ImageAsset
2
+ end
@@ -0,0 +1,2 @@
1
+ class FileUploader < Lalala::Uploaders::File
2
+ end
@@ -0,0 +1,11 @@
1
+ class ImageUploader < Lalala::Uploaders::Image
2
+
3
+ #
4
+ # Versions
5
+ # -- https://github.com/jnicklas/carrierwave#adding-versions
6
+ #
7
+ # version :example do
8
+ # process :resize_to_fill => [420, 700]
9
+ # end
10
+
11
+ end
data/lib/lalala/engine.rb CHANGED
@@ -45,6 +45,10 @@ module Lalala
45
45
  'ActionDispatch::Flash',
46
46
  Lalala::ExtRack::PageLoader)
47
47
 
48
+ stack.insert_before(
49
+ 'ActionDispatch::Head',
50
+ Lalala::ExtRack::MultipleFileUploadSupport)
51
+
48
52
  end
49
53
 
50
54
  end
@@ -70,6 +74,9 @@ module Lalala
70
74
  ActiveRecord::Base.send(
71
75
  :include, Lalala::ExtActiveRecord::I18nTranslationsWriter)
72
76
 
77
+ ActiveRecord::Base.send(
78
+ :include, Lalala::ExtActiveRecord::Assets)
79
+
73
80
  end
74
81
 
75
82
  ActiveSupport.on_load :action_controller do
@@ -0,0 +1,25 @@
1
+ module Lalala::ExtActiveRecord::Assets
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+
6
+ def has_many_assets(name, options={})
7
+ class_name = options.delete(:class_name)
8
+ class_name ||= if name.to_s.include?("image") then "::ImageAsset" else "::FileAsset" end
9
+
10
+ attr_accessible :"#{name}_attributes"
11
+ has_many name, class_name: class_name, as: :asset_owner, dependent: :destroy, conditions: { asset_owner_section: name.to_s }
12
+ accepts_nested_attributes_for name, allow_destroy: true
13
+ end
14
+
15
+ def has_one_asset(name, options={})
16
+ class_name = options.delete(:class_name)
17
+ class_name ||= if name.to_s.include?("image") then "::ImageAsset" else "::FileAsset" end
18
+
19
+ attr_accessible :"#{name}_attributes"
20
+ has_one name, class_name: class_name, as: :asset_owner, dependent: :destroy, conditions: { asset_owner_section: name.to_s }
21
+ accepts_nested_attributes_for name, allow_destroy: true
22
+ end
23
+
24
+ end
25
+ end
@@ -3,4 +3,5 @@ module Lalala::ExtActiveRecord
3
3
 
4
4
  autoload :Schema
5
5
  autoload :I18nTranslationsWriter
6
+ autoload :Assets
6
7
  end
@@ -0,0 +1,46 @@
1
+ class Lalala::ExtRack::MultipleFileUploadSupport
2
+
3
+ METHODS = /^POST|PUT|PATCH$/
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if METHODS === env["REQUEST_METHOD"]
11
+ params = env["rack.request.form_hash"]
12
+ correct_assets_hash_nesting(params)
13
+ end
14
+
15
+ @app.call(env)
16
+ end
17
+
18
+ def correct_assets_hash_nesting(params, key=nil)
19
+ if key and key.to_s.ends_with?("_attributes")
20
+ return if params.size == 0
21
+
22
+ last_id = params.keys.sort_by(&:to_i).last
23
+ last_id = "#{last_id}"
24
+
25
+ return if params[last_id]["asset"].nil?
26
+
27
+ last = params.delete(last_id)
28
+ assets = last["asset"]
29
+
30
+ return unless Array === assets
31
+
32
+ assets.each do |file|
33
+ params[last_id] = { "asset" => file }.with_indifferent_access
34
+ last_id.succ!
35
+ end
36
+
37
+ else
38
+ case params
39
+ when Hash then params.each { |k, v| correct_assets_hash_nesting(v, k) }
40
+ when Array then params.each { |v| correct_assets_hash_nesting(v) }
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+ end
@@ -4,5 +4,6 @@ module Lalala::ExtRack
4
4
  autoload :CanonicalURL
5
5
  autoload :PageLoader
6
6
  autoload :I18nNegotiator
7
+ autoload :MultipleFileUploadSupport
7
8
 
8
9
  end
@@ -0,0 +1,19 @@
1
+ class Lalala::Uploaders::File < CarrierWave::Uploader::Base
2
+
3
+ def store_dir
4
+ if Rails.env.production? or Rails.env.staging?
5
+ "#{model.class.to_s.underscore}/#{model.id}"
6
+ else
7
+ "uploads/#{model.class.to_s.underscore}/#{model.id}"
8
+ end
9
+ end
10
+
11
+ def url(*)
12
+ if Rails.env.production? or Rails.env.staging?
13
+ File.join("/storage/assets", super)
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ end
@@ -1,27 +1,15 @@
1
- class Lalala::Uploaders::Image < CarrierWave::Uploader::Base
1
+ class Lalala::Uploaders::Image < Lalala::Uploaders::File
2
2
 
3
3
  include CarrierWave::MiniMagick
4
4
  include Sprockets::Helpers::RailsHelper
5
5
  include Sprockets::Helpers::IsolatedHelper
6
6
 
7
- def store_dir
8
- if Rails.env.production? or Rails.env.staging?
9
- "#{model.class.to_s.underscore}/#{model.id}"
10
- else
11
- "uploads/#{model.class.to_s.underscore}/#{model.id}"
12
- end
13
- end
14
-
15
- def url(*)
16
- if Rails.env.production? or Rails.env.staging?
17
- File.join("/storage/assets", super)
18
- else
19
- super
20
- end
21
- end
22
-
23
7
  def extension_white_list
24
8
  %w(jpg jpeg gif png)
25
9
  end
26
10
 
11
+ version :lalala_thumb do
12
+ process :resize_to_fill => [100, 100]
13
+ end
14
+
27
15
  end
@@ -1,5 +1,6 @@
1
1
  module Lalala::Uploaders
2
2
  extend ActiveSupport::Autoload
3
3
 
4
+ autoload :File
4
5
  autoload :Image
5
6
  end
@@ -1,6 +1,6 @@
1
1
  module Lalala
2
2
  VERSION = "4.0.0"
3
- BUILD = "94"
3
+ BUILD = "107"
4
4
 
5
5
  if BUILD != ("{{BUILD_NUMBER" + "}}") # prevent sed replacement (see script/ci)
6
6
  BUILD_VERSION = "#{VERSION}.dev.#{BUILD}"
data/lib/lalala.rb CHANGED
@@ -41,6 +41,7 @@ module Lalala
41
41
  end
42
42
 
43
43
  require 'formtastic/inputs/grid_input'
44
+ require 'formtastic/inputs/single_file_input'
44
45
 
45
46
  autoload :ExtActiveRecord
46
47
  autoload :ExtRack
@@ -1,4 +1,12 @@
1
- # desc "Explaining what the task does"
2
- # task :lalala do
3
- # # Task goes here
4
- # end
1
+ namespace :lalala do
2
+
3
+ namespace :assets do
4
+ desc "Reprocess assets"
5
+ task :reprocess => :environment do
6
+ ImageAsset.all.each do |image|
7
+ image.asset.recreate_versions! if image.asset
8
+ end
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,2 @@
1
+ class FileUploader < Lalala::Uploaders::File
2
+ end
@@ -0,0 +1,2 @@
1
+ class ImageUploader < Lalala::Uploaders::Image
2
+ end