polymorph 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 818cc6635c8cb12b5c0b5a003042744a7c241e51
4
+ data.tar.gz: ae9b7516830bf132471633a30e8c1d102e490fd7
5
+ SHA512:
6
+ metadata.gz: a29513acc0d384ce26d8fc9f275f3784d4e18c4755d44c708dbd880fc3160ac04627948302f9cd46a2060bc3b8a1e6b0b640cf60b0699f858d90738e321546b8
7
+ data.tar.gz: 1b726dd11f58c44ae34dfa3781621ddca77065c5340fc20eb1db87997ab166c3473a401c62a41e041ee464e8b4d2bfbf5b8663972d5be0457f28698ef35db31a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Nick Ostrovsky
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Polymorph
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Polymorph'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,26 @@
1
+ class Orderable
2
+ el: '.admin [data-orderable]'
3
+
4
+ constructor: ->
5
+ return unless $(@el).length
6
+ $(@el).each @attachSortable
7
+
8
+ attachSortable: (i, el) =>
9
+ options = @options(el)
10
+ $(el).sortable options
11
+
12
+ options: (el) =>
13
+ options =
14
+ update: ->
15
+ $.post $(@).data('orderable'), $(@).sortable('serialize')
16
+
17
+ if $(el).data('orderableItems')
18
+ options.items = $(el).data('orderableItems')
19
+
20
+ if $(el).data('orderableAxis')
21
+ options.axis = $(el).data('orderableAxis')
22
+
23
+ options
24
+
25
+ $ ->
26
+ new Orderable
@@ -0,0 +1 @@
1
+ #= require polymorph/orderable
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Polymorph
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module Polymorph
2
+ class OrderableController < Polymorph::ApplicationController
3
+ def create
4
+ klass.reorder(order)
5
+ head :ok
6
+ end
7
+
8
+ private
9
+
10
+ def orderable
11
+ params[:orderable_type]
12
+ end
13
+
14
+ def klass
15
+ orderable.camelize.constantize
16
+ end
17
+
18
+ def order
19
+ params[orderable]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module Polymorph
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Polymorph</title>
5
+ <%= stylesheet_link_tag "polymorph/application", media: "all" %>
6
+ <%= javascript_include_tag "polymorph/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Polymorph::Engine.routes.draw do
2
+ post 'orderable/:orderable_type',
3
+ to: 'orderable#create',
4
+ as: :orderable
5
+ end
data/lib/polymorph.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "polymorph/engine"
2
+ require "polymorph/orderable"
3
+
4
+ module Polymorph
5
+ end
@@ -0,0 +1,5 @@
1
+ module Polymorph
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Polymorph
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ module Polymorph
2
+ module Orderable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ scope :ordered, -> { order position: :asc }
7
+ before_save :set_max_position
8
+ end
9
+
10
+ def set_max_position
11
+ self.position = self.class.maximum(:position).to_i + 10 unless position
12
+ end
13
+
14
+ module ClassMethods
15
+ def reorder(*new_order)
16
+ def ensure_resource(id_or_resource)
17
+ return id_or_resource if id_or_resource.is_a? self
18
+ find(id_or_resource)
19
+ end
20
+
21
+ new_order.flatten.compact.map.each_with_index do |id_or_resource, index|
22
+ resource = ensure_resource(id_or_resource)
23
+ position = index * 10 + 10
24
+ resource.update_attribute(:position, position)
25
+ [resource, position]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Polymorph
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :polymorph do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polymorph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Ostrovsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ description: http://firedev.com
42
+ email:
43
+ - nick@firedev.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - app/assets/javascripts/polymorph/orderable.coffee
52
+ - app/assets/javascripts/polymorph/polymorph.coffee
53
+ - app/assets/stylesheets/polymorph/application.css
54
+ - app/controllers/polymorph/application_controller.rb
55
+ - app/controllers/polymorph/orderable_controller.rb
56
+ - app/helpers/polymorph/application_helper.rb
57
+ - app/views/layouts/polymorph/application.html.erb
58
+ - config/routes.rb
59
+ - lib/polymorph.rb
60
+ - lib/polymorph/engine.rb
61
+ - lib/polymorph/orderable.rb
62
+ - lib/polymorph/version.rb
63
+ - lib/tasks/polymorph_tasks.rake
64
+ homepage: http://firedev.com
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Frontend Bits and Pieces for Rails
88
+ test_files: []
89
+ has_rdoc: