redditor 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04ff6d5b84a9af7e952457bf4152e61e452cfd45
4
- data.tar.gz: 14883d81bbe9394caf1dc7df81389e9d6951d1a3
3
+ metadata.gz: e399c8e0938274cca6da98a2c382d4b818bf9f4d
4
+ data.tar.gz: 200d213665eec8faea1909f83b82b8c31a26a564
5
5
  SHA512:
6
- metadata.gz: 45c34e057d72a2ede65fc11562fdc55facaf642c371c6eb28aa62877cbf1bc3812429aef85c51a1530a327f46c1f9d9346fa7eed8dd037d0a2f4f83c1d300835
7
- data.tar.gz: 996b6f0500b2900fdb13a16cb95f1242111fef407425ae5a960ac16baffa919cff86697310f61b38ab0c148acca0d7ce365582f5fd42b94db0f01126825d265c
6
+ metadata.gz: 9629b1b6dbc4701d51a966074e5a2e3a066c7c8a1555ee39ec306a930a2c520349fb61f16642316c596f5c8d9efbef6e9efabe5ad4ccae9e16787d88d4664766
7
+ data.tar.gz: 25a9e5ac05f6e212b2dd2c25e4a40be25741ce79b94cddcca9b7bcd4518e86a041faf58262cf6de692e4c29bae0c7b85d43ae53d6e7e9e982718db7792e1fddd
@@ -13,15 +13,13 @@ module Redditor
13
13
  def redditor_form(f, &block)
14
14
  id = "#{real_name(f.object)}_"
15
15
  id += f.object.id.nil? ? "#{f.object.object_id}" : "#{f.object.id}"
16
- if f.object.object_id.present?
17
- f.object_name.sub!(/\[\d*\]/, "[#{f.object.object_id}]")
18
- end
16
+ f.object_name.sub!(/\[\d*\]/, "[#{f.object.object_id}]") if f.object.object_id.present?
19
17
  index = if f.object.object_id.present?
20
18
  f.object.object_id
21
19
  else
22
20
  f.index
23
21
  end
24
- data = {'object-name' => f.object_name, 'object-id' => index}
22
+ data = { 'object-name' => f.object_name, 'object-id' => index }
25
23
  content_tag(:div, capture(&block), class: 'redditor__form', id: id, data: data)
26
24
  end
27
25
 
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  module Redditor
4
2
  class Image < ActiveRecord::Base
5
3
  self.table_name = "redditor_images"
@@ -5,10 +5,11 @@ module Redditor
5
5
  self.table_name = "redditor_pages"
6
6
 
7
7
  belongs_to :pageable, polymorphic: true, touch: true
8
- has_many :text_blocks, class_name: "Redditor::TextBlock"
9
- has_many :video_blocks, class_name: "Redditor::VideoBlock"
10
- has_many :images, as: :imageable, class_name: "Redditor::Image"
11
- has_many :slider_blocks, class_name: "Redditor::SliderBlock"
8
+
9
+ has_many :text_blocks, class_name: "::Redditor::TextBlock"
10
+ has_many :video_blocks, class_name: "::Redditor::VideoBlock"
11
+ has_many :images, as: :imageable, class_name: "::Redditor::Image"
12
+ has_many :slider_blocks, class_name: "::Redditor::SliderBlock"
12
13
 
13
14
  accepts_nested_attributes_for :text_blocks, allow_destroy: true
14
15
  accepts_nested_attributes_for :video_blocks, allow_destroy: true
@@ -20,7 +21,7 @@ module Redditor
20
21
  end
21
22
 
22
23
  def content_blocks
23
- (self.text_blocks + self.video_blocks + self.images + self.slider_blocks).sort {|x, y| x.position <=> y.position}
24
+ (text_blocks + video_blocks + images + slider_blocks).sort {|x, y| x.position <=> y.position}
24
25
  end
25
26
  end
26
27
  end
@@ -6,8 +6,8 @@ module Redditor
6
6
 
7
7
  attr_accessor :object_id, :kind
8
8
 
9
- belongs_to :page, class_name: "Redditor::Page", touch: true
10
- has_many :images, as: :imageable, dependent: :destroy
9
+ belongs_to :page, class_name: "::Redditor::Page", touch: true
10
+ has_many :images, as: :imageable, dependent: :destroy, class_name: "::Redditor::Image"
11
11
  accepts_nested_attributes_for :images
12
12
 
13
13
  def self.model_name
@@ -6,7 +6,7 @@ module Redditor
6
6
 
7
7
  attr_accessor :object_id
8
8
 
9
- belongs_to :page, class_name: "Redditor::Page", touch: true
9
+ belongs_to :page, class_name: "::Redditor::Page", touch: true
10
10
 
11
11
  default_scope -> { order(:position) }
12
12
 
@@ -1,14 +1,3 @@
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
1
  module Redditor
13
2
  class VideoBlock < ActiveRecord::Base
14
3
  self.table_name = "redditor_video_blocks"
@@ -17,7 +6,7 @@ module Redditor
17
6
 
18
7
  validates :youtube, length: { is: 11 }, youtube: true
19
8
 
20
- belongs_to :page, class_name: "Redditor::Page", touch: true
9
+ belongs_to :page, class_name: "::Redditor::Page", touch: true
21
10
 
22
11
  def self.model_name
