rails_admin_comments 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9febe88a376f4232264f3dfd6e79c83817f209f
4
+ data.tar.gz: 9b227c1018f97ee6ff00ee2b4e873ecd5aae5c57
5
+ SHA512:
6
+ metadata.gz: c4ab99cc9ec64650c4f78bfd1b910540c45ee6c41b53f2aa61c9a1f475de0f17ddce4f38ca0c4f314b7b0585f49f4a4d7e639ffe520f1ffed376137b6c6c08e3
7
+ data.tar.gz: 429c3ff63b85d5ec570e1e3e836d91b5d03009feaba1f131cca6f3956fca3f8d840bc7b1ad1b4565578fe63975b8323956d3276210afc883c67691f1904cc233
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ rails_admin_settings
@@ -0,0 +1 @@
1
+ 2.2.3
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_admin_comments.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # RailsAdminComments DEVELOPMENT VERSION
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_admin_comments`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails_admin_comments'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails_admin_comments
22
+
23
+ ## Usage
24
+
25
+ Add in model what you need to be commentable
26
+
27
+ ```ruby
28
+ include RailsAdminComments::Commentable
29
+ ```
30
+
31
+ And add action available for this model_name
32
+
33
+ ```ruby
34
+ comments do
35
+ visible do
36
+ [
37
+ "SomeModel"
38
+ ].include? bindings[:abstract_model].model_name
39
+ end
40
+ end
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/enjoycreative/rails_admin_comments.
52
+
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ $(document).delegate ".comment_edit_form_link", 'click', (e)->
2
+ e.preventDefault()
3
+ link = $(e.currentTarget)
4
+ target = $(link.attr('href'))
5
+ $('.comment_edit_form').addClass('hidden').closest('.comment_block').find(".content_block").removeClass('hidden')
6
+ target.removeClass('hidden').closest('.comment_block').find(".content_block").addClass('hidden')
@@ -0,0 +1,25 @@
1
+ #rails_admin_comments
2
+ .hidden
3
+ display: none
4
+
5
+ .error
6
+ color: red
7
+
8
+ .success
9
+ color: green
10
+
11
+ .comment_block
12
+ .creator_link
13
+ margin-left: 10px
14
+ .created_at
15
+ margin-left: 10px
16
+ .updated_at
17
+ margin-left: 2px
18
+ .comment_edit_form_link
19
+ margin-left: 10px
20
+ text-decoration: none
21
+ border-bottom: 1px dotted
22
+
23
+ textarea
24
+ width: 70%
25
+ height: 200px
@@ -0,0 +1,8 @@
1
+ module RailsAdminComments
2
+ module Commentable
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ has_many :rails_admin_comments, as: :rails_admin_commentable, class_name: "RailsAdminComments::Comment"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ if RailsAdminComments.active_record?
2
+ module RailsAdminComments
3
+ class Comment < ActiveRecord::Base
4
+ end
5
+ end
6
+ end
7
+
8
+ module RailsAdminComments
9
+ class Comment
10
+ #binding.pry
11
+ if RailsAdminComments.mongoid?
12
+ include RailsAdminComments::Mongoid
13
+ end
14
+
15
+ if RailsAdminComments.active_record?
16
+ self.table_name = "rails_admin_comments"
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ #rails_admin_comments_wrapper
2
+ = stylesheet_link_tag 'rails_admin/rails_admin_comments'
3
+ = javascript_include_tag 'rails_admin/rails_admin_comments'
4
+
5
+ #rails_admin_comments
6
+
7
+ - url = comments_path(model_name: @abstract_model, id: @object.id)
8
+ .controls
9
+ - @comments.each do |c|
10
+ .comment_block
11
+ - edit_form_id = "comment_#{c.id}_edit"
12
+ p
13
+ - creator = c.creator
14
+ - if creator
15
+ - model_name = creator.class.to_param.gsub("::", "~").underscore
16
+ = link_to creator.name_for_rails_admin, show_path(model_name: model_name, id: creator._id), class: "creator_link"
17
+ span.created_at= Russian::strftime c.c_at, "%d.%m.%Y в %H:%M:%S"
18
+ span.updated_at= " (изм. #{Russian::strftime c.u_at, "%d.%m.%Y в %H:%M:%S"})" if Russian::strftime c.u_at
19
+ = link_to 'изменить', "##{edit_form_id}", class: 'comment_edit_form_link' if creator == current_user
20
+ p.content_block= c.content
21
+ p
22
+ .comment_edit_form.hidden{id="#{edit_form_id}"}
23
+ - if @comment and @comment._id == c._id
24
+ - c = @comment
25
+ - unless @message.blank?
26
+ p== @message
27
+ - @comment = @message = nil
28
+
29
+ = form_for c, url: url, method: :post do |f|
30
+ p= f.hidden_field :id
31
+ p= f.text_area :content
32
+ p= f.submit
33
+ br
34
+
35
+ hr
36
+ - @comment ||= RailsAdminComments::Comment.new
37
+ p
38
+ = form_for @comment, url: url, method: :post do |f|
39
+ - unless @message.blank?
40
+ p== @message
41
+ p= f.text_area :content
42
+ p= f.submit
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_admin_comments"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ if defined?(RailsAdmin)
2
+ RailsAdmin.config do |config|
3
+ config.excluded_models ||= []
4
+ config.excluded_models << [
5
+ 'RailsAdminComments::Comment'
6
+ ]
7
+ config.excluded_models.flatten!
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ ru:
2
+ admin:
3
+ actions:
4
+ comments:
5
+ menu: "Коментарии"
6
+ breadcrumb: "Коментарии"
7
+ error: "Ошибка"
8
+ error_no_data: "Нет данных"
9
+ success: "Успешно"
10
+ title: "Коментарии"
@@ -0,0 +1,40 @@
1
+
2
+ require "rails_admin_comments/version"
3
+
4
+ require 'mongoid'
5
+ require 'mongoid_userstamp'
6
+
7
+ require 'rails_admin/config/actions'
8
+ require 'rails_admin/config/model'
9
+
10
+ module RailsAdminComments
11
+ class << self
12
+ def orm
13
+ :mongoid
14
+ # if defined?(::Mongoid)
15
+ # :mongoid
16
+ # else
17
+ # :active_record
18
+ # end
19
+ end
20
+
21
+ def mongoid?
22
+ orm == :mongoid
23
+ end
24
+
25
+ def active_record?
26
+ orm == :active_record
27
+ end
28
+ end
29
+
30
+ autoload :Mongoid, "rails_admin_comments/mongoid"
31
+ # autoload :RailsAdminConfig, "rails_admin_comments/rails_admin_config"
32
+ end
33
+
34
+
35
+ require "rails_admin_comments/engine"
36
+
37
+ require 'rails_admin_comments/configuration'
38
+ require 'rails_admin_comments/action'
39
+ # require 'rails_admin_comments/model'
40
+ require 'rails_admin_comments/helper'
@@ -0,0 +1,80 @@
1
+ module RailsAdmin
2
+ module Config
3
+ module Actions
4
+ class Comments < Base
5
+ RailsAdmin::Config::Actions.register(self)
6
+
7
+ # Is the action acting on the root level (Example: /admin/contact)
8
+ register_instance_option :root? do
9
+ false
10
+ end
11
+
12
+ register_instance_option :collection? do
13
+ false
14
+ end
15
+
16
+ # Is the action on an object scope (Example: /admin/team/1/edit)
17
+ register_instance_option :member? do
18
+ true
19
+ end
20
+
21
+ register_instance_option :route_fragment do
22
+ 'comments'
23
+ end
24
+
25
+ register_instance_option :controller do
26
+ Proc.new do |klass|
27
+ @config = ::RailsAdminComments::Configuration.new @abstract_model
28
+
29
+ if params['id'].present?
30
+ @comments = @object.rails_admin_comments.by_date.enabled
31
+ if request.get?
32
+ render action: @action.template_name
33
+
34
+ elsif request.post?
35
+ begin
36
+ if params['rails_admin_comments_comment'].present?
37
+ if params['rails_admin_comments_comment']['id'].present?
38
+ @comment = @object.rails_admin_comments.find(params['rails_admin_comments_comment']['id'])
39
+ end
40
+ @comment = @object.rails_admin_comments.new if @comment.nil?
41
+
42
+ @comment.content = params['rails_admin_comments_comment']['content']
43
+
44
+ if @comment.save
45
+ @comment = nil
46
+ @message = "<strong class='success'>#{I18n.t('admin.actions.comments.success')}!</strong>"
47
+
48
+ else
49
+ @message = []
50
+ @message << "<strong class='error'>#{I18n.t('admin.actions.comments.error')}!</strong>"
51
+ @comment.errors.each do |e|
52
+ @message << "<p>#{e.message}</p>"
53
+ end
54
+ @message = @message.join
55
+ end
56
+ else
57
+ @message = "<strong class='error'>#{I18n.t('admin.actions.comments.error')}</strong>:<p>#{I18n.t('admin.actions.comments.error_no_data')}</p>"
58
+ end
59
+
60
+ rescue Exception => e
61
+ @message = "<strong class='error'>#{I18n.t('admin.actions.comments.error')}</strong>: #{e}"
62
+ end
63
+
64
+ render action: @action.template_name
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ register_instance_option :link_icon do
71
+ 'icon-comment'
72
+ end
73
+
74
+ register_instance_option :http_methods do
75
+ [:get, :post]
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,24 @@
1
+ module RailsAdminComments
2
+ class Configuration
3
+ def initialize(abstract_model)
4
+ @abstract_model = abstract_model
5
+ end
6
+
7
+ def options
8
+ # @options ||= {
9
+ # fields: [{}],
10
+ # thumbnail_fields: [:image, :cover],
11
+ # label_methods: [:name, :label],
12
+ # hint_fields: [],
13
+ # thumbnail_size: :thumb,
14
+ # thumbnail_gem: :paperclip,
15
+ # }.merge(config || {})
16
+ @options ||= {}
17
+ end
18
+
19
+ protected
20
+ def config
21
+ ::RailsAdmin::Config.model(@abstract_model.model).comments || {}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module RailsAdminComments
2
+ class Engine < ::Rails::Engine
3
+
4
+ initializer "RailsAdminComments precompile hook", group: :all do |app|
5
+ app.config.assets.precompile += %w(rails_admin/rails_admin_comments.js rails_admin/rails_admin_comments.css)
6
+ end
7
+
8
+ initializer 'Include RailsAdminComments::Helper' do |app|
9
+ ActionView::Base.send :include, RailsAdminComments::Helper
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module RailsAdminComments
2
+ module Helper
3
+ def rails_admin_comments_form
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module RailsAdminComments
2
+ module Mongoid
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ include ::Mongoid::Document
6
+ include ::Mongoid::Timestamps::Short
7
+ include ::Mongoid::Userstamp
8
+
9
+ belongs_to :rails_admin_commentable, polymorphic: true
10
+
11
+ store_in collection: "rails_admin_comments"
12
+
13
+ field :enabled, type: ::Mongoid::VERSION.to_i < 4 ? Boolean : ::Mongoid::Boolean, default: true
14
+ scope :enabled, -> { where(enabled: true) }
15
+
16
+ scope :by_date, -> { order([:c_at, :asc]) }
17
+
18
+ field :content
19
+ validates_presence_of :content
20
+
21
+ scope :for_user, ->(user) {}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminComments
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_admin_comments/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_admin_comments"
8
+ spec.version = RailsAdminComments::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["dev@enjoycreate.ru"]
11
+
12
+ spec.summary = %q{Comments for rails_admin}
13
+ spec.description = %q{Comments for rails_admin}
14
+ spec.homepage = "https://github.com/enjoycreative/rails_admin_comments"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency "rails"
34
+ spec.add_dependency "mongoid", [">= 5.0", "< 6.0"]
35
+ spec.add_dependency "glebtv_mongoid_userstamp"
36
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push
6
+ git push gh master
7
+ rake release
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_comments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mongoid
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '6.0'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '5.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '6.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: glebtv_mongoid_userstamp
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Comments for rails_admin
90
+ email:
91
+ - dev@enjoycreate.ru
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".ruby-gemset"
98
+ - ".ruby-version"
99
+ - ".travis.yml"
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - app/assets/javascripts/rails_admin/rails_admin_comments.coffee
105
+ - app/assets/stylesheets/rails_admin/rails_admin_comments.sass
106
+ - app/models/concerns/rails_admin_comments/commentable.rb
107
+ - app/models/rails_admin_comments/comment.rb
108
+ - app/views/rails_admin/main/comments.html.slim
109
+ - bin/console
110
+ - bin/setup
111
+ - config/initializers/rails_admin.rb
112
+ - config/locales/ru.rails_admin_comments.yml
113
+ - lib/rails_admin_comments.rb
114
+ - lib/rails_admin_comments/action.rb
115
+ - lib/rails_admin_comments/configuration.rb
116
+ - lib/rails_admin_comments/engine.rb
117
+ - lib/rails_admin_comments/helper.rb
118
+ - lib/rails_admin_comments/mongoid.rb
119
+ - lib/rails_admin_comments/version.rb
120
+ - rails_admin_comments.gemspec
121
+ - release.sh
122
+ homepage: https://github.com/enjoycreative/rails_admin_comments
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.8
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Comments for rails_admin
146
+ test_files: []