futurism 0.3.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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +168 -0
- data/Rakefile +29 -0
- data/app/assets/config/futurism_manifest.js +0 -0
- data/config/routes.rb +2 -0
- data/lib/futurism.rb +16 -0
- data/lib/futurism.rb~ +5 -0
- data/lib/futurism/channel.rb +26 -0
- data/lib/futurism/channel.rb~ +22 -0
- data/lib/futurism/engine.rb +4 -0
- data/lib/futurism/helpers.rb +46 -0
- data/lib/futurism/helpers.rb~ +13 -0
- data/lib/futurism/version.rb +3 -0
- data/lib/tasks/futurism_tasks.rake +39 -0
- data/lib/tasks/futurism_tasks.rake~ +4 -0
- metadata +199 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: e4522cbff1a5893e2a977bf7a32236b1ad9425983ed38521f188c5696dbbfec1
         | 
| 4 | 
            +
              data.tar.gz: 37cb1278ae994766170290f172aca2f4db3b8e2a801edcb77c1ce4632352d56a
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 83742f96cb378d99ddc8d51bb95b8734fcdec0d9e22d0f3ac2b17122977dedf518942ed38664d715ec2b6890017269a301c31ebe3489d1e10d2176412970c13e
         | 
| 7 | 
            +
              data.tar.gz: 42a03c5aa611bd415ecfc33b76b9242ce2c4d1e2c06cab8bf50ee06e6e7fe67fb14bad078f4c36bf9b0cd2e242eeefdd3f79581a5f50d47e2c89f5c184f12e40
         | 
    
        data/MIT-LICENSE
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            Copyright 2020 Julian Rubisch
         | 
| 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,168 @@ | |
| 1 | 
            +
            # Futurism
         | 
