redditor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +23 -0
  6. data/Guardfile +24 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +16 -0
  9. data/Rakefile +23 -0
  10. data/app/assets/images/redditor/.keep +0 -0
  11. data/app/assets/images/redditor/add_photo.png +0 -0
  12. data/app/assets/images/redditor/add_photo_big.png +0 -0
  13. data/app/assets/images/redditor/add_slider.png +0 -0
  14. data/app/assets/images/redditor/add_slider_big.png +0 -0
  15. data/app/assets/images/redditor/add_txt.png +0 -0
  16. data/app/assets/images/redditor/add_txt_big.png +0 -0
  17. data/app/assets/images/redditor/add_video.png +0 -0
  18. data/app/assets/images/redditor/add_video_big.png +0 -0
  19. data/app/assets/images/redditor/destroy_block_text.png +0 -0
  20. data/app/assets/images/redditor/move_handler.png +0 -0
  21. data/app/assets/images/redditor/no_format_text.png +0 -0
  22. data/app/assets/images/redditor/trash.png +0 -0
  23. data/app/assets/javascripts/fileapi/FileAPI.exif.js +59 -0
  24. data/app/assets/javascripts/fileapi/FileAPI.flash.image.swf +0 -0
  25. data/app/assets/javascripts/fileapi/FileAPI.flash.swf +0 -0
  26. data/app/assets/javascripts/fileapi/FileAPI.id3.js +67 -0
  27. data/app/assets/javascripts/fileapi/FileAPI.min.js +73 -0
  28. data/app/assets/javascripts/fileapi/fileapi.js.coffee.erb +12 -0
  29. data/app/assets/javascripts/fileapi/tmpl.js +35 -0
  30. data/app/assets/javascripts/fileapi/uploader.coffee +139 -0
  31. data/app/assets/javascripts/jquery-ui.min.js +12 -0
  32. data/app/assets/javascripts/redditor/application.js +14 -0
  33. data/app/assets/javascripts/redditor/fileapi/FileAPI.exif.js +59 -0
  34. data/app/assets/javascripts/redditor/fileapi/FileAPI.flash.image.swf +0 -0
  35. data/app/assets/javascripts/redditor/fileapi/FileAPI.flash.swf +0 -0
  36. data/app/assets/javascripts/redditor/fileapi/FileAPI.id3.js +67 -0
  37. data/app/assets/javascripts/redditor/fileapi/FileAPI.min.js +72 -0
  38. data/app/assets/javascripts/redditor/fileapi/README.md +724 -0
  39. data/app/assets/javascripts/redditor/fileapi/config.js.coffee.erb +5 -0
  40. data/app/assets/javascripts/redditor/fileapi/crossdomain.xml +19 -0
  41. data/app/assets/javascripts/redditor/fileapi/example.userpic.html +212 -0
  42. data/app/assets/javascripts/redditor/fileapi/index.html +548 -0
  43. data/app/assets/javascripts/redditor/fileapi/mailru.js +6 -0
  44. data/app/assets/javascripts/redditor/fileapi/mailru_front.js.coffee +143 -0
  45. data/app/assets/javascripts/redditor/fileapi/tmpl.js +35 -0
  46. data/app/assets/javascripts/redditor/fileapi/uploader.coffee +139 -0
  47. data/app/assets/javascripts/redditor/redditor.coffee +148 -0
  48. data/app/assets/stylesheets/redditor/application.css.scss +47 -0
  49. data/app/assets/stylesheets/redditor/fileapi/fileapi.css.scss +174 -0
  50. data/app/assets/stylesheets/redditor/fileapi/fileapi_front.css.scss +175 -0
  51. data/app/assets/stylesheets/redditor/redditor.css.scss +108 -0
  52. data/app/controllers/redditor/admin/base_controller.rb +18 -0
  53. data/app/controllers/redditor/admin/image_blocks_controller.rb +37 -0
  54. data/app/controllers/redditor/admin/images_controller.rb +33 -0
  55. data/app/controllers/redditor/admin/pages_controller.rb +15 -0
  56. data/app/controllers/redditor/admin/slider_blocks_controller.rb +32 -0
  57. data/app/controllers/redditor/admin/text_blocks_controller.rb +31 -0
  58. data/app/controllers/redditor/admin/video_blocks_controller.rb +31 -0
  59. data/app/controllers/redditor/application_controller.rb +4 -0
  60. data/app/helpers/redditor/application_helper.rb +4 -0
  61. data/app/helpers/redditor/fileapi_helper.rb +17 -0
  62. data/app/helpers/redditor/pages_helper.rb +24 -0
  63. data/app/models/redditor/content_block.rb +24 -0
  64. data/app/models/redditor/image.rb +29 -0
  65. data/app/models/redditor/page.rb +28 -0
  66. data/app/models/redditor/slider_block.rb +17 -0
  67. data/app/models/redditor/text_block.rb +20 -0
  68. data/app/models/redditor/video_block.rb +27 -0
  69. data/app/uploaders/redditor_uploader.rb +57 -0
  70. data/app/views/layouts/redditor/application.html.erb +15 -0
  71. data/app/views/redditor/admin/pages/_content_block.haml +16 -0
  72. data/app/views/redditor/admin/pages/_fileapi.erb +199 -0
  73. data/app/views/redditor/admin/pages/_image.haml +18 -0
  74. data/app/views/redditor/admin/pages/_page.haml +13 -0
  75. data/app/views/redditor/admin/pages/_slider_block.haml +16 -0
  76. data/app/views/redditor/admin/pages/_slider_block_image.haml +3 -0
  77. data/app/views/redditor/admin/pages/_text_block.haml +5 -0
  78. data/app/views/redditor/admin/pages/_validate.haml +4 -0
  79. data/app/views/redditor/admin/pages/_video_block.haml +19 -0
  80. data/app/views/redditor/admin/pages/_wrap_dd.haml +1 -0
  81. data/app/views/redditor/admin/pages/_wrapper.haml +3 -0
  82. data/app/views/redditor/admin/pages/new.js.coffee +7 -0
  83. data/app/views/redditor/admin/pages/new.js.erb +7 -0
  84. data/app/views/redditor/admin/pages/slider_block_image.js.coffee +2 -0
  85. data/app/views/redditor/admin/pages/wrapper.js.coffee +6 -0
  86. data/app/views/redditor/pages/_page.html.haml +1 -0
  87. data/app/views/redditor/slider_blocks/_slider_block.html.haml +2 -0
  88. data/app/views/redditor/slider_blocks/_slider_block_image.html.erb +3 -0
  89. data/app/views/redditor/text_blocks/_text_block.html.haml +1 -0
  90. data/app/views/redditor/video_blocks/_video_block.html.haml +2 -0
  91. data/bin/rails +8 -0
  92. data/config/locales/redditor.en.yml +20 -0
  93. data/config/locales/redditor.ru.yml +20 -0
  94. data/config/routes.rb +17 -0
  95. data/db/migrate/20130916155124_create_redditor_images.rb +15 -0
  96. data/db/migrate/20130916155156_create_redditor_pages.rb +12 -0
  97. data/db/migrate/20130916155219_create_redditor_slider_blocks.rb +11 -0
  98. data/db/migrate/20130916155239_create_redditor_text_blocks.rb +12 -0
  99. data/db/migrate/20130916155301_create_redditor_video_blocks.rb +14 -0
  100. data/lib/generators/redditor/views/views_generator.rb +17 -0
  101. data/lib/redditor/engine.rb +12 -0
  102. data/lib/redditor/has_redditor.rb +17 -0
  103. data/lib/redditor/version.rb +3 -0
  104. data/lib/redditor.rb +9 -0
  105. data/lib/tasks/redditor_tasks.rake +4 -0
  106. data/redditor.gemspec +38 -0
  107. data/spec/dummy/.rspec +1 -0
  108. data/spec/dummy/README.rdoc +28 -0
  109. data/spec/dummy/Rakefile +6 -0
  110. data/spec/dummy/app/assets/images/.keep +0 -0
  111. data/spec/dummy/app/assets/javascripts/application.js +17 -0
  112. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  113. data/spec/dummy/app/controllers/admin/articles_controller.rb +23 -0
  114. data/spec/dummy/app/controllers/admin/base_controller.rb +6 -0
  115. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  116. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  117. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  118. data/spec/dummy/app/mailers/.keep +0 -0
  119. data/spec/dummy/app/models/.keep +0 -0
  120. data/spec/dummy/app/models/article.rb +7 -0
  121. data/spec/dummy/app/models/concerns/.keep +0 -0
  122. data/spec/dummy/app/views/admin/articles/edit.html.haml +15 -0
  123. data/spec/dummy/app/views/articles/show.html.haml +2 -0
  124. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  125. data/spec/dummy/bin/bundle +3 -0
  126. data/spec/dummy/bin/rails +4 -0
  127. data/spec/dummy/bin/rake +4 -0
  128. data/spec/dummy/config/application.rb +31 -0
  129. data/spec/dummy/config/boot.rb +5 -0
  130. data/spec/dummy/config/database.yml +25 -0
  131. data/spec/dummy/config/environment.rb +5 -0
  132. data/spec/dummy/config/environments/development.rb +29 -0
  133. data/spec/dummy/config/environments/production.rb +80 -0
  134. data/spec/dummy/config/environments/test.rb +36 -0
  135. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  136. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  137. data/spec/dummy/config/initializers/inflections.rb +16 -0
  138. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  139. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  140. data/spec/dummy/config/initializers/session_store.rb +3 -0
  141. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  142. data/spec/dummy/config/locales/en.yml +23 -0
  143. data/spec/dummy/config/routes.rb +10 -0
  144. data/spec/dummy/config.ru +4 -0
  145. data/spec/dummy/db/migrate/20130908123351_create_articles.rb +9 -0
  146. data/spec/dummy/db/schema.rb +76 -0
  147. data/spec/dummy/lib/assets/.keep +0 -0
  148. data/spec/dummy/log/.keep +0 -0
  149. data/spec/dummy/public/404.html +58 -0
  150. data/spec/dummy/public/422.html +58 -0
  151. data/spec/dummy/public/500.html +57 -0
  152. data/spec/dummy/public/favicon.ico +0 -0
  153. data/spec/factories/articles_factory.rb +27 -0
  154. data/spec/factories/redditor/images_factory.rb +9 -0
  155. data/spec/factories/redditor/pages_factory.rb +37 -0
  156. data/spec/factories/redditor/sliders_factory.rb +9 -0
  157. data/spec/factories/redditor/texts_factory.rb +5 -0
  158. data/spec/factories/redditor/videos_factories.rb +7 -0
  159. data/spec/features/text_spec.rb +52 -0
  160. data/spec/features/video_spec.rb +52 -0
  161. data/spec/fixtures/test.jpg +0 -0
  162. data/spec/generators/views_generator_spec.rb +20 -0
  163. data/spec/models/article_spec.rb +40 -0
  164. data/spec/spec_helper.rb +67 -0
  165. data/spec/views/article/show_spec.rb +22 -0
  166. metadata +480 -0
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ class RedditorUploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or MiniMagick support:
6
+ include CarrierWave::RMagick
7
+ # include CarrierWave::MiniMagick
8
+
9
+ # Choose what kind of storage to use for this uploader:
10
+ storage :file
11
+ # storage :fog
12
+
13
+ # Override the directory where uploaded files will be stored.
14
+ # This is a sensible default for uploaders that are meant to be mounted:
15
+ def store_dir
16
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
17
+ end
18
+
19
+ version :admin do
20
+ # process :resize_to_fit => [119, 119]
21
+ process :resize_and_pad => [119, 119, :transparent, ::Magick::CenterGravity]
22
+ end
23
+
24
+ version :show do
25
+ process :resize_to_fill => [600, 400]
26
+ end
27
+
28
+ # Provide a default URL as a default if there hasn't been a file uploaded:
29
+ # def default_url
30
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
31
+ # end
32
+
33
+ # Process files as they are uploaded:
34
+ # process :scale => [200, 300]
35
+ #
36
+ # def scale(width, height)
37
+ # # do something
38
+ # end
39
+
40
+ # Create different versions of your uploaded files:
41
+ # version :thumb do
42
+ # process :scale => [50, 50]
43
+ # end
44
+
45
+ # Add a white list of extensions which are allowed to be uploaded.
46
+ # For images you might use something like this:
47
+ # def extension_white_list
48
+ # %w(jpg jpeg gif png)
49
+ # end
50
+
51
+ # Override the filename of the uploaded files:
52
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
53
+ # def filename
54
+ # "something.jpg" if original_filename
55
+ # end
56
+
57
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Redditor</title>
5
+ <%= stylesheet_link_tag "redditor/application", media: "all" %>
6
+ <%= javascript_include_tag "redditor/application" %>
7
+ <%= yield :js %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,16 @@
1
+ .handle
2
+
3
+ - if content_block.new_record?
4
+ .control-data
5
+ = link_to "✘", "javascript:void(0);", onclick: "if (confirm('#{t "redditor.remove?"}')) $(this).closest('dd').remove();", class: "delete-data"
6
+ = link_to "✔", [redditor, :admin, p.object, content_block], method: "post", class: "update-data", remote: true, data: {:disable_with => "✔ #{t "redditor.saving"}"}
7
+ - else
8
+ .control-data
9
+ = link_to "✘", [redditor, :admin, p.object, content_block], :method => :delete, remote: true, data: {confirm: "Вы, действительно, хотите удалить контент-блок?", disable_with: "✘ #{t "redditor.deleting"}"}, class: "delete-data"
10
+ = link_to "✔", [redditor, :admin, p.object, content_block], method: "put", class: "update-data", remote: true, data: {disable_with: "✔ #{t "redditor.saving"}"}
11
+
12
+ = p.fields_for content_block.class.name.underscore.sub('redditor/', '').pluralize.to_sym, content_block do |f|
13
+ %div.form-name{data: {"object-name" => f.object.temp_id.present? ? f.object_name.sub!(/\[\d*\]/, "[#{f.object.temp_id}]") : f.object_name}, id: "#{content_block.class.name.underscore.sub(/\Aredditor\//, '')}_#{content_block.id.nil? ? f.object.temp_id : content_block.id}"}
14
+ = f.text_field :position, class: 'js-position', hidden: true
15
+ = render :partial => "redditor/admin/pages/#{content_block.class.name.underscore.sub('redditor/', '')}", locals: {f: f}
16
+ = f.hidden_field :temp_id
@@ -0,0 +1,199 @@
1
+
2
+ <% content_for :js do %>
3
+
4
+ <%= javascript_include_tag "fileapi/config", "fileapi/FileAPI.min", "fileapi/FileAPI.id3.js", "fileapi/FileAPI.exif.js", "fileapi/tmpl" %>
5
+
6
+ <%= stylesheet_link_tag "fileapi/fileapi" %>
7
+
8
+ <script id="b-file-ejs" type="text/ejs">
9
+ <div id="file-<%%=FileAPI.uid(file)%>" class="js-file b-file b-file_<%%=file.type.split('/')[0]%>">
10
+ <div class="js-left b-file__left">
11
+ <img src="<%%=icon[file.type.split('/')[0]]||icon.def%>" width="32" height="32" style="margin: 2px 0 0 3px"/>
12
+ </div>
13
+ <div class="b-file__right">
14
+ <div><a class="js-name b-file__name"><%%=file.name%></a></div>
15
+ <div class="js-info b-file__info">size: <%%=(file.size/FileAPI.KB).toFixed(2)%> KB</div>
16
+ <div class="js-progress b-file__bar" style="display: none">
17
+ <div class="b-progress"><div class="js-bar b-progress__bar"></div></div>
18
+ </div>
19
+ </div>
20
+ <i class="js-abort b-file__abort" title="abort">&times;</i>
21
+ </div>
22
+ </script>
23
+
24
+ <script id="b-layer-ejs" type="text/ejs">
25
+ <div class="b-layer">
26
+ <div class="b-layer__h1"><%%=file.name%></div>
27
+ <div class="js-img b-layer__img"></div>
28
+ <div class="b-layer__info">
29
+ <%%
30
+ FileAPI.each(info, function(val, key){
31
+ if( Object.prototype.toString.call(val) == '[object Object]' ){
32
+ var sub = '';
33
+ FileAPI.each(val, function (val, key){ sub += '<div>'+key+': '+val+'</div>'; });
34
+ if( sub ){
35
+ %><%%=key%><div style="margin: 0 0 5px 20px;"><%%=sub%></div><%%
36
+ }
37
+ } else {
38
+ %>
39
+ <div><%%=key%>: <%%=val%></div>
40
+ <%%
41
+ }
42
+ });
43
+ %>
44
+ </div>
45
+ </div>
46
+ </script>
47
+
48
+
49
+ <script type="text/javascript">
50
+ jQuery(function ($){
51
+ if( !(FileAPI.support.cors || FileAPI.support.flash) ){
52
+ $('#oooops').show();
53
+ $('#buttons-panel').hide();
54
+ }
55
+
56
+ $(document).on('mouseenter mouseleave', '.b-button', function (evt){
57
+ $(evt.currentTarget).toggleClass('b-button_hover', evt.type == 'mouseenter');
58
+ });
59
+
60
+
61
+ if( FileAPI.support.dnd ){
62
+ $('#drag-n-drop').show();
63
+ $(document).dnd(function (over){
64
+ $('#drop-zone').toggle(over);
65
+ }, function (files){
66
+ onFiles(files);
67
+ });
68
+ }
69
+
70
+
71
+ $(document).on('change', 'input[type="file"]', function (evt){
72
+ var files = FileAPI.getFiles(evt);
73
+ onFiles.call(this, files);
74
+ FileAPI.reset(evt.currentTarget);
75
+ });
76
+
77
+
78
+ var FU = {
79
+ icon: {
80
+ def: '//cdn1.iconfinder.com/data/icons/CrystalClear/32x32/mimetypes/unknown.png'
81
+ , image: '//cdn1.iconfinder.com/data/icons/humano2/32x32/apps/synfig_icon.png'
82
+ , audio: '//cdn1.iconfinder.com/data/icons/august/PNG/Music.png'
83
+ , video: '//cdn1.iconfinder.com/data/icons/df_On_Stage_Icon_Set/128/Video.png'
84
+ },
85
+
86
+ files: [],
87
+ index: 0,
88
+ active: false,
89
+
90
+ add: function (file){
91
+ FU.files.push(file);
92
+
93
+ if( /^image/.test(file.type) ){
94
+ FileAPI.Image(file).preview(35).rotate('auto').get(function (err, img){
95
+ if( !err ){
96
+ FU._getEl(file, '.js-left')
97
+ .addClass('b-file__left_border')
98
+ .html(img)
99
+ ;
100
+ }
101
+ });
102
+ }
103
+ },
104
+
105
+ getFileById: function (id){
106
+ var i = FU.files.length;
107
+ while( i-- ){
108
+ if( FileAPI.uid(FU.files[i]) == id ){
109
+ return FU.files[i];
110
+ }
111
+ }
112
+ },
113
+
114
+ start: function (context){
115
+ if( !FU.active && (FU.active = FU.files.length > FU.index) ){
116
+ FU._upload(FU.files[FU.index], context);
117
+ }
118
+ },
119
+
120
+ abort: function (id){
121
+ var file = this.getFileById(id);
122
+ if( file.xhr ){
123
+ file.xhr.abort();
124
+ }
125
+ },
126
+
127
+ _getEl: function (file, sel){
128
+ var $el = $('#file-'+FileAPI.uid(file));
129
+ return sel ? $el.find(sel) : $el;
130
+ },
131
+
132
+ _upload: function (file, context){
133
+ if( file ){
134
+ file.xhr = FileAPI.upload({
135
+ url: FU.uploadUrl,
136
+ data: {"content_block_id": FU.contentBlockId},
137
+ dataType: "script", // forced respond is script!!
138
+ headers: {
139
+ 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
140
+ },
141
+ files: {
142
+ file: file
143
+ },
144
+ upload: function (){
145
+ FU._getEl(file).addClass('b-file_upload');
146
+ FU._getEl(file, '.js-progress')
147
+ .css({ opacity: 0 }).show()
148
+ .animate({ opacity: 1 }, 100)
149
+ ;
150
+ },
151
+ progress: function (evt){
152
+ FU._getEl(file, '.js-bar').css('width', evt.loaded/evt.total*100+'%');
153
+ },
154
+ complete: function (err, xhr){
155
+ setTimeout(xhr.response, 10)
156
+ var state = err ? 'error' : 'done';
157
+
158
+ FU._getEl(file).removeClass('b-file_upload');
159
+ FU._getEl(file, '.js-progress').animate({ opacity: 0 }, 200, function (){ $(this).hide() });
160
+ FU._getEl(file, '.js-info').append(', <b class="b-file__'+state+'">'+(err ? (xhr.statusText || err) : state)+'</b>');
161
+
162
+ FU.index++;
163
+ FU.active = false;
164
+
165
+ FU.start(context);
166
+ }
167
+ });
168
+ }
169
+ }
170
+ };
171
+
172
+ function onFiles(files){
173
+ var context = this; // input, на который нажали
174
+ var $Queue = $('<div class="upload-area" />').appendTo($(this).closest("dd"));
175
+
176
+
177
+ FU.uploadUrl = $(context).data("url");
178
+ FU.contentBlockId = $(context).closest("dd").attr("id").replace(/\D/gi,"");
179
+
180
+ FileAPI.each(files, function (file){
181
+ if( file.size >= 25*FileAPI.MB ){
182
+ alert('Sorrow.\nMax size 25MB')
183
+ }
184
+ else if( file.size === void 0 ){
185
+ $('#oooops').show();
186
+ $('#buttons-panel').hide();
187
+ }
188
+ else {
189
+ $Queue.append(tmpl($('#b-file-ejs').html(), { file: file, icon: FU.icon }));
190
+
191
+ FU.add(file);
192
+ FU.start(context);
193
+ }
194
+ });
195
+ }
196
+ }); // ready
197
+ </script>
198
+
199
+ <% end %>
@@ -0,0 +1,18 @@
1
+ .tit-form
2
+ = t 'redditor.title.image'
3
+ = image_tag 'redditor/add_photo_big.png'
4
+ - if f.object.src.present?
5
+ %div{style: "padding: 5px; border: 1px solid #ccc; background:#fff; margin: 5px 0;"}= image_tag f.object.src, style: "max-width: 100%"
6
+ = redditor_validate f
7
+ .condom{style: "margin:5px 0;"}
8
+ = f.text_field :description, placeholder: t("redditor.description"), class: 'full-width'
9
+
10
+ .condom{style: "margin:5px 0; height:1px; background:#ccc;"}
11
+
12
+ .b-button.js-fileapi-wrapper
13
+ - if f.object.new_record?
14
+ .b-button__text= t("redditor.add.upload_image")
15
+ = f.file_field :src, :class => "b-button__input js-fileapi", data: {"upload-url" => redditor.admin_page_image_blocks_path(f.object.imageable_id), "content-block-id" => true}
16
+ - else
17
+ .b-button__text= t("redditor.add.change_image")
18
+ = f.file_field :src, :class => "b-button__input js-fileapi", data: {"upload-url" => redditor.update_post_admin_page_image_block_path(f.object.imageable_id, f.object)}
@@ -0,0 +1,13 @@
1
+ = f.fields_for :page, f.object.page do |p|
2
+
3
+ - unless f.object.new_record?
4
+ %dl.redditor{data: {"sort-url" => url_for(redditor.sort_admin_page_path(p.object))}}
5
+ - p.object.content_blocks.each do |content_block|
6
+ = render partial: "redditor/admin/pages/content_block", locals: {p: p, page: p.object, content_block: content_block}, :layout => "redditor/admin/pages/wrap_dd"
7
+
8
+ %div.redditor-add-blocks
9
+ %p
10
+ = link_to t('redditor.add.text_block'), redditor.new_admin_page_text_block_path(f.object.page), remote: true, class: "new-block add-txt"
11
+ = link_to t('redditor.add.video_block'), redditor.new_admin_page_video_block_path(f.object.page), remote: true, class: "new-block add-video"
12
+ = link_to t('redditor.add.image_block'), redditor.new_admin_page_image_block_path(f.object.page), remote: true, class: "new-block add-photo"
13
+ = link_to t('redditor.add.slider_block'), redditor.admin_page_slider_blocks_path(f.object.page), remote: true, method: 'POST', class: "new-block add-slider"
@@ -0,0 +1,16 @@
1
+ .tit-form
2
+ = t 'redditor.title.slider'
3
+ = image_tag 'redditor/add_slider_big.png'
4
+ = redditor_validate f
5
+ .condom{style: "margin:5px 0; height:1px; background:#ccc;"}
6
+
7
+ - unless f.object.new_record?
8
+ %ul.slider-block-images{data: {"sortable-url" => redditor.sort_admin_page_slider_block_images_path(f.object.page_id, f.object.id)}}
9
+ = render partial: "redditor/admin/pages/slider_block_image", collection: f.object.images, :as => :i
10
+
11
+ .condom{style: "margin:5px 0; height:1px; background:#ccc;"}
12
+
13
+ - unless f.object.new_record?
14
+ .b-button.js-fileapi-wrapper
15
+ .b-button__text= t("redditor.add.upload_images")
16
+ = file_field_tag :src, :class => "b-button__input js-fileapi", name: nil, :multiple => true, data: {"upload-url" => redditor.admin_page_slider_block_images_path(f.object.page_id, f.object.id)}
@@ -0,0 +1,3 @@
1
+ %li{id: "slider_block_image_#{i.id}"}
2
+ = image_tag i.src.url(:admin)
3
+ = link_to "", redditor.admin_page_slider_block_image_path(i.imageable.page, i.imageable, i), data: {:method => :delete, remote: true, confirm: t("redditor.delete_image")}, class: "del-item"
@@ -0,0 +1,5 @@
1
+ .tit-form
2
+ = t 'redditor.title.text'
3
+ = image_tag 'redditor/add_txt_big.png'
4
+ = redditor_validate f
5
+ = f.text_area :body, size: "25x15", class: "text-block-input"
@@ -0,0 +1,4 @@
1
+ - if f.object.errors.any?
2
+ %ol.validate
3
+ - f.object.errors.full_messages.each do |msg|
4
+ %li= msg
@@ -0,0 +1,19 @@
1
+ .tit-form
2
+ = t 'redditor.title.video'
3
+ = image_tag 'redditor/add_video_big.png'
4
+ = redditor_validate f
5
+ - if f.object.youtube.present?
6
+ %iframe(width="#{f.object.width || "100%"}" height="#{f.object.height || 315}" src="http://www.youtube.com/embed/#{f.object.youtube}" frameborder="0" allowfullscreen)
7
+ %br
8
+ .line-form
9
+ = f.label :youtube
10
+ %br
11
+ = f.text_field :youtube, class: "video-block-input"
12
+ .line-form
13
+ = f.label :width
14
+ %br
15
+ = f.text_field :width, :size => 10
16
+ .line-form
17
+ = f.label :height
18
+ %br
19
+ = f.text_field :height, :size => 10
@@ -0,0 +1 @@
1
+ %dd{class: content_block.class.name.underscore.sub('redditor/', '')}= yield
@@ -0,0 +1,3 @@
1
+ = fields_for :article, @page.pageable do |a|
2
+ = a.fields_for :page do |p|
3
+ = render "redditor/admin/pages/content_block", {p: p, content_block: content_block, page: @page}
@@ -0,0 +1,7 @@
1
+ REDDE.redditor.$el
2
+ .append('<%= j(render(partial: "redditor/admin/pages/wrapper", layout: "redditor/admin/pages/wrap_dd", locals: {content_block: @content_block, page: @page})) %>')
3
+ # .find("textarea:visible:not(.nowred)").redactor(reddactorSettings)
4
+ .end()
5
+ .find("ul.slider-block-images").sortable REDDE.redditor.sliderBlockImagesSortableParams
6
+ REDDE.redditor.sortList()
7
+ # selectLang(location.hash.replace("#",""))
@@ -0,0 +1,7 @@
1
+ REDDE.redditor.$el
2
+ .append('<%= j(render(partial: "redditor/admin/pages/wrapper", layout: "redditor/admin/pages/wrap_dd", locals: {content_block: @content_block, page: @page})) %>')
3
+ // .find("textarea:visible:not(.nowred)").redactor(reddactorSettings)
4
+ .end()
5
+ .find("ul.slider-block-images").sortable(REDDE.redditor.sliderBlockImagesSortableParams)
6
+ REDDE.redditor.sortList()
7
+ // selectLang(location.hash.replace("#",""))
@@ -0,0 +1,2 @@
1
+ $("#slider_block_<%= @slider_block.id %>").find("ul.slider-block-images")
2
+ .append '<%= j(render "redditor/admin/pages/slider_block_image", {i: @image}) %>'
@@ -0,0 +1,6 @@
1
+ $("#<%= @content_block.class.name.underscore.sub(/\Aredditor\//, '') %>_<%= @content_block.temp_id %>, #<%= @content_block.class.name.underscore.sub(/\Aredditor\//, '') %>_<%= @content_block.id %>").closest("dd")
2
+ .html('<%= j(render(partial: "redditor/admin/pages/wrapper", locals: {content_block: @content_block, page: @page})) %>')
3
+ # .find("textarea:visible:not(.nowred)").redactor(reddactorSettings)
4
+ .end()
5
+ .find("ul.slider-block-images").sortable REDDE.redditor.sliderBlockImagesSortableParams
6
+ # selectLang(location.hash.replace("#",""))
@@ -0,0 +1 @@
1
+ = render page.content_blocks
@@ -0,0 +1,2 @@
1
+ %ul.slider-block-images{id: "slider_block_#{slider_block.id}"}
2
+ = render partial: "redditor/slider_blocks/slider_block_image", collection: slider_block.images, :as => :image
@@ -0,0 +1,3 @@
1
+ <li id="slider_block_image_<%= image.id %>">
2
+ <%= image_tag image.src.url, alt: image.description %>
3
+ </li>
@@ -0,0 +1 @@
1
+ .text_block{id: "text_block_#{text_block.id}"}= raw text_block.body
@@ -0,0 +1,2 @@
1
+ .video-block{id: "video_block_#{video_block.id}"}
2
+ %iframe(width="#{video_block.width || "100%"}" height="#{video_block.height || 315}" src="http://www.youtube.com/embed/#{video_block.youtube}" frameborder="0" allowfullscreen)
data/bin/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/redditor/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,20 @@
1
+ en:
2
+ redditor:
3
+ add:
4
+ text_block: Add text
5
+ video_block: Add video
6
+ image_block: Add photo
7
+ slider_block: Add slider
8
+ upload_image: Upload image
9
+ upload_images: Upload images
10
+ change_image: Change image
11
+ delete_image: "Delete image?"
12
+ description: "Description"
13
+ remove?: "Really delete content block?"
14
+ deleting: Deleting...
15
+ saving: Saving...
16
+ title:
17
+ image: Image
18
+ video: Video
19
+ slider: Slider
20
+ text: Text
@@ -0,0 +1,20 @@
1
+ ru:
2
+ redditor:
3
+ add:
4
+ text_block: Добавить текст
5
+ video_block: Добавить видео
6
+ image_block: Добавить фото
7
+ slider_block: Добавить логотипы
8
+ upload_image: Загрузить изображение
9
+ upload_images: Загрузить изображения
10
+ change_image: "Заменить изображение"
11
+ delete_image: "Удалить изображение?"
12
+ description: "Описание"
13
+ remove?: "Вы, действительно, хотите удалить контент-блок?"
14
+ deleting: Удаление...
15
+ saving: Сохранение...
16
+ title:
17
+ image: Изображение
18
+ video: Видео
19
+ slider: Слайдеры
20
+ text: Текст
data/config/routes.rb ADDED
@@ -0,0 +1,17 @@
1
+ Redditor::Engine.routes.draw do
2
+ namespace :admin do
3
+ resources :pages do
4
+ resources :text_blocks, :video_blocks
5
+ resources :image_blocks, :images, :controller => "image_blocks" do
6
+ post :update_post, :on => :member
7
+ end
8
+ resources :slider_blocks do
9
+ resources :images do
10
+ get 'sort', :on => :collection
11
+ end
12
+ end
13
+ post 'sort', :on => :member
14
+ post 'create_image', :on => :member
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ class CreateRedditorImages < ActiveRecord::Migration
2
+ def change
3
+ create_table(:redditor_images) do |t|
4
+ t.integer "imageable_id"
5
+ t.string "imageable_type"
6
+ t.integer "position"
7
+ t.string "src"
8
+ t.string "description"
9
+ t.datetime "created_at", :null => false
10
+ t.datetime "updated_at", :null => false
11
+ end
12
+ add_index :redditor_images, :imageable_type
13
+ add_index :redditor_images, :imageable_id
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ class CreateRedditorPages < ActiveRecord::Migration
2
+ def change
3
+ create_table(:redditor_pages) do |t|
4
+ t.integer "pageable_id"
5
+ t.string "pageable_type"
6
+ t.datetime "created_at", :null => false
7
+ t.datetime "updated_at", :null => false
8
+ end
9
+ add_index :redditor_pages, :pageable_type
10
+ add_index :redditor_pages, :pageable_id
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateRedditorSliderBlocks < ActiveRecord::Migration
2
+ def change
3
+ create_table(:redditor_slider_blocks) do |t|
4
+ t.integer "page_id"
5
+ t.integer "position"
6
+ t.datetime "created_at", :null => false
7
+ t.datetime "updated_at", :null => false
8
+ end
9
+ add_index :redditor_slider_blocks, :page_id
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateRedditorTextBlocks < ActiveRecord::Migration
2
+ def change
3
+ create_table(:redditor_text_blocks) do |t|
4
+ t.integer "page_id"
5
+ t.text "body"
6
+ t.integer "position"
7
+ t.datetime "created_at", :null => false
8
+ t.datetime "updated_at", :null => false
9
+ end
10
+ add_index :redditor_text_blocks, :page_id
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class CreateRedditorVideoBlocks < ActiveRecord::Migration
2
+ def change
3
+ create_table(:redditor_video_blocks) do |t|
4
+ t.integer "page_id"
5
+ t.integer "position"
6
+ t.integer "width"
7
+ t.integer "height"
8
+ t.string "youtube"
9
+ t.datetime "created_at", :null => false
10
+ t.datetime "updated_at", :null => false
11
+ end
12
+ add_index :redditor_video_blocks, :page_id
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/generated_attribute'
5
+
6
+ module Redditor
7
+ module Generators
8
+ class ViewsGenerator < ::Rails::Generators::Base
9
+ source_root File.expand_path('../../../../../app/views', __FILE__)
10
+
11
+ def copy_views
12
+ directory "redditor", "app/views/redditor"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Redditor
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Redditor
4
+
5
+ initializer 'redditor.action_controller' do |app|
6
+ ActiveSupport.on_load :action_controller do
7
+ helper Redditor::FileapiHelper
8
+ helper Redditor::PagesHelper
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+
3
+ class << ActiveRecord::Base
4
+ def has_redditor
5
+ # Include required methods
6
+ # include Redditor::InstanceMethods
7
+ # extend Redditor::ClassMethods
8
+
9
+ # Save self as base class (for STI)
10
+
11
+ cattr_accessor :redditor_base_class
12
+ self.redditor_base_class = self
13
+ has_one :page, :as => :pageable, class_name: "Redditor::Page"
14
+ accepts_nested_attributes_for :page
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Redditor
2
+ VERSION = "0.1.0"
3
+ end
data/lib/redditor.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "redditor/engine"
2
+
3
+ require 'redditor/has_redditor'
4
+
5
+ require "generators/redditor/views/views_generator"
6
+ require 'rails/generators/active_record'
7
+
8
+ module Redditor
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :redditor do
3
+ # # Task goes here
4
+ # end