rad_kit 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/lib/components/captcha.rb +4 -4
  2. data/lib/components/kit.rb +5 -5
  3. data/lib/components/kit.yml +0 -2
  4. data/lib/components/models.rb +2 -5
  5. data/lib/components/models.yml +3 -0
  6. data/lib/kit/controller/authorized.rb +9 -8
  7. data/lib/kit/controller/captcha.rb +6 -6
  8. data/lib/kit/controller/localized.rb +2 -2
  9. data/lib/kit/gems.rb +12 -8
  10. data/lib/kit/i18n.rb +3 -3
  11. data/lib/kit/i18n/locales/ru/pluralization.rb +3 -3
  12. data/lib/kit/kit.rb +7 -7
  13. data/lib/kit/kit_text_utils.rb +6 -6
  14. data/lib/kit/misc/prepare_model.rb +4 -4
  15. data/lib/kit/models.rb +22 -5
  16. data/lib/kit/models/attachment_file.rb +27 -0
  17. data/lib/kit/models/{attachments_uploader_helper.rb → attachments_helper.rb} +34 -28
  18. data/lib/kit/models/authorized.rb +64 -63
  19. data/lib/kit/models/authorized_object.rb +70 -73
  20. data/lib/kit/models/base_file.rb +37 -0
  21. data/lib/kit/models/config.rb +30 -0
  22. data/lib/kit/models/indexes.rb +30 -0
  23. data/lib/kit/models/miscellaneous.rb +7 -1
  24. data/lib/kit/models/role.rb +17 -17
  25. data/lib/kit/models/tags.rb +71 -0
  26. data/lib/kit/models/tags_mixin.rb +39 -0
  27. data/lib/kit/mongodb_model.rb +13 -0
  28. data/lib/kit/mongodb_model/text_processor.rb +32 -0
  29. data/lib/kit/spec.rb +30 -30
  30. data/lib/kit/spec/items_controller_crud.rb +9 -9
  31. data/lib/kit/support.rb +1 -1
  32. data/lib/kit/tasks.rb +3 -7
  33. data/lib/text_utils.rb +2 -2
  34. data/lib/text_utils/code_highlighter.rb +17 -17
  35. data/lib/text_utils/custom_markdown.rb +7 -7
  36. data/lib/text_utils/ensure_utf.rb +3 -3
  37. data/lib/text_utils/format_qualifier.rb +2 -2
  38. data/lib/text_utils/html_sanitizer.rb +9 -9
  39. data/lib/text_utils/markdown.rb +9 -9
  40. data/lib/text_utils/pipe.rb +1 -1
  41. data/lib/text_utils/processor.rb +3 -3
  42. data/lib/text_utils/support.rb +3 -3
  43. data/lib/text_utils/truncate.rb +4 -4
  44. data/readme.md +3 -1
  45. data/spec/controller/authorization_spec.rb +45 -45
  46. data/spec/controller/captcha_spec.rb +18 -18
  47. data/spec/controller/comments_spec.rb +16 -14
  48. data/spec/controller/items_spec.rb +16 -17
  49. data/spec/i18n/i18n_spec.rb +5 -5
  50. data/spec/misc/kit_text_utils_spec.rb +5 -5
  51. data/spec/misc/prepare_model_spec.rb +6 -6
  52. data/spec/misc/user_error_spec.rb +8 -8
  53. data/spec/models/{attachments_uploader_helper_spec.rb → attachments_helper_spec.rb} +46 -50
  54. data/spec/models/{attachments_uploader_helper_spec → attachments_helper_spec}/v1/a.txt +0 -0
  55. data/spec/models/{attachments_uploader_helper_spec → attachments_helper_spec}/v1/b.txt +0 -0
  56. data/spec/models/{attachments_uploader_helper_spec → attachments_helper_spec}/v2/a.txt +0 -0
  57. data/spec/models/attachments_spec.rb +4 -7
  58. data/spec/models/authorization_spec.rb +15 -15
  59. data/spec/models/authorized_object_spec.rb +75 -75
  60. data/spec/models/item_spec.rb +44 -40
  61. data/spec/models/role_spec.rb +4 -4
  62. data/spec/models/tags_spec.rb +47 -21
  63. data/spec/models/uploader_spec.rb +13 -23
  64. data/spec/mongodb_model/text_processor_spec.rb +26 -0
  65. data/spec/spec_helper.rb +6 -4
  66. data/spec/spec_helper/factories.rb +3 -3
  67. data/spec/spec_helper/user.rb +4 -7
  68. data/spec/text_utils/code_highlighter_spec.rb +7 -7
  69. data/spec/text_utils/custom_markdown_spec.rb +14 -14
  70. data/spec/text_utils/format_qualifier_spec.rb +6 -6
  71. data/spec/text_utils/html_sanitizer_spec.rb +15 -15
  72. data/spec/text_utils/markdown_spec.rb +17 -17
  73. data/spec/text_utils/pipe_spec.rb +5 -5
  74. data/spec/text_utils/spec_helper.rb +1 -1
  75. data/spec/text_utils/text_processor_shared.rb +1 -1
  76. data/spec/text_utils/truncate_spec.rb +5 -5
  77. metadata +118 -114
  78. data/lib/kit/models/attachment_uploader.rb +0 -15
  79. data/lib/kit/models/file_uploader.rb +0 -26
  80. data/lib/kit/models_after.rb +0 -27
  81. data/lib/kit/mongoid.rb +0 -22
  82. data/lib/kit/mongoid/rad_miscellaneous.rb +0 -36
  83. data/lib/kit/mongoid/text_processor.rb +0 -44
  84. data/spec/mongoid/basic_spec.rb +0 -36
