outpost-aggregator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/.gitignore +17 -0
  2. data/CHANGELOG.md +16 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +117 -0
  6. data/Rakefile +14 -0
  7. data/config.ru +7 -0
  8. data/lib/assets/javascripts/outpost/aggregator/aggregator.js.coffee +796 -0
  9. data/lib/assets/javascripts/outpost/aggregator/templates/_pagination.jst.eco +12 -0
  10. data/lib/assets/javascripts/outpost/aggregator/templates/base.jst.eco +90 -0
  11. data/lib/assets/javascripts/outpost/aggregator/templates/content_full.jst.eco +19 -0
  12. data/lib/assets/javascripts/outpost/aggregator/templates/content_small.jst.eco +15 -0
  13. data/lib/assets/javascripts/outpost/aggregator/templates/drop_zone.jst.eco +1 -0
  14. data/lib/assets/javascripts/outpost/aggregator/templates/error.jst.eco +4 -0
  15. data/lib/assets/javascripts/outpost/aggregator/templates/recent_content.jst.eco +2 -0
  16. data/lib/assets/javascripts/outpost/aggregator/templates/search.jst.eco +6 -0
  17. data/lib/assets/javascripts/outpost/aggregator/templates/url.jst.eco +5 -0
  18. data/lib/assets/javascripts/outpost/aggregator.js +2 -0
  19. data/lib/assets/stylesheets/outpost/aggregator.css.scss +93 -0
  20. data/lib/outpost/aggregator/json_input.rb +75 -0
  21. data/lib/outpost/aggregator/simple_json.rb +12 -0
  22. data/lib/outpost/aggregator/version.rb +5 -0
  23. data/lib/outpost/aggregator.rb +21 -0
  24. data/outpost-aggregator.gemspec +28 -0
  25. data/spec/factories.rb +2 -0
  26. data/spec/internal/config/database.yml +3 -0
  27. data/spec/internal/config/routes.rb +3 -0
  28. data/spec/internal/db/combustion_test.sqlite +0 -0
  29. data/spec/internal/db/schema.rb +3 -0
  30. data/spec/internal/log/.gitignore +1 -0
  31. data/spec/internal/public/favicon.ico +0 -0
  32. data/spec/lib/outpost/aggregator/json_input_spec.rb +4 -0
  33. data/spec/lib/outpost/aggregator/simple_json_spec.rb +4 -0
  34. data/spec/spec_helper.rb +23 -0
  35. metadata +204 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ ### 1.0.0 (2013-06-13)
2
+ * The method to use is now `accepts_json_input_for`, and requires
3
+ a single argument: the name of the association.
4
+ * Does not do a `published?` check anymore. That's up to you to check when
5
+ building the association.
6
+ * Method to specify how to build the association is now
7
+ `build_#{name.singularize}_association`. For example, if you have
8
+ `accepts_json_input_for :assets`, then you should define
9
+ `build_asset_association`. This is where you should do any validations
10
+ on the content - `published?`, `persisted?`, etc.
11
+
12
+
13
+ ### v0.1.1
14
+ * Merge in the passed-in params (such as api token) to the params for
15
+ "by_url" requests. This allows one to use their internal/private API
16
+ with the by_url requests.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in outpost-aggregator.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Bryan Ricker
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.md ADDED
@@ -0,0 +1,117 @@
1
+ # Outpost::Aggregator
2
+
3
+ Provides UI and server-side handling for building associations between
4
+ any two objects.
5
+
6
+ ## Installation
7
+
8
+ gem 'outpost-aggregator'
9
+
10
+
11
+ ## Dependencies
12
+
13
+ This is a pretty simple gem... you can probably get away with using this gem without Outpost. Just be sure you have a few things setup:
14
+
15
+ * A client-side `window.outpost` object for the javascript.
16
+ * `Outpost.obj_by_key` - to find an object by the passed-in object key.
17
+ This is defined in outpost.
18
+ * The join model must respond to `position` and `obj_key` if you want to
19
+ use the SimpleJson module. This module is dead-simple, so you definitely
20
+ could just copy and paste its contents into your model and customize it
21
+ there.
22
+
23
+
24
+ ## Usage
25
+
26
+ The aggregator writes a JSON string to a hidden input, and that's
27
+ what gets submitted to and parsed by the server.
28
+
29
+ In your model:
30
+
31
+ ```ruby
32
+ class Post < ActiveRecord::Base
33
+ has_many :related_posts, order: "position", dependent: :destroy
34
+ accepts_json_input_for :related_posts
35
+ end
36
+ ```
37
+
38
+ In the form, you need to provide a div for the aggregator to be built in,
39
+ the hidden input for the JSON string, and then initialize the Aggregator with
40
+ bootstrapped content. Using simple_form, and assuming the record's association
41
+ is called "content" (which is the default), it might look like this:
42
+
43
+ ```erb
44
+ <div id="aggregator" class="aggregator"></div>
45
+ <%= f.input :related_posts_json, as: :hidden, input_html: { id: "related_posts_json" } %>
46
+
47
+ <script>
48
+ aggregator = new outpost.Aggregator(
49
+ "#aggregator", "#related_posts_json",
50
+ <%= j record.related_posts.includes(:post).map(&:post).to_json.html_safe %>,
51
+ <%= raw options.to_json %>);
52
+ </script>
53
+ ```
54
+
55
+ You should also define an `outpost.ContentAPI`, to tell the Aggregator how to get in touch with your server.
56
+
57
+ ```coffee
58
+ class outpost.ContentAPI
59
+
60
+ #-----------------------------
61
+
62
+ class @Content extends Backbone.Model
63
+ #----------
64
+ # simpleJSON is an object of just the attributes
65
+ # we care about for SCPRv4. Everything else will
66
+ # filled out server-side.
67
+ simpleJSON: ->
68
+ {
69
+ id: @get 'id'
70
+ position: @get 'position'
71
+ }
72
+
73
+ #-----------------------------
74
+
75
+ class @ContentCollection extends Backbone.Collection
76
+ url: "/api/content/"
77
+ model: ContentAPI.Content
78
+
79
+ #----------
80
+ # Sort by position attribute
81
+ comparator: (model) ->
82
+ model.get 'position'
83
+
84
+ #----------
85
+ # An array of content turned into simpleJSON. See
86
+ # Content#simpleJSON for more.
87
+ simpleJSON: ->
88
+ contents = []
89
+ @each (content) -> contents.push(content.simpleJSON())
90
+ contents
91
+
92
+ #-----------------------------
93
+
94
+ class @PrivateContentCollection extends @ContentCollection
95
+ url: "/api/private/content"
96
+
97
+ #-----------------------------
98
+ ```
99
+
100
+ Your API should have a `by_url` path, and should accept query params for
101
+ the search and URL import to work.
102
+
103
+ See the `content_full` and `content_small` templates to see what the aggregator
104
+ expects the response object to look.
105
+
106
+
107
+ ## TODO
108
+ * Write tests
109
+
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Push to the branch (`git push origin my-new-feature`)
117
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ RAKED = true
3
+
4
+ require 'bundler/setup'
5
+ require 'rdoc/task'
6
+ require 'rspec/core/rake_task'
7
+ require 'combustion'
8
+
9
+ Bundler.require :default, :test
10
+ Combustion.initialize! :active_record
11
+ Combustion::Application.load_tasks
12
+
13
+ RSpec::Core::RakeTask.new(:test)
14
+ task default: :test
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize!
7
+ run Combustion::Application