infienity 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e14ab0327e7a89967c4449bd94309d1a49517c54edc633c1800bf367c80a2d35
4
- data.tar.gz: e1b0898f2c52bf281b3620ecbdc1e311871308e6ca9cf4d2eb09ad1fc864b6d5
3
+ metadata.gz: cd2ea4ac28e3f022e0ccb9506f9736c75f69d8b527636f5941945204232702f7
4
+ data.tar.gz: 7fdda8a96b8d6af219bf189af127dc2c32be7382f92dbcf7b464013b5c67939b
5
5
  SHA512:
6
- metadata.gz: 561b7eb224d49fcf22531db57cac7a33dc4d04b1e919dce22910f85fd6b2e26c56e59e904cc755a6f0b338142db9a98181fef1d83a2786e20a1c4a1bd022f2b1
7
- data.tar.gz: c420259d0bb739059bb0bda8b3bb59396b26193c0c36044a03a934d14ce71e915d020eee610f484a398c39eb1169b2bcbdad34194c96a80a8c24a01dcfc43afe
6
+ metadata.gz: 48be04b7244d1ae386f97a8a7c8a9cf978a74526e464b87f216da74439fdfd567e51ddb8c59a02d99f09bb90734683859a64580aa5064b439bd7f190d04466e9
7
+ data.tar.gz: eaca0a347d91ba2c1af4b851363e3f10dc848b3542262f35ac602162f062acd2af6f9ce2b7d2ff1bb991f92f4a448d37016f1be4fd52f808332da9d24e00d639
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infienity (0.1.0)
4
+ infienity (0.1.1)
5
5
  rails
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Infienity
2
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/infienity`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Infienity provides infinity scroll, combined with sort and search via web-socket connection. Since infinity scroll requires continuous calls to request new parts of the data, requesting new data via a permanent web-socket connection should be a cleaner approach than using traditional AJAX calls.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem is dependent on [Fie]("https://github.com/raen79/fie"), a gem that makes DOM manipulations through web sockets possible. It works by... (TODO).
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
-
11
10
  ```ruby
12
11
  gem 'infienity'
12
+ gem 'fie' # dependency, use your preferred version
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -20,15 +20,162 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install infienity
22
22
 
23
+ Add Infienity's javascript in your project, by adding the following lines into `app/assets/javascripts/application.js`:
24
+
25
+ ```ruby
26
+ # just before require_tree
27
+ //= require fie
28
+ //= require infienity
29
+ ```
30
+
31
+ As Infienity is dependent on Fie, you will have to follow the regular [Fie setup]("https://github.com/raen79/fie"), which also includes setting up Redis.
32
+
23
33
  ## Usage
34
+ For both infinity scroll, searching and sorting you will need to perform the following steps:
24
35
 
