There's one thing that I felt was missing from the CableReady ecosystem and should be doable: lazy loading
I introduce:
with a helper in your template
<%= futurize @posts %>| function encodeAssetCacheName(contentType, contentLength) { | |
| return Buffer.from(`${contentType}:${contentLength}`).toString("base64"); | |
| } | |
| function decodeAssetCacheName(encodedString) { | |
| const decodedFileName = Buffer.from(encodedString, "base64").toString( | |
| "ascii" | |
| ); | |
| return decodedFileName.split(":"); | |
| } |
| /* from https://github.com/segment-boneyard/hash-mod/blob/master/lib/index.js */ | |
| function integerHash(string) { | |
| return (string + "").split("").reduce((memo, item) => { | |
| return (memo * 31 * item.charCodeAt(0)) % 982451653; | |
| }, 7); | |
| } | |
| function makeAssetCachePath(cacheDir, cacheKey) { | |
| const hash = crypto | |
| .createHash("sha256") |
| router.get( | |
| "/:asset_type/:space_id/:asset_id/:token/:name", | |
| async (req, res, next) => { | |
| const format = req.query.fm; | |
| const width = req.query.w; | |
| const { asset_type, space_id, asset_id, token, name } = req.params; | |
| res.locals.fetchUrl = `https://${asset_type}.ctfassets.net/${space_id}/${asset_id}/${token}/${name}?fm=${format}${ | |
| width ? `&w=${width}` : "" |
| function evictLeastRecentlyUsed(cacheDir, maxSize, logger) { | |
| getFolderSize(cacheDir, (err, size) => { | |
| if (err) { | |
| throw err; | |
| } | |
| if (size >= maxSize) { | |
| try { | |
| // find least recently used file | |
| const leastRecentlyUsed = findLeastRecentlyUsed(cacheDir); |
| require 'fileutils' | |
| namespace :solargraph do | |
| task update_model_definitions: :environment do | |
| if Rails.env.development? | |
| Rails.application.eager_load! unless Rails.application.config.cache_classes | |
| Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk) | |
| ApplicationRecord.descendants.each do |model| | |
| def_file = Rails.root.join('config', 'model_definitions', "#{model.name.underscore}.rb") |
| image: "ruby:2.7" | |
| services: | |
| - postgres | |
| - redis:latest | |
| variables: | |
| RAILS_ENV: test | |
| POSTGRES_DB: my_app_test | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: "password" |
| class ArticlesController < ApplicationController | |
| def index | |
| @articles = Article.where(session[:articles][:param] => session[:articles][:value]) | |
| end | |
| end |
| <%= article.title # ... etc %> |
| <%= form_with(model: model, data: {controller: "reflex-form", reflex_form_reflex: "ExampleReflex#submit"}) do |form| %> | |
| <%= form.button data: {action: "click->reflex-form#submit"} %> | |
| <% end %> |