23
12
  ActiveModel::Name.new(self, nil, 'VideoBlock')
@@ -0,0 +1,5 @@
1
+ class YoutubeValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ record.errors[attribute] << (options[:message] || "- используются недопустимые символы") if value =~ /[^A-z0-9_-]/
4
+ end
5
+ end
@@ -1,8 +1,9 @@
1
1
  = f.fields_for :page, f.object.page do |p|
2
2
 
3
3
  - unless f.object.new_record?
4
- %dl#redditor.redditor{data: {"sort-url" => url_for(redditor.sort_admin_page_path(p.object))}}
5
- = render partial: "redditor/admin/content_block", collection: p.object.content_blocks, locals: {p: p, page: p.object}, layout: 'redditor/admin/wrap'
4
+ %dl#redditor.redditor{ data: {"sort-url" => url_for(redditor.sort_admin_page_path(p.object)) } }
5
+ / = render partial: "redditor/admin/content_block", collection: p.object.content_blocks, locals: { p: p, page: p.object }, layout: 'redditor/admin/wrap'
6
+ = p.object.content_blocks.to_json
6
7
 
7
8
  %div.redditor__add-blocks
8
9
  %p
@@ -1,3 +1,3 @@
1
1
  module Redditor
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
@@ -2,6 +2,24 @@
2
2
 
3
3
  class Admin::ArticlesController < Admin::BaseController
4
4
 
5
+ def index
6
+ @articles = Article.all
7
+ end
8
+
9
+ def new
10
+ @article = Article.new
11
+ render "edit"
12
+ end
13
+
14
+ def create
15
+ @article = Article.new(article_params)
16
+ if @article.save
17
+ redirect_to [:edit, :admin, @article], notice: "Article created"
18
+ else
19
+ render "edit", alert: "Error"
20
+ end
21
+ end
22
+
5
23
  def edit
6
24
  @article = Article.find(params[:id])
7
25
  @article.build_page.save unless @article.page
@@ -14,6 +32,9 @@ class Admin::ArticlesController < Admin::BaseController
14
32
  end
15
33
 
16
34
  def destroy
35
+ @article = Article.find(params[:id])
36
+ @article.destroy
37
+ redirect_to [:admin, :articles]
17
38
  end
18
39
 
19
40
  private
@@ -1,4 +1,5 @@
1
- %h1 Edit article
1
+ %h1 Article editor
2
+ %p= link_to "back", [:admin, :articles]
2
3
 
3
4
  = form_for [:admin, @article], html: {multipart: true} do |f|
4
5
  %ul.errors
@@ -0,0 +1,8 @@
1
+ %h1 Articles
2
+ %p= link_to 'add', [:new, :admin, :article]
3
+
4
+ %ul
5
+ - @articles.all.each do |article|
6
+ %li
7
+ = link_to article.title, [:edit, :admin, article]
8
+ = link_to 'x', [:admin, article], method: :delete, data: { confirm: "Really delete?" }
@@ -5,6 +5,6 @@ Rails.application.routes.draw do
5
5
  resources :articles, only: [:show]
6
6
 
7
7
  namespace :admin do
8
- resources :articles, only: [:edit, :update]
8
+ resources :articles
9
9
  end
10
10
  end
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ require 'capybara/rails'
14
14
  require 'capybara/rspec'
15
15
  require 'capybara/poltergeist'
16
16
 
17
- Capybara.default_wait_time = ENV['CAPYBARA_WAIT_TIME'].present? ? ENV['CAPYBARA_WAIT_TIME'].to_i : 5
17
+ Capybara.default_wait_time = ENV['CAPYBARA_WAIT_TIME'].present? ? ENV['CAPYBARA_WAIT_TIME'].to_i : 10
18
18
 
19
19
  Capybara.register_driver :poltergeist do |app|
20
20
  Capybara::Poltergeist::Driver.new(app, {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Bovykin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-17 00:00:00.000000000 Z
12
+ date: 2014-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -177,6 +177,7 @@ files:
177
177
  - app/models/redditor/text_block.rb
178
178
  - app/models/redditor/video_block.rb
179
179
  - app/uploaders/redditor_uploader.rb
180
+ - app/validators/youtube_validator.rb
180
181
  - app/views/layouts/redditor/application.html.erb
181
182
  - app/views/redditor/admin/_content_block.haml
182
183
  - app/views/redditor/admin/_image.haml
@@ -245,6 +246,7 @@ files:
245
246
  - spec/dummy/app/models/article.rb
246
247
  - spec/dummy/app/models/concerns/.keep
247
248
  - spec/dummy/app/views/admin/articles/edit.html.haml
249
+ - spec/dummy/app/views/admin/articles/index.html.haml
248
250
  - spec/dummy/app/views/articles/show.html.haml
249
251
  - spec/dummy/app/views/layouts/application.html.erb
250
252
  - spec/dummy/bin/bundle
@@ -344,6 +346,7 @@ test_files:
344
346
  - spec/dummy/app/models/article.rb
345
347
  - spec/dummy/app/models/concerns/.keep
346
348
  - spec/dummy/app/views/admin/articles/edit.html.haml
349
+ - spec/dummy/app/views/admin/articles/index.html.haml
347
350
  - spec/dummy/app/views/articles/show.html.haml
348
351
  - spec/dummy/app/views/layouts/application.html.erb
349
352
  - spec/dummy/bin/bundle