25
- TODO: Write usage instructions here
36
+ Add the following line in the model you want to perform the actions on:
37
+ ```ruby
38
+ extend Infienity::Model
39
+ ```
40
+
41
+ Create a commander for your model (for front-end manipulation). The commander should be correspondant to the controller of your model (path: `app/commanders/[name]_commander).
42
+ ```ruby
43
+ class HomeCommander < Fie::Commander
44
+ extend Infienity::Commander
45
+ commander_assigns :users # model name in this format
46
+ end
47
+ ```
48
+
49
+ In your controller method, you will need to assign some variables, which will hold the state. you must declare all of them in order for the infinity scroll to work:
50
+ ```ruby
51
+ @index = 0
52
+ @per_page = 10 # choose your preferred amount
53
+ ```
54
+
55
+ ### Pagination
56
+
57
+ In your controller method, perform the pagination of the infinity scroll like so:
58
+ ```ruby
59
+ @users = User.paginate
60
+ ```
61
+
62
+ In your view, for each data entry, wrap it up in a span, with the following class and custom attribute. `infienity-model` should include your model name, in plural.
63
+ Example:
64
+ ```ruby
65
+ <% @users.each do |u| %>
66
+ <span class="paginate" infienity-model="users">
67
+ Name: <%= u.full_name %> <br/>
68
+ Username: <%= u.username %>
69
+ </span>
70
+ <% end %>
71
+ ```
72
+
73
+ ### Search
74
+
75
+ In your controller method, add the following variables, in order to hold the state:
76
+ ```ruby
77
+ @search_attribute = 'username'
78
+ @search_string = ''
79
+ ```
80
+
81
+ In your view, you can use this predefined layout:
82
+ ```ruby
83
+ <%= render template: 'layouts/search', locals: { assign: "users", search_string: @search_string } %>
84
+ ```
85
+
86
+ Or use html in this manner:
87
+ ```html
88
+ <input type="text" name="search_string" value="<%= @search_string %>" fie-keyup="filter_users" > </input>
89
+ ```
90
+ Note: be careful to put the correct assign for `fie-keyup` attribute
91
+
92
+ ### Sort
93
+
94
+ In your controller method, add the following variables, in order to hold the state:
95
+ ```ruby
96
+ @sorting_dropdown_options =
97
+ {
98
+ "Username (A-Z)" => [:username, :asc],
99
+ "Username (Z-A)" => [:username, :desc],
100
+ "Date (Asc)" => [:created_at, :asc],
101
+ "Date (Desc)" => [:created_at, :desc]
102
+ }
103
+ @selected_dropdown_option = "Username (A-Z)"
104
+ ```
105
+ - The keys in the `@sorting_dropdown_options` are the values the user is going to see.
106
+ - The first value in `@sorting_dropdown_options` is the model attruibute, and the second is always `:asc` or `:desc`.
107
+ - The `@selected_dropdown_option` must correspond to one of the keys stated in `@sorting_dropdown_options`
108
+
109
+ If you use a custom dropdown using `<li>` elements, you can use this template:
110
+ ```ruby
111
+ <%= render
112
+ template: 'layouts/sort',
113
+ locals:
114
+ {
115
+ dropdown_options: @sorting_dropdown_options,
116
+ current_option: @selected_dropdown_option,
117
+ assign: "users"
118
+ }
119
+ %>
120
+ ```
121
+
122
+ Or for a basic `<select>` dropdown:
123
+ ```ruby
124
+ <%= render
125
+ template: 'layouts/sort_select',
126
+ locals: {
127
+ dropdown_options: @sorting_dropdown_options,
128
+ current_option: @selected_dropdown_option,
129
+ assign: "users"
130
+ }
131
+ %>
132
+ ```
133
+
134
+ Or use html in this manner:
135
+ ```html
136
+ <div class="dropdown">
137
+ <button type="button" data-toggle="dropdown"> <%= @selected_dropdown_option %>
138
+ <span class="caret"></span>
139
+ </button>
140
+ <ul class="dropdown-menu">
141
+ <% @selected_dropdown_option.each do |key,val| %>
142
+ <li fie-click="sort_users" fie-parameters= "<%= { sort: {key => val} }.to_json %>"> <%= key %> </li>
143
+ <% end %>
144
+ </ul>
145
+ </div>
146
+ ```
147
+ Note: be careful to put the correct assign for `fie-click` attribute
148
+
149
+ ### Template options
150
+
151
+ To style the html in the templates, add the `options` hash inside the locals hash, in this manner:
152
+ ```ruby
153
+ <%= render
154
+ template: 'layouts/sort',
155
+ locals:
156
+ {
157
+ dropdown_options: @sorting_dropdown_options,
158
+ current_option: @selected_dropdown_option,
159
+ assign: "users",
160
+ options: { class: "btn btn-primary dropdown-toggle" }
161
+ }
162
+ %>
163
+ ```
164
+
165
+ Supported options:
166
+ - `:id`
167
+ - `:class`
168
+ - `:name`
26
169
 
27
170
  ## Development
28
171
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
172
+ Your first step is to run `npm install` within the root folder in order to install the relevant NodeJS packages.
173
+
174
+ To work on the JavaScript, begin by running `npm run build`. This will start a watcher that will automatically transpile your ES6 within the `ib/javascripts` folder into a bundle within `vendor/javascripts/infienity.js` using webpacker.
175
+
176
+ The Ruby files can be found within `lib/infienity` and their development is the same as in any other gem.
30
177
 
31
- 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).
178
+ Please add tests if you add new features or resolve bugs.
32
179
 
33
180
  ## Contributing
34
181
 
data/infienity.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["ioana.sbob@gmail.com"]
11
11
 
12
12
  spec.summary = %q{summary}
13
- spec.description = %q{description}
13
+ spec.description = %q{Infinity scroll, search and sort via web socket connection.}
14
14
  spec.homepage = "https://github.com/ioanabob/infienity"
15
15
  spec.license = "MIT"
16
16
 
@@ -1,3 +1,3 @@
1
1
  module Infienity
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1 +1,8 @@
1
- <input type="text" name="search_string" value="<%= search_string %>" fie-keyup="filter_<%= assign %>" > </input>
1
+ <input
2
+ type="text"
3
+ class="<%= options[:class] %>"
4
+ id="<%= options[:id] %>"
5
+ name="search_string <%= options[:name] %>"
6
+ value="<%= search_string %>"
7
+ fie-keyup="filter_<%= assign %>" >
8
+ </input>
File without changes
@@ -1,4 +1,10 @@
1
- <select fie-change="sort_select_<%= assign %>">
1
+ <select
2
+ class="<%= options[:class] %>"
3
+ id="<%= options[:id] %>"
4
+ name="<%= options[:name] %>"
5
+ value="<%= search_string %>"
6
+ fie-keyup="filter_<%= assign %>" >
7
+ fie-change="sort_select_<%= assign %>">
2
8
  <% dropdown_options.each do |key,val| %>
3
9
  <option value="<%= {key => val}.to_json %>"> <%= key %> </option>
4
10
  <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infienity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ioana Surdu-Bob
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-17 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: description
69
+ description: Infinity scroll, search and sort via web socket connection.
70
70
  email:
71
71
  - ioana.sbob@gmail.com
72
72
  executables: []
@@ -94,7 +94,7 @@ files:
94
94
  - lib/infienity/view.rb
95
95
  - lib/javascripts/infienity.js
96
96
  - lib/layouts/search.html.erb
97
- - lib/layouts/sort_li.html.erb
97
+ - lib/layouts/sort.html.erb
98
98
  - lib/layouts/sort_select.html.erb
99
99
  - package-lock.json
100
100
  - package.json