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,175 @@
1
+ @import "compass";
2
+
3
+ #oooops {
4
+ // уведомления о том что ничего не поддерживается кроме фрейма
5
+ display: none;
6
+ border-radius: 4px;
7
+ padding: 10px;
8
+ margin: 10px 0; border: 2px solid #f60;
9
+ }
10
+
11
+ #buttons-panel {
12
+ font-size: 15px;
13
+ font-family: "Helvetica Neue";
14
+ margin-top: 7%;
15
+ }
16
+
17
+ .b-button {
18
+ position: relative;
19
+ overflow: hidden;
20
+ cursor: pointer;
21
+ color: rgb(62, 112, 141);
22
+ border-bottom: 1px dashed #000080;
23
+ -webkit-user-select: none;
24
+ -moz-user-select: none;
25
+ user-select: none;
26
+ margin-left: 8%;
27
+ display: inline-block;
28
+ font: 16px myfont;
29
+ &:hover {
30
+ text-decoration: underline;
31
+ border-bottom-color: transparent;
32
+ };
33
+ .b-button__input {
34
+ cursor: pointer;
35
+ @include opacity(0);
36
+ top: -10px;
37
+ right: -40px;
38
+ font-size: 50px;
39
+ position: absolute;
40
+ padding: 50px;
41
+ }
42
+ }
43
+
44
+
45
+
46
+
47
+ #preview {
48
+ box-shadow: 0 1px 3px rgba(0,0,0,.4);
49
+ border-radius: 3px;
50
+ }
51
+
52
+ .b-file {
53
+ padding: 5px;
54
+ position: relative;
55
+ overflow: hidden;
56
+ border-radius: 3px;
57
+ background-color: #fcfcfc;
58
+ background: -webkit-linear-gradient(top, #fcfcfc 0%, #f6f6f6 100%);
59
+ background: -moz-linear-gradient(top, #fcfcfc 0%, #f6f6f6 100%);
60
+ background: -o-linear-gradient(top, #fcfcfc 0%, #f6f6f6 100%);
61
+ background: linear-gradient(to bottom, #fcfcfc 0%, #f6f6f6 100%);
62
+ clear: both;
63
+ }
64
+ .b-file__left {
65
+ float: left;
66
+ margin: 1px 0 0 2px;
67
+ line-height: 0;
68
+ }
69
+ .b-file__left_border {
70
+ border: 2px solid #fff;
71
+ border-radius: 4px;
72
+ }
73
+
74
+ .b-file__right {
75
+ margin-left: 45px;
76
+ }
77
+
78
+ .b-file__name {
79
+ color: #36c;
80
+ }
81
+
82
+ .b-file__info {
83
+ color: #666;
84
+ position: relative;
85
+ font-size: 12px;
86
+ margin-top: 3px;
87
+ }
88
+
89
+ .b-file__bar {
90
+ padding-top: 4px;
91
+ }
92
+
93
+ .b-file__error {
94
+ color: #c00;
95
+ }
96
+ .b-file__done {
97
+ color: #458383;
98
+ }
99
+ .b-file__abort {
100
+ top: 10px;
101
+ right: 20px;
102
+ width: 15px;
103
+ height: 15px;
104
+ position: absolute;
105
+ color: #c00;
106
+ cursor: pointer;
107
+ font-size: 20px;
108
+ display: none;
109
+ font-style: italic;
110
+ border-bottom: none !important;
111
+ text-decoration: none !important;
112
+ }
113
+ .b-file_upload .b-file__abort { display: block; }
114
+
115
+ .b-progress {
116
+ max-width: 200px;
117
+ clear: both;
118
+ height: 10px;
119
+ border: 2px solid #E2E4E2;
120
+ border-radius: 10px;
121
+ box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
122
+ background-color: #d3d3d3;
123
+ position: relative;
124
+ }
125
+ .b-progress__bar {
126
+ width: 0;
127
+ height: 10px;
128
+ border-radius: 10px;
129
+ background-color: #2D9DD7;
130
+ @include background(linear-gradient(top, #2D9DD7 0%, #1C81C7 100%));
131
+ -webkit-transition: width .5s ease-out;
132
+ -moz-transition: width .5s ease-out;
133
+ -ms-transition: width .5s ease-out;
134
+ transition: width .5s ease-out;
135
+ }
136
+
137
+ .b-dropzone {
138
+ position: relative;
139
+ border: 1px dashed #babbbf;
140
+ margin: 2% 0 7%;
141
+ &.active {
142
+ }
143
+ }
144
+
145
+ .b-dropzone__bg, .b-dropzone__txt {
146
+ position: absolute;
147
+ .b-dropzone.active & {display: block;}
148
+ }
149
+
150
+ .b-dropzone__bg {
151
+ top: 0;
152
+ left: 0;
153
+ right: 0;
154
+ bottom: 0;
155
+ z-index: 30000;
156
+ opacity: .2;
157
+ // background:#EEDA7C;
158
+ .active & {
159
+ background-color: #2D9DD7;
160
+
161
+ }
162
+ }
163
+
164
+ .b-dropzone__txt {
165
+ // color: rgb(168, 162, 94);
166
+ .active & {color: #1C81C7;}
167
+ text-align: center;
168
+ width: 500px;
169
+ top: 50%;
170
+ left: 50%;
171
+ margin: -50px 0 0 -250px;
172
+ z-index: 30001;
173
+ line-height: 100px;
174
+ font-size: 13px;
175
+ }
@@ -0,0 +1,108 @@
1
+ @import "compass";
2
+ dl.redditor {
3
+ dd {
4
+ /*нельзя задавать position-relative, иначе глючит сортировка в хроме*/
5
+ margin: 10px -10px; padding:10px; background:#efefef;
6
+ border: 1px solid #e8e8e8;
7
+ .handle {
8
+ width:20px; height: 20px; float: left;
9
+ background: image-url('redditor/move_handler.png') center no-repeat;
10
+ cursor: move;
11
+ }
12
+ }
13
+ &.now-sortable dd {
14
+ height: 50px !important; overflow: hidden;
15
+ .tit-form {display: block;}
16
+ }
17
+ label.delete {
18
+ position: absolute; left:100%; bottom: 100%; white-space:nowrap;
19
+ @include transform(rotate(90deg));
20
+ @include transform-origin(0, 100%);
21
+ }
22
+ .ui-sortable-helper, .ui-sortable-placeholder {
23
+ /*max-height: 200px !important; overflow: hidden;*/
24
+ }
25
+ .upload-area {
26
+ overflow: hidden; margin-top: 10px;
27
+ }
28
+ }
29
+
30
+ ul.slider-block-images {
31
+ overflow: hidden;
32
+ li {
33
+ margin: 0 5px 5px 0; list-style: none;
34
+ float: left; position: relative;
35
+ border: 1px solid #e8e8e8;
36
+ background: #fff;
37
+ img {display: block;}
38
+ }
39
+ }
40
+
41
+ div.redditor-add-blocks {
42
+ margin:10px -10px; padding:10px;
43
+ > p {
44
+ overflow: hidden;
45
+ }
46
+ }
47
+ .control-data {float: right;}
48
+ .delete-data, .update-data {
49
+ text-decoration: none;
50
+ display: inline-block;
51
+ text-align: center; min-width: 10px; padding: 0 5px;
52
+ font-size: 10px; line-height: 20px;
53
+ border: 1px solid #C2C2C2; border-radius: 15px;
54
+ background: #F8F8F8;
55
+ }
56
+ .delete-data { color: #A72522;}
57
+ .update-data { color: green;}
58
+
59
+ .form-name {
60
+ margin-top: 25px;
61
+ }
62
+ .tit-form {
63
+ display: none; margin-top: -25px; text-align: center; font-size: 18px;
64
+ line-height: 30px; vertical-align: middle;
65
+ img { width: 30px; display: inline-block; vertical-align: middle;}
66
+ }
67
+ .line-form {
68
+ display: inline-block; margin-right: 5px;
69
+ }
70
+ .del-item {
71
+ text-decoration: none; position: absolute; right: 1px; bottom: 1px;
72
+ width: 22px; height: 22px;
73
+ background: #eee image-url('redditor/trash.png') center no-repeat;
74
+ border-radius: 15px; border: 1px solid #aaa;
75
+ }
76
+ .full-width {
77
+ width: 100%; box-sizing: border-box;
78
+ }
79
+ .add-txt, .add-video, .add-photo, .add-slider {
80
+ text-decoration: none; color: #222; float: left; padding: 4px 10px 4px 25px;
81
+ border-radius: 3px; border: 1px solid #ccc; font-size: 11px; margin-right: 3px;
82
+ }
83
+ .add-txt {
84
+ @include background(image-url('redditor/add_txt.png') 3px center no-repeat, linear-gradient(top, #fff 0%, #f5f5f5 49%, #ececec 50%, #eee 100%));
85
+ }
86
+ .add-video {
87
+ @include background(image-url('redditor/add_video.png') 3px center no-repeat, linear-gradient(top, #fff 0%, #f5f5f5 49%, #ececec 50%, #eee 100%));
88
+ }
89
+ .add-photo {
90
+ @include background(image-url('redditor/add_photo.png') 3px center no-repeat, linear-gradient(top, #fff 0%, #f5f5f5 49%, #ececec 50%, #eee 100%));
91
+ }
92
+ .add-slider {
93
+ @include background(image-url('redditor/add_slider.png') 3px center no-repeat, linear-gradient(top, #fff 0%, #f5f5f5 49%, #ececec 50%, #eee 100%));
94
+ }
95
+ a.redactor_btn_format {
96
+ background: image-url('redditor/no_format_text.png') center no-repeat !important;
97
+ }
98
+ a.redactor_btn_divide {
99
+ background: image-url('redditor/destroy_block_text.png') center no-repeat !important;
100
+ }
101
+ // dl.redditor dd:before {
102
+ // content: "class: " attr(class); display: block; padding: 2px; background: #fcc;
103
+ // }
104
+
105
+ // dl.redditor div.form-name:before {
106
+ // content: "object-name: " attr(data-object-name) "\A id: " attr(id); display: block; padding: 2px; background: #ffc;
107
+ // white-space: pre;
108
+ // }
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+
3
+ class Redditor::Admin::BaseController < ActionController::Base
4
+ layout false
5
+
6
+ before_filter :get_page
7
+
8
+ private
9
+
10
+ def get_page
11
+ @page = Redditor::Page.find(params[:page_id] || params[:id])
12
+ end
13
+
14
+ def content_block_params
15
+ params.require(:content_block).permit!
16
+ end
17
+
18
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ class Redditor::Admin::ImageBlocksController < Redditor::Admin::BaseController
4
+
5
+ def new
6
+ @content_block = @page.images.build(content_block_params)
7
+ render "redditor/admin/pages/new"
8
+ end
9
+
10
+ def update
11
+ @content_block = @page.images.find(params[:id])
12
+ @content_block.update_attributes(content_block_params)
13
+ render "redditor/admin/pages/wrapper"
14
+ end
15
+
16
+ def create
17
+ @content_block = @page.images.build(content_block_params)
18
+ @content_block.update_attributes(src: params[:file])
19
+ render "redditor/admin/pages/wrapper"
20
+ end
21
+
22
+ def destroy
23
+ @content_block = @page.images.find(params[:id])
24
+ if @content_block.destroy
25
+ render :js => "$('#image_#{@content_block.id}').closest('dd').remove();"
26
+ else
27
+ render :js => "alert('Контент-блок не удален');"
28
+ end
29
+ end
30
+
31
+ def update_post
32
+ @content_block = @page.images.find(params[:id])
33
+ @content_block.update_attributes(src: params[:file])
34
+ render "redditor/admin/pages/wrapper"
35
+ end
36
+
37
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ class Redditor::Admin::ImagesController < Redditor::Admin::BaseController
4
+
5
+ layout false
6
+
7
+ def sort
8
+ params[:slider_block_image].each_with_index do |id, idx|
9
+ p = Redditor::Image.find(id)
10
+ p.position = idx
11
+ p.save
12
+ end
13
+ render :nothing => true
14
+ end
15
+
16
+ def create
17
+ @slider_block = @page.slider_blocks.find(params[:slider_block_id])
18
+ @image = @slider_block.images.build(src: params[:file])
19
+ if @image.save
20
+ render "redditor/admin/pages/slider_block_image"
21
+ end
22
+ end
23
+
24
+ def destroy
25
+ @image = Redditor::Image.find(params[:id])
26
+ if @image.destroy
27
+ render :js => "$('#slider_block_image_#{@image.id}').remove()"
28
+ else
29
+ render :js => 'Ошибка! Изображение не было удалено.'
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+
3
+ class Redditor::Admin::PagesController < Redditor::Admin::BaseController
4
+ layout false
5
+
6
+ def sort
7
+ params[:sort].each do |k, v|
8
+ v.each do |klass, info|
9
+ klass.camelcase.constantize.find_by_id(info[:index]).update_attributes(position: info[:position]) rescue nil
10
+ end
11
+ end
12
+
13
+ render :nothing => true
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ class Redditor::Admin::SliderBlocksController < Redditor::Admin::BaseController
4
+
5
+ def new
6
+ @content_block = @page.slider_blocks.build(content_block_params)
7
+ render "redditor/admin/pages/new"
8
+ end
9
+
10
+ def update
11
+ @content_block = @page.slider_blocks.find(params[:id])
12
+ @content_block.update_attributes(content_block_params)
13
+ render "redditor/admin/pages/wrapper"
14
+ end
15
+
16
+ def create
17
+ temp_last_postion = @page.try(:content_blocks).try(:last).try(:position).to_i + 1
18
+ @content_block = @page.slider_blocks.build(content_block_params)
19
+ @content_block.update_attributes(position: temp_last_postion)
20
+ render "redditor/admin/pages/new"
21
+ end
22
+
23
+ def destroy
24
+ @content_block = @page.slider_blocks.find(params[:id])
25
+ if @content_block.destroy
26
+ render :js => "$('#slider_block_#{@content_block.id}').closest('dd').remove();"
27
+ else
28
+ render :js => "alert('Контент-блок не удален');"
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,31 @@
1
+ #coding: utf-8
2
+
3
+ class Redditor::Admin::TextBlocksController < Redditor::Admin::BaseController
4
+
5
+ def new
6
+ @content_block = @page.text_blocks.build(content_block_params)
7
+ render "redditor/admin/pages/new"
8
+ end
9
+
10
+ def update
11
+ @content_block = @page.text_blocks.find(params[:id])
12
+ @content_block.update_attributes(content_block_params)
13
+ render "redditor/admin/pages/wrapper"
14
+ end
15
+
16
+ def create
17
+ @content_block = @page.text_blocks.build(content_block_params)
18
+ @content_block.save
19
+ render "redditor/admin/pages/wrapper"
20
+ end
21
+
22
+ def destroy
23
+ @content_block = @page.text_blocks.find(params[:id])
24
+ if @content_block.destroy
25
+ render :js => "$('#text_block_#{@content_block.id}').closest('dd').remove();"
26
+ else
27
+ render :js => "alert('Контент-блок не удален');"
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ #coding: utf-8
2
+
3
+ class Redditor::Admin::VideoBlocksController < Redditor::Admin::BaseController
4
+
5
+ def new
6
+ @content_block = @page.video_blocks.build(content_block_params)
7
+ render "redditor/admin/pages/new"
8
+ end
9
+
10
+ def update
11
+ @content_block = @page.video_blocks.find(params[:id])
12
+ @content_block.update_attributes(content_block_params)
13
+ render "redditor/admin/pages/wrapper"
14
+ end
15
+
16
+ def create
17
+ @content_block = @page.video_blocks.build(content_block_params)
18
+ @content_block.save
19
+ render "redditor/admin/pages/wrapper"
20
+ end
21
+
22
+ def destroy
23
+ @content_block = @page.video_blocks.find(params[:id])
24
+ if @content_block.destroy
25
+ render :js => "$('#video_block_#{@content_block.id}').closest('dd').remove();"
26
+ else
27
+ render :js => "alert('Контент-блок не удален');"
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,4 @@
1
+ module Redditor
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Redditor
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ #coding: utf-8
2
+ module Redditor
3
+ module FileapiHelper
4
+
5
+ def fileapi url=nil
6
+ html = stylesheet_link_tag "redditor/fileapi/fileapi"
7
+ html += javascript_include_tag "redditor/fileapi/mailru"
8
+ if url.present?
9
+ html += javascript_tag do
10
+ %Q{FU.config.uploadUrl = "#{url}"}.html_safe
11
+ end
12
+ end
13
+ content_for(:js, html)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ module Redditor
4
+ module PagesHelper
5
+ def button_tag_add_fields(name, f, association)
6
+ new_object = f.object.send(association).klass.new
7
+ id = new_object.object_id
8
+ fields = f.fields_for(association, new_object, child_index: id) do |builder|
9
+ content_tag(:dd, :id => "#{association.to_s.singularize}_#{id}") do
10
+ tag(:div, class: "handle") +
11
+ link_to("Удалить", "javascript:void(0);", onclick: "if (confirm('dfasdsa')) $(this).closest('dd').remove();") + "\s" +
12
+ link_to("Обновить", [:admin, @article.page, association], method: "post", class: "update-data", remote: true, data: {disable_with: "Обновляется"}) + "\s" +
13
+ render("admin/pages/" + association.to_s.singularize, f: builder)
14
+ end
15
+ end
16
+
17
+ button_tag(name, class: "add_fields", type: "button", data: {id: id, fields: fields.gsub("\n", "")})
18
+ end
19
+
20
+ def redditor_validate f
21
+ render "redditor/admin/pages/validate", {f: f}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ module Redditor
3
+ class ContentBlock < ActiveRecord::Base
4
+
5
+ def self.find_by_position_and_type(position, type, page_id)
6
+ type.to_s.sub("s_attributes", "").camelcase.constantize.where(page_id: page_id, position: position).first
7
+ end
8
+
9
+ def self.init_by_type(type, params)
10
+ res = type.to_s.sub("s_attributes", "").camelcase.constantize.new(params)
11
+ res.valid?
12
+ res
13
+ end
14
+
15
+ def self.check_by_position_and_type position, type, page_id
16
+ type.to_s.sub("s_attributes", "").camelcase.constantize.where(page_id: page_id, position: position).any?
17
+ end
18
+
19
+ # def self.model_name
20
+ # ActiveModel::Name.new(self, nil, self.class.name.gsub("Redditor::", ''))
21
+ # end
22
+
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ module Redditor
4
+ class Image < ActiveRecord::Base
5
+ self.table_name = "redditor_images"
6
+
7
+ after_initialize :default_values # чтобы файл загружался, пока через html5 не передаем позицию
8
+
9
+ # attr_accessible :descr, :imageable_id, :imageable_type, :position, :src, :temp_id
10
+ attr_accessor :temp_id
11
+
12
+ mount_uploader :src, RedditorUploader
13
+
14
+ validates :src, :presence => true
15
+
16
+ belongs_to :imageable, :polymorphic => true
17
+
18
+ default_scope -> { order(:position) }
19
+
20
+ def self.model_name
21
+ ActiveModel::Name.new(self, nil, 'Image')
22
+ end
23
+
24
+ private
25
+ def default_values
26
+ self.position ||= 1000
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ module Redditor
4
+ class Page < ActiveRecord::Base
5
+ self.table_name = "redditor_pages"
6
+
7
+ # attr_accessible :pageable_id, :pageable_type, :metakey, :metadesc, :text_blocks_attributes, :video_blocks_attributes, :images_attributes, :slider_blocks_attributes
8
+
9
+ belongs_to :pageable, :polymorphic => true
10
+ has_many :text_blocks, :class_name => "Redditor::TextBlock"
11
+ has_many :video_blocks, :class_name => "Redditor::VideoBlock"
12
+ has_many :images, :as => :imageable
13
+ has_many :slider_blocks, :class_name => "Redditor::SliderBlock"
14
+
15
+ accepts_nested_attributes_for :text_blocks, :allow_destroy => true
16
+ accepts_nested_attributes_for :video_blocks, :allow_destroy => true
17
+ accepts_nested_attributes_for :slider_blocks, :allow_destroy => true
18
+ accepts_nested_attributes_for :images, :allow_destroy => true
19
+
20
+ def self.model_name
21
+ ActiveModel::Name.new(self, nil, 'Page')
22
+ end
23
+
24
+ def content_blocks
25
+ (self.text_blocks + self.video_blocks + self.images + self.slider_blocks).sort {|x, y| x.position <=> y.position}
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+
3
+ module Redditor
4
+ class SliderBlock < ActiveRecord::Base
5
+ self.table_name = "redditor_slider_blocks"
6
+
7
+ # attr_accessible :page_id, :position, :temp_id
8
+ attr_accessor :temp_id
9
+
10
+ belongs_to :page, :class_name => "Redditor::Page"
11
+ has_many :images, :as => :imageable, :dependent => :destroy
12
+
13
+ def self.model_name
14
+ ActiveModel::Name.new(self, nil, 'SliderBlock')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+
3
+ module Redditor
4
+ class TextBlock < ActiveRecord::Base
5
+ self.table_name = "redditor_text_blocks"
6
+
7
+ # attr_accessible :body, :page_id, :position, :temp_id, :translations_attributes
8
+ attr_accessor :temp_id
9
+
10
+ belongs_to :page, :class_name => "Redditor::Page"
11
+
12
+ default_scope -> { order(:position) }
13
+
14
+ validates :position, :body, :presence => true
15
+
16
+ def self.model_name
17
+ ActiveModel::Name.new(self, nil, 'TextBlock')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ #coding: utf-8
2
+
3
+ class YoutubeValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ if value =~ /[^A-z0-9_-]/
6
+ record.errors[attribute] << (options[:message] || "- используются недопустимые символы")
7
+ end
8
+ end
9
+ end
10
+
11
+
12
+ module Redditor
13
+ class VideoBlock < ActiveRecord::Base
14
+ self.table_name = "redditor_video_blocks"
15
+
16
+ # attr_accessible :height, :page_id, :position, :width, :youtube, :temp_id
17
+ attr_accessor :temp_id
18
+
19
+ validates :youtube, :length => { :is => 11 }, :youtube => true
20
+
21
+ belongs_to :page, :class_name => "Redditor::Page"
22
+
23
+ def self.model_name
24
+ ActiveModel::Name.new(self, nil, 'VideoBlock')
25
+ end
26
+ end
27
+ end