@@ -1,15 +0,0 @@
1
- class Models::AttachmentUploader < Models::FileUploader
2
- rad.extension :attachment_file_path, self do
3
- define_method :file_path do
4
- "#{rad.kit.fs_prefix}/#{model.item.id}"
5
- end
6
- end
7
-
8
- version :icon do
9
- process resize_to_fit: [50, 50]
10
- end
11
-
12
- version :thumb do
13
- process resize_to_fit: [150, 150]
14
- end
15
- end
@@ -1,26 +0,0 @@
1
- require 'carrierwave/processing/mini_magick'
2
-
3
- class Models::FileUploader < CarrierWave::Uploader::Base
4
- include CarrierWave::MiniMagick
5
-
6
- storage rad.config.fs_type
7
-
8
- # def sanitize_regexp
9
- # /[^[:word:]\.\-\+\s_]/i
10
- # end
11
-
12
- def file_path
13
- "#{rad.config.fs_prefix}/system/#{model.class.model_name.underscore}/#{model.id}"
14
- end
15
-
16
- def store_dir
17
- "#{root}#{file_path}"
18
- end
19
-
20
- def extension_white_list
21
- [/.*/]
22
- end
23
-
24
- def cache_dir; rad.config.fs_cache_path end
25
- def root; rad.config.fs_path end
26
- end
@@ -1,27 +0,0 @@
1
- # use database config if provided
2
- if rad.models.config
3
- b = lambda do
4
- Mongoid.configure do |config|
5
- config.logger = rad.logger
6
- end
7
- Mongoid.from_hash rad.models.config
8
- end
9
-
10
- # hiding MongoDB connecting messages
11
- rad.logger.respond_to?(:silence) ? rad.logger.silence(&b) : b.call
12
- end
13
-
14
-
15
- %w(
16
- miscellaneous
17
- role
18
- authorized
19
- authorized_object
20
- file_uploader
21
- attachments_uploader_helper
22
- attachment_uploader
23
- ).each{|n| require "kit/models/#{n}"}
24
-
25
- Mongoid::Document.class_eval do
26
- include Mongoid::AttachmentsUploaderHelper
27
- end
data/lib/kit/mongoid.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'mongoid_misc'
2
- require 'carrierwave_ext'
3
- require 'rad'
4
-
5
- #
6
- # Attribute protection
7
- #
8
- Mongoid::Document.included do
9
- attr_protected :id, :_id, :_type, :created_at, :updated_at
10
- end
11
-
12
- module Models
13
- end
14
-
15
- %w(
16
- text_processor
17
- rad_miscellaneous
18
- ).each{|n| require "kit/mongoid/#{n}"}
19
-
20
- (rad.extension(:mm_plugins){[]} + [Mongoid::RadMiscellaneous]).each do |plugin|
21
- Mongoid::Document.include plugin
22
- end
@@ -1,36 +0,0 @@
1
- module Mongoid::RadMiscellaneous
2
- extend ActiveSupport::Concern
3
-
4
- delegate :t, to: I18n
5
-
6
- def to_rson options = {}
7
- with_errors = if options.include?('errors')
8
- options.delete 'errors'
9
- elsif options.include?(:errors)
10
- options.delete :errors
11
- else
12
- true
13
- end
14
-
15
- # standard MongoMaper as_json conversion
16
- hash = as_json(options)
17
-
18
- # MongoMaper fix
19
- hash['id'] = hash.delete('_id').to_s if hash.include? '_id'
20
-
21
- # adding errors
22
- if with_errors
23
- errors = {}
24
- errors.each do |name, list|
25
- errors[name.to_s] = list
26
- end
27
- hash['errors'] = errors unless errors.empty?
28
- end
29
-
30
- hash
31
- end
32
-
33
- module ClassMethods
34
- delegate :t, to: I18n
35
- end
36
- end
@@ -1,44 +0,0 @@
1
- module Mongoid::TextProcessor
2
- extend ActiveSupport::Concern
3
-
4
- module ClassMethods
5
- def markup_field attr_name, opt = {}
6
- attr_name = attr_name.to_s
7
- opt = opt.to_openobject
8
- original_attr_name = "original_#{attr_name}"
9
-
10
- field original_attr_name, type: String, default: ''
11
- field attr_name, type: String, protected: true, default: '' unless fields.include? attr_name
12
-
13
- validates_presence_of attr_name, original_attr_name if opt.required?
14
-
15
- alias_method "#{attr_name}_without_markup=", "#{attr_name}="
16
- alias_method "#{original_attr_name}_without_markup=", "#{original_attr_name}="
17
-
18
- define_method "#{attr_name}=" do |value|
19
- send "#{original_attr_name}_without_markup=", value
20
- send "#{attr_name}_without_markup=", value
21
- end
22
-
23
- define_method "#{original_attr_name}=" do |value|
24
- send "#{original_attr_name}_without_markup=", value
25
- send "#{attr_name}_without_markup=", TextUtils.markup(value)
26
- end
27
-
28
- define_method "#{attr_name}_as_text" do
29
- value = send(attr_name)
30
- return "" if value.blank?
31
- Nokogiri::XML(value).content
32
- end
33
-
34
- ce_method_name = "copy_errors_for_#{attr_name}"
35
- define_method ce_method_name do
36
- if !errors.include?(original_attr_name) and errors.include?(attr_name)
37
- errors.add original_attr_name, errors[attr_name]
38
- end
39
- end
40
- after_validation ce_method_name
41
- end
42
- end
43
-
44
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Rad Mongoid basics" do
4
- with_mongoid
5
-
6
- after(:all){remove_constants :ToRsonTest}
7
-
8
- it "to_rson" do
9
- class ToRsonTest
10
- include Mongoid::Document
11
-
12
- field :name, type: String
13
- field :text, type: String
14
- validates_presence_of :name
15
- end
16
- ToRsonTest.delete_all
17
-
18
- ToRsonTest.create! name: 'a'
19
- ToRsonTest.create! name: 'b'
20
-
21
- # model.to_rson
22
- o = ToRsonTest.first
23
- r = o.to_rson
24
- r.delete 'id'
25
- r.should == {"name" => "a"}
26
-
27
- o.to_rson(only: :name).should == {"name" => "a"}
28
-
29
- # collections.to_rson
30
- r = ToRsonTest.all.to_rson
31
- r.collect!{|h| h.delete('id'); h}
32
- r.should == [{"name" => "a"}, {"name" => "b"}]
33
-
34
- ToRsonTest.all.to_rson(only: :name).should == [{"name" => "a"}, {"name" => "b"}]
35
- end
36
- end