timeline_rails_helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fd3ef7dfe81f7c0e3bab03ec91cddb12d4c1cbc8c40f316ec355a973bc0a42b
4
+ data.tar.gz: ed275e2031856318918fd927a480ef19b01a86ea06eaed9f9b6adbf8e8b4ee70
5
+ SHA512:
6
+ metadata.gz: 888d4715e99f20956d36f00244edc086252ed356f9d55dafdbf2e19f07b3792f97788e5293945b8e1927fd6fd037edd9165754a024ccedab472217a8ee02c21f
7
+ data.tar.gz: 2fde4a12bb3013f80cbf0fc7c8325e41bf6fcfdfb7243bf6a074d70fa8af3d11eca31aa88ff12b804609eb0ae8f0f33c59e3aeba27e3250275effe9eefe90316
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 smapira
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,92 @@
1
+ # TimelineRailsHelper
2
+
3
+ ![Ruby](https://img.shields.io/badge/Ruby-CC342D?style=for-the-badge&logo=ruby&logoColor=white)
4
+ [![Gem Version](https://badge.fury.io/rb/timeline_rails_helper.svg)](https://badge.fury.io/rb/jma)
5
+ ![](https://ruby-gem-downloads-badge.herokuapp.com/timeline_rails_helper)
6
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
7
+ [![CircleCI](https://circleci.com/gh/smapira/timeline_rails_helper/tree/main.svg?style=svg)](https://circleci.com/gh/smapira/timeline_rails_helper/tree/main)
8
+
9
+ The TimelineRailsHelper provides a timeline_molecules_tag helper to draw a vertical time line usable with vanilla [CSS](https://codepen.io/z-/pen/bwPBjY).
10
+
11
+ ## See It Work
12
+
13
+ ![output](https://user-images.githubusercontent.com/25024587/163623635-e0b8fdab-b8dc-4bad-b795-7631931a8acc.gif)
14
+
15
+ ## Installation
16
+
17
+ ### Prerequisites
18
+ - Ruby >= 2.6
19
+
20
+ ### Stacks
21
+ - [ActionView](https://api.rubyonrails.org/classes/ActionView.html)
22
+ - [minitest](https://github.com/seattlerb/minitest)
23
+ - [RuboCop](https://github.com/rubocop/rubocop)
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem "timeline_rails_helper"
29
+ ```
30
+
31
+ And then execute:
32
+ ```bash
33
+ $ bundle
34
+ ```
35
+
36
+ Or install it yourself as:
37
+ ```bash
38
+ $ gem install timeline_rails_helper
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### QQTW (Quickest Quick-start in The West)
44
+
45
+ ```ruby
46
+ timeline_molecules_tag [{title: (DateTime.now - 3.days).strftime('%Y-%m-%d'),
47
+ body: 'This is a test'},
48
+ {title: DateTime.now.strftime('%Y-%m-%d'),
49
+ body: 'This is a test'}]
50
+
51
+ # => "<div id="time_line_rails_helper">
52
+ # <div class="entries">
53
+ # <div class="entry">
54
+ # <div class="title ">2022-04-13</div>
55
+ # <div class="body">This is a test</div>
56
+ # </div>
57
+ # <div class="entry">
58
+ # <div class="title ">2022-04-16</div>
59
+ # <div class="body">This is a test</div>
60
+ # </div>
61
+ # </div>
62
+ # </div>"
63
+ ```
64
+
65
+ ## Development
66
+
67
+ ### Test
68
+
69
+ ```bash
70
+ bin/test
71
+ ```
72
+
73
+ ## Changelog
74
+
75
+ TimelineRailsHelper's changelog is available [here](https://github.com/smapira/timeline_rails_helper/blob/main/CHANGELOG.md).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on Github at https://github.com/smapira/timeline_rails_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/smapira/timeline_rails_helper/src/main/CODE_OF_CONDUCT.md).
80
+ License
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+ ## Code of Conduct
87
+
88
+ Everyone interacting in the timeline_rails_helper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/smapira/timeline_rails_helper/blob/main/CODE_OF_CONDUCT.md).
89
+
90
+ ## Acknowledgments
91
+ - [CSS by Zed Dash at Codepen](https://codepen.io/z-/pen/bwPBjY)
92
+ - [rails-timeago](https://github.com/jgraichen/rails-timeago)
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+
5
+ require "bundler/gem_tasks"
@@ -0,0 +1,82 @@
1
+ // see the reference by Zed Dash https://codepen.io/z-/pen/bwPBjY
2
+
3
+ #time_line_rails_helper{
4
+ background-color:#1D1D1D;
5
+ min-height:100vh;
6
+ margin:0;
7
+ font-family: 'Droid Sans', sans-serif;
8
+ &:before {
9
+ content: '';
10
+ position: fixed;
11
+ top:0px;
12
+ left:50%;
13
+ bottom:0px;
14
+ transform:translateX(-50%);
15
+ width:4px;
16
+ background-color:#fff;
17
+ }
18
+ .entries {
19
+ width:calc(100% - 80px);
20
+ max-width:800px;
21
+ margin:auto;
22
+ position: relative;
23
+ left:-5px;
24
+ .entry {
25
+ width:calc(50% - 80px);
26
+ float:left;
27
+ padding:20px;
28
+ clear:both;
29
+ text-align:right;
30
+ &:not(:first-child) {
31
+ margin-top:-60px;
32
+ }
33
+ .title {
34
+ font-size:32px;
35
+ margin-bottom:12px;
36
+ position: relative;
37
+ color:#fff;
38
+ &:before {
39
+ content: '';
40
+ position: absolute;
41
+ width:8px;
42
+ height:8px;
43
+ border:4px solid #ffffff;
44
+ background-color:#1D1D1D;
45
+ border-radius:100%;
46
+ top:50%;
47
+ transform:translateY(-50%);
48
+ right:-73px;
49
+ z-index:1000;
50
+ }
51
+ &.big:before {
52
+ width:24px;
53
+ height:24px;
54
+ transform:translate(8px,-50%);
55
+ }
56
+ a {
57
+ color: white;
58
+ text-decoration: none;
59
+ }
60
+ }
61
+ .body {
62
+ color:#aaa;
63
+ min-height: 40px;
64
+ p {
65
+ line-height:1.4em;
66
+ }
67
+ }
68
+ &:nth-child(2n) {
69
+ text-align:left;
70
+ float:right;
71
+ .title {
72
+ &:before {
73
+ left:-63px;
74
+ }
75
+ &.big:before {
76
+ transform:translate(-8px,-50%);
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TimelineRailsHelper
4
+ ##
5
+ # This module expands the helper method into ActiveSupport helper.
6
+ module Helpers
7
+ # Create a timeline_molecules tag usable with vanilla CSS.
8
+ #
9
+ # timeline_molecules_tag [{title: (DateTime.now - 3.days).strftime('%Y-%m-%d'),
10
+ # body: 'This is a test'},
11
+ # {title: DateTime.now.strftime('%Y-%m-%d'),
12
+ # body: 'This is a test'}]
13
+ # => "<div id=\"time_line_rails_helper\">
14
+ # <div class=\"entries\">
15
+ # <div class=\"entry\">
16
+ # <div class=\"title \">2022-04-13</div>
17
+ # <div class=\"body\">This is a test</div>
18
+ # </div>
19
+ # <div class=\"entry\">
20
+ # <div class=\"title \">2022-04-16</div>
21
+ # <div class=\"body\">This is a test</div>
22
+ # </div>
23
+ # </div>
24
+ # </div>"
25
+ #
26
+ # Available options:
27
+ # [:+condition+]
28
+ # Add a condition which corresponds to the title, then assign the CSS property.
29
+ # (default: nil)
30
+ #
31
+ # @param [Array] records
32
+ # @param [String] condition
33
+ # @return [String]
34
+ def timeline_molecules_tag(records, condition = nil)
35
+ return "" if records.empty?
36
+
37
+ wrap_container = ->(x) { "<div class=\"entry\">\n#{x}\n</div>" }
38
+ content = records.map(&(wrap_tag(condition) >> wrap_container)).join("\n")
39
+ "<div id=\"time_line_rails_helper\">\n<div class=\"entries\">\n#{content}\n</div>\n</div>"
40
+ end
41
+
42
+ private
43
+
44
+ # @param [String] title
45
+ # @param [String | nil] condition
46
+ # @return [String]
47
+ def assign_class(title, condition)
48
+ return "" if condition.nil?
49
+
50
+ title == condition ? "big" : ""
51
+ end
52
+
53
+ # @param [String | nil] condition
54
+ # @return [Proc]
55
+ def wrap_tag(condition)
56
+ lambda { |x|
57
+ "<div class=\"title #{assign_class(x[:title],
58
+ condition)}\">#{x[:title]}</div>\n<div class=\"body\">#{x[:body]}</div>"
59
+ }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TimelineRailsHelper
4
+ class Railtie < ::Rails::Railtie
5
+ class Engine < ::Rails::Engine # :nodoc:
6
+ initializer "timeline_rails_helper.assets" do |app|
7
+ %w[stylesheets].each do |sub|
8
+ app.config.assets.paths << root.join("assets", sub).to_s
9
+ end
10
+ end
11
+ initializer "timeline_rails_helper", group: :all do |_app|
12
+ ActiveSupport.on_load(:action_controller) do
13
+ include TimelineRailsHelper::Helpers
14
+ end
15
+
16
+ ActiveSupport.on_load(:action_view) do
17
+ include TimelineRailsHelper::Helpers
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TimelineRailsHelper
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timeline_rails_helper/version"
4
+ require "timeline_rails_helper/railtie"
5
+ require "timeline_rails_helper/helpers"
6
+
7
+ ##
8
+ # The module represents a vertical timeline through a data set.
9
+ module TimelineRailsHelper
10
+ end
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timeline_rails_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - smapira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-15 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sassc-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: better_errors
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: binding_of_caller
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: listen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: puma
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rdoc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: sqlite3
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: web-console
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description: Provides a timeline_molecules_tag helper to draw a vertical time line
196
+ usable with vanilla CSS.
197
+ email:
198
+ - 25024587+smapira@users.noreply.github.com
199
+ executables: []
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - MIT-LICENSE
204
+ - README.md
205
+ - Rakefile
206
+ - app/assets/stylesheets/timeline_rails_helper.scss
207
+ - lib/timeline_rails_helper.rb
208
+ - lib/timeline_rails_helper/helpers.rb
209
+ - lib/timeline_rails_helper/railtie.rb
210
+ - lib/timeline_rails_helper/version.rb
211
+ homepage: https://github.com/smapira/timeline_rails_helper
212
+ licenses:
213
+ - MIT
214
+ metadata:
215
+ homepage_uri: https://github.com/smapira/timeline_rails_helper
216
+ source_code_uri: https://github.com/smapira/timeline_rails_helper
217
+ changelog_uri: https://github.com/smapira/timeline_rails_helper
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 2.6.0
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubygems_version: 3.3.3
234
+ signing_key:
235
+ specification_version: 4
236
+ summary: A helper to display vertical time line series.
237
+ test_files: []