| 2 | 
            +
            [](https://twitter.com/julian_rubisch)
         | 
| 3 | 
            +
            <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
         | 
| 4 | 
            +
            [](#contributors-)
         | 
| 5 | 
            +
            <!-- ALL-CONTRIBUTORS-BADGE:END -->
         | 
| 6 | 
            +
            Lazy-load Rails partials via CableReady
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            :rotating_light: *Futurism is still in pre-1.0 state. As much as I hope to keep the API backwards-compatible, I cannot guarantee it* :rotating_light:
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ## Facts
         | 
| 11 | 
            +
            - only one dependency: CableReady
         | 
| 12 | 
            +
            - bundle size (without CableReady) is around [~1.04kB](https://bundlephobia.com/result?p=@minthesize/futurism@0.1.3)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ### Browser Support
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            - Chrome v67+ (v54+ via Polyfill)
         | 
| 17 | 
            +
            - Firefox v63+
         | 
| 18 | 
            +
            - Edge v79+
         | 
| 19 | 
            +
            - Safari v10.1+ via Polyfill
         | 
| 20 | 
            +
            - iOS Safari & Chrome v10.3+ via Polyfill
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            [Caniuse](https://www.caniuse.com/#search=custom%20elements)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ## Usage
         | 
| 25 | 
            +
            with a helper in your template
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ```erb
         | 
| 28 | 
            +
            <%= futurize @posts, extends: :div do %>
         | 
| 29 | 
            +
              <!-- placeholder -->
         | 
| 30 | 
            +
            <% end %>
         | 
| 31 | 
            +
            ```
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            custom `<futurism-element>`s (in the form of a `<div>` or a `<tr is="futurism-table-row">` are rendered. Those custom elements have an `IntersectionObserver` attached that will send a signed global id to an ActionCable channel (`FuturismChannel`) which will then replace the placeholders with the actual resource partial.
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            With that method, you could lazy load every class that has to_partial_path defined (ActiveModel has by default).
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            You can pass the placeholder as a block:
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            ```erb
         | 
| 40 | 
            +
            <%= futurize @posts, extends: :tr do %>
         | 
| 41 | 
            +
              <td class="placeholder"></td>
         | 
| 42 | 
            +
            <% end %>
         | 
| 43 | 
            +
            ```
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            ## API
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            Currently there are two ways to call `futurize`, designed to wrap `render`'s behavior:
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            ### Resource
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            You can pass a single `ActiveRecord` or an `ActiveRecord::Relation` to `futurize`, just as you would call `render`:
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            ```erb
         | 
| 56 | 
            +
            <%= futurize @posts, extends: :tr do %>
         | 
| 57 | 
            +
              <td class="placeholder"></td>
         | 
| 58 | 
            +
            <% end %>
         | 
| 59 | 
            +
            ```
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            #### Partial Path
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            Remember that you can override the partial path in you models, like so:
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            ```rb
         | 
| 66 | 
            +
            class Post < ApplicationRecord
         | 
| 67 | 
            +
              def to_partial_path
         | 
| 68 | 
            +
                "home/post"
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
| 71 | 
            +
            ```
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            That way you get maximal flexibility when just specifying a single resource.
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            ### Explicit Partial
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            Call `futurize` with a `partial` keyword:
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            ```erb
         | 
| 80 | 
            +
            <%= futurize partial: "items/card", locals: {card: @card}, extends: :div do %>
         | 
| 81 | 
            +
              <div class="spinner"></div>
         | 
| 82 | 
            +
            <% end %>
         | 
| 83 | 
            +
            ```
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            You can also use the shorthand syntax:
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            ```erb
         | 
| 88 | 
            +
            <%= futurize "items/card", card: @card, extends: :div do %>
         | 
| 89 | 
            +
              <div class="spinner"></div>
         | 
| 90 | 
            +
            <% end %>
         | 
| 91 | 
            +
            ```
         | 
| 92 | 
            +
             | 
| 93 | 
            +
            #### Collections
         | 
| 94 | 
            +
             | 
| 95 | 
            +
            Collection rendering is also possible:
         | 
| 96 | 
            +
             | 
| 97 | 
            +
            ```erb
         | 
| 98 | 
            +
            <%= futurize partial: "items/card", collection: @cards, extends: :div do %>
         | 
| 99 | 
            +
              <div class="spinner"></div>
         | 
| 100 | 
            +
            <% end %>
         | 
| 101 | 
            +
            ```
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            ## Installation
         | 
| 104 | 
            +
            Add this line to your application's Gemfile:
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            ```ruby
         | 
| 107 | 
            +
            gem 'futurism'
         | 
| 108 | 
            +
            ```
         | 
| 109 | 
            +
             | 
| 110 | 
            +
            And then execute:
         | 
| 111 | 
            +
            ```bash
         | 
| 112 | 
            +
            $ bundle
         | 
| 113 | 
            +
            ```
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            To copy over the javascript files to your application, run
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            ```bash
         | 
| 118 | 
            +
            $ bin/rails futurism:install
         | 
| 119 | 
            +
            ```
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            **! Note that the installer will run `yarn add @minthesize/futurism` for you !**
         | 
| 122 | 
            +
             | 
| 123 | 
            +
            ### Manual Installation
         | 
| 124 | 
            +
            After `bundle`, install the Javascript library:
         | 
| 125 | 
            +
             | 
| 126 | 
            +
            ```bash
         | 
| 127 | 
            +
            $ bin/yarn add @minthesize/futurism
         | 
| 128 | 
            +
            ```
         | 
| 129 | 
            +
             | 
| 130 | 
            +
            In your `app/javascript/channels/index.js`, add the following
         | 
| 131 | 
            +
             | 
| 132 | 
            +
            ```js
         | 
| 133 | 
            +
            import * as Futurism
         | 
| 134 | 
            +
             | 
| 135 | 
            +
            import consumer from './consumer'
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            Futurism.initializeElements()
         | 
| 138 | 
            +
            Futurism.createSubscription(consumer)
         | 
| 139 | 
            +
            ```
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            ## Contributing
         | 
| 142 | 
            +
             | 
| 143 | 
            +
            ## License
         | 
| 144 | 
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         | 
| 145 | 
            +
             | 
| 146 | 
            +
            ## Contributors ✨
         | 
| 147 | 
            +
             | 
| 148 | 
            +
            Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
         | 
| 149 | 
            +
             | 
| 150 | 
            +
            <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
         | 
| 151 | 
            +
            <!-- prettier-ignore-start -->
         | 
| 152 | 
            +
            <!-- markdownlint-disable -->
         | 
| 153 | 
            +
            <table>
         | 
| 154 | 
            +
              <tr>
         | 
| 155 | 
            +
                <td align="center"><a href="http://www.julianrubisch.at"><img src="https://avatars0.githubusercontent.com/u/4352208?v=4" width="100px;" alt=""/><br /><sub><b>Julian Rubisch</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=julianrubisch" title="Code">💻</a></td>
         | 
| 156 | 
            +
                <td align="center"><a href="https://github.com/darkrubyist"><img src="https://avatars2.githubusercontent.com/u/11207292?v=4" width="100px;" alt=""/><br /><sub><b>darkrubyist</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=darkrubyist" title="Code">💻</a> <a href="https://github.com/julianrubisch/futurism/commits?author=darkrubyist" title="Documentation">📖</a></td>
         | 
| 157 | 
            +
                <td align="center"><a href="https://ParamagicDev.github.io/portfolio"><img src="https://avatars2.githubusercontent.com/u/26425882?v=4" width="100px;" alt=""/><br /><sub><b>Konnor Rogers</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=ParamagicDev" title="Code">💻</a></td>
         | 
| 158 | 
            +
                <td align="center"><a href="https://www.andrewm.codes"><img src="https://avatars1.githubusercontent.com/u/18423853?v=4" width="100px;" alt=""/><br /><sub><b>Andrew Mason</b></sub></a><br /><a href="#maintenance-andrewmcodes" title="Maintenance">🚧</a></td>
         | 
| 159 | 
            +
                <td align="center"><a href="http://gorails.com"><img src="https://avatars1.githubusercontent.com/u/67093?v=4" width="100px;" alt=""/><br /><sub><b>Chris Oliver</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=excid3" title="Code">💻</a> <a href="https://github.com/julianrubisch/futurism/pulls?q=is%3Apr+reviewed-by%3Aexcid3" title="Reviewed Pull Requests">👀</a></td>
         | 
| 160 | 
            +
                <td align="center"><a href="https://github.com/leastbad"><img src="https://avatars2.githubusercontent.com/u/38150464?v=4" width="100px;" alt=""/><br /><sub><b>leastbad</b></sub></a><br /><a href="https://github.com/julianrubisch/futurism/commits?author=leastbad" title="Code">💻</a></td>
         | 
| 161 | 
            +
              </tr>
         | 
| 162 | 
            +
            </table>
         | 
| 163 | 
            +
             | 
| 164 | 
            +
            <!-- markdownlint-enable -->
         | 
| 165 | 
            +
            <!-- prettier-ignore-end -->
         | 
| 166 | 
            +
            <!-- ALL-CONTRIBUTORS-LIST:END -->
         | 
| 167 | 
            +
             | 
| 168 | 
            +
            This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 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 = "Futurism"
         | 
| 12 | 
            +
              rdoc.options << "--line-numbers"
         | 
| 13 | 
            +
              rdoc.rdoc_files.include("README.md")
         | 
| 14 | 
            +
              rdoc.rdoc_files.include("lib/**/*.rb")
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            load "rails/tasks/statistics.rake"
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            require "bundler/gem_tasks"
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            require "rake/testtask"
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            Rake::TestTask.new(:test) do |t|
         | 
| 24 | 
            +
              t.libs << "test"
         | 
| 25 | 
            +
              t.pattern = "test/**/*_test.rb"
         | 
| 26 | 
            +
              t.verbose = false
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            task default: :test
         | 
| 
            File without changes
         | 
    
        data/config/routes.rb
    ADDED
    
    
    
        data/lib/futurism.rb
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            require "rails"
         | 
| 2 | 
            +
            require "action_cable"
         | 
| 3 | 
            +
            require "cable_ready"
         | 
| 4 | 
            +
            require "futurism/engine"
         | 
| 5 | 
            +
            require "futurism/channel"
         | 
| 6 | 
            +
            require "futurism/helpers"
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module Futurism
         | 
| 9 | 
            +
              extend ActiveSupport::Autoload
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              autoload :Helpers, "futurism/helpers"
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              ActiveSupport.on_load(:action_view) {
         | 
| 14 | 
            +
                include Futurism::Helpers
         | 
| 15 | 
            +
              }
         | 
| 16 | 
            +
            end
         | 
    
        data/lib/futurism.rb~
    ADDED
    
    
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            module Futurism
         | 
| 2 | 
            +
              class Channel < ActionCable::Channel::Base
         | 
| 3 | 
            +
                include CableReady::Broadcaster
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def subscribed
         | 
| 6 | 
            +
                  stream_from "Futurism::Channel"
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def receive(data)
         | 
| 10 | 
            +
                  resources = data["signed_params"].map { |signed_params|
         | 
| 11 | 
            +
                    [signed_params, Rails.application.message_verifier("futurism").verify(signed_params)]
         | 
| 12 | 
            +
                  }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  ApplicationController.renderer.instance_variable_set(:@env, connection.env)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  resources.each do |signed_params, resource|
         | 
| 17 | 
            +
                    cable_ready["Futurism::Channel"].outer_html(
         | 
| 18 | 
            +
                      selector: "[data-signed-params='#{signed_params}']",
         | 
| 19 | 
            +
                      html: ApplicationController.render(resource)
         | 
| 20 | 
            +
                    )
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  cable_ready.broadcast
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            class FuturismChannel < ApplicationCable::Channel
         | 
| 2 | 
            +
              include CableReady::Broadcaster
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              def subscribed
         | 
| 5 | 
            +
                stream_from "FuturismChannel"
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def receive(data)
         | 
| 9 | 
            +
                resources = data["sgids"].map { |sgid|
         | 
| 10 | 
            +
                  [sgid, GlobalID::Locator.locate_signed(sgid)]
         | 
| 11 | 
            +
                }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                resources.each do |sgid, resource|
         | 
| 14 | 
            +
                  cable_ready["FuturismChannel"].outer_html(
         | 
| 15 | 
            +
                    selector: "[data-sgid='#{sgid}']",
         | 
| 16 | 
            +
                    html: ApplicationController.render(resource)
         | 
| 17 | 
            +
                  )
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                cable_ready.broadcast
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            module Futurism
         | 
| 2 | 
            +
              module Helpers
         | 
| 3 | 
            +
                def futurize(records_or_string = nil, extends:, **options, &block)
         | 
| 4 | 
            +
                  placeholder = capture(&block)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
         | 
| 7 | 
            +
                    futurize_active_record(records_or_string, extends: extends, placeholder: placeholder)
         | 
| 8 | 
            +
                  elsif records_or_string.is_a?(String)
         | 
| 9 | 
            +
                    futurize_with_options(extends: extends, partial: records_or_string, locals: options, placeholder: placeholder)
         | 
| 10 | 
            +
                  else
         | 
| 11 | 
            +
                    futurize_with_options(extends: extends, placeholder: placeholder, **options)
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def futurize_with_options(extends:, placeholder:, **options)
         | 
| 16 | 
            +
                  collection = options.delete(:collection)
         | 
| 17 | 
            +
                  if collection.nil?
         | 
| 18 | 
            +
                    render_element(extends: extends, placeholder: placeholder, options: options)
         | 
| 19 | 
            +
                  else
         | 
| 20 | 
            +
                    collection_class_name = collection.first.class.name
         | 
| 21 | 
            +
                    collection.map { |record|
         | 
| 22 | 
            +
                      render_element(extends: extends, placeholder: placeholder, options: options.merge(locals: {collection_class_name.downcase.to_sym => record}))
         | 
| 23 | 
            +
                    }.join.html_safe
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def futurize_active_record(records, extends:, placeholder:)
         | 
| 28 | 
            +
                  Array(records).map { |record|
         | 
| 29 | 
            +
                    render_element(extends: extends, placeholder: placeholder, options: record)
         | 
| 30 | 
            +
                  }.join.html_safe
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def render_element(extends:, options:, placeholder:)
         | 
| 34 | 
            +
                  case extends
         | 
| 35 | 
            +
                  when :tr
         | 
| 36 | 
            +
                    content_tag :tr, placeholder, data: {signed_params: futurism_signed_params(options)}, is: "futurism-table-row"
         | 
| 37 | 
            +
                  else
         | 
| 38 | 
            +
                    content_tag :"futurism-element", placeholder, data: {signed_params: futurism_signed_params(options)}
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def futurism_signed_params(params)
         | 
| 43 | 
            +
                  Rails.application.message_verifier("futurism").generate(params)
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            module FuturismHelper
         | 
| 2 | 
            +
              def futurize(records, extends: :tr, &block)
         | 
| 3 | 
            +
                placeholder = capture(&block)
         | 
| 4 | 
            +
                Array(records).map { |record|
         | 
| 5 | 
            +
                  case extends
         | 
| 6 | 
            +
                  when :tr
         | 
| 7 | 
            +
                    content_tag :tr, placeholder, data: { sgid: record.to_sgid.to_s }, is: "futurism-table-row"
         | 
| 8 | 
            +
                  else
         | 
| 9 | 
            +
                    content_tag :"futurism-element", placeholder, data: { sgid: record.to_sgid.to_s }
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                }.join.html_safe
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            require "fileutils"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            namespace :futurism do
         | 
| 4 | 
            +
              desc "Let's look into a brighter future with futurism and CableReady"
         | 
| 5 | 
            +
              task install: :environment do
         | 
| 6 | 
            +
                system "yarn add @minthesize/futurism"
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                filepath = %w[
         | 
| 9 | 
            +
                  app/javascript/channels/index.js
         | 
| 10 | 
            +
                  app/javascript/channels/index.ts
         | 
| 11 | 
            +
                  app/javascript/packs/application.js
         | 
| 12 | 
            +
                  app/javascript/packs/application.ts
         | 
| 13 | 
            +
                ]
         | 
| 14 | 
            +
                  .select { |path| File.exist?(path) }
         | 
| 15 | 
            +
                  .map { |path| Rails.root.join(path) }
         | 
| 16 | 
            +
                  .first
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                puts "Updating #{filepath}"
         | 
| 19 | 
            +
                lines = File.open(filepath, "r") { |f| f.readlines }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                unless lines.find { |line| line.start_with?("import * as Futurism") }
         | 
| 22 | 
            +
                  matches = lines.select { |line| line =~ /\A(require|import)/ }
         | 
| 23 | 
            +
                  lines.insert lines.index(matches.last).to_i + 1, "import * as Futurism from '@minthesize/futurism'\n"
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                unless lines.find { |line| line.start_with?("import consumer") }
         | 
| 27 | 
            +
                  matches = lines.select { |line| line =~ /\A(require|import)/ }
         | 
| 28 | 
            +
                  lines.insert lines.index(matches.last).to_i + 1, "import consumer from '../channels/consumer'\n"
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                initialize_line = lines.find { |line| line.start_with?("Futurism.initializeElements") }
         | 
| 32 | 
            +
                lines << "Futurism.initializeElements()\n" unless initialize_line
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                subscribe_line = lines.find { |line| line.start_with?("Futurism.createSubscription") }
         | 
| 35 | 
            +
                lines << "Futurism.createSubscription(consumer)\n" unless subscribe_line
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                File.open(filepath, "w") { |f| f.write lines.join }
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,199 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: futurism
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Julian Rubisch
         | 
| 8 | 
            +
            autorequire:
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2020-07-22 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: '2.0'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '2.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '13.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '13.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: pry
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 0.12.2
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 0.12.2
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: nokogiri
         | 
| 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: standardrb
         | 
| 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: sqlite3
         | 
| 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: spy
         | 
| 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: rack
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - "~>"
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '2.0'
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - "~>"
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '2.0'
         | 
| 125 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            +
              name: rails
         | 
| 127 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 | 
            +
                requirements:
         | 
| 129 | 
            +
                - - ">="
         | 
| 130 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            +
                    version: '6'
         | 
| 132 | 
            +
              type: :runtime
         | 
| 133 | 
            +
              prerelease: false
         | 
| 134 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 | 
            +
                requirements:
         | 
| 136 | 
            +
                - - ">="
         | 
| 137 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            +
                    version: '6'
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: cable_ready
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - ">="
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: '4'
         | 
| 146 | 
            +
              type: :runtime
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - ">="
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: '4'
         | 
| 153 | 
            +
            description: Uses custom html elements with attached IntersectionObserver to automatically
         | 
| 154 | 
            +
              lazy load partials via websockets
         | 
| 155 | 
            +
            email:
         | 
| 156 | 
            +
            - julian@julianrubisch.at
         | 
| 157 | 
            +
            executables: []
         | 
| 158 | 
            +
            extensions: []
         | 
| 159 | 
            +
            extra_rdoc_files: []
         | 
| 160 | 
            +
            files:
         | 
| 161 | 
            +
            - MIT-LICENSE
         | 
| 162 | 
            +
            - README.md
         | 
| 163 | 
            +
            - Rakefile
         | 
| 164 | 
            +
            - app/assets/config/futurism_manifest.js
         | 
| 165 | 
            +
            - config/routes.rb
         | 
| 166 | 
            +
            - lib/futurism.rb
         | 
| 167 | 
            +
            - lib/futurism.rb~
         | 
| 168 | 
            +
            - lib/futurism/channel.rb
         | 
| 169 | 
            +
            - lib/futurism/channel.rb~
         | 
| 170 | 
            +
            - lib/futurism/engine.rb
         | 
| 171 | 
            +
            - lib/futurism/helpers.rb
         | 
| 172 | 
            +
            - lib/futurism/helpers.rb~
         | 
| 173 | 
            +
            - lib/futurism/version.rb
         | 
| 174 | 
            +
            - lib/tasks/futurism_tasks.rake
         | 
| 175 | 
            +
            - lib/tasks/futurism_tasks.rake~
         | 
| 176 | 
            +
            homepage: https://github.com/julianrubisch/futurism
         | 
| 177 | 
            +
            licenses:
         | 
| 178 | 
            +
            - MIT
         | 
| 179 | 
            +
            metadata: {}
         | 
| 180 | 
            +
            post_install_message:
         | 
| 181 | 
            +
            rdoc_options: []
         | 
| 182 | 
            +
            require_paths:
         | 
| 183 | 
            +
            - lib
         | 
| 184 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 185 | 
            +
              requirements:
         | 
| 186 | 
            +
              - - ">="
         | 
| 187 | 
            +
                - !ruby/object:Gem::Version
         | 
| 188 | 
            +
                  version: '0'
         | 
| 189 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 190 | 
            +
              requirements:
         | 
| 191 | 
            +
              - - ">="
         | 
| 192 | 
            +
                - !ruby/object:Gem::Version
         | 
| 193 | 
            +
                  version: '0'
         | 
| 194 | 
            +
            requirements: []
         | 
| 195 | 
            +
            rubygems_version: 3.1.4
         | 
| 196 | 
            +
            signing_key:
         | 
| 197 | 
            +
            specification_version: 4
         | 
| 198 | 
            +
            summary: Lazy-load Rails partials via CableReady
         | 
| 199 | 
            +
            test_files: []
         |