Coder Social home page Coder Social logo

cache_rocket's People

Contributors

teeparham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cache_rocket's Issues

Edit/delete buttons in lists

How would you go on for adding edit/delete buttons for each item in a collection so that they can be shown alongside the post name (for instance)?

Do you create each link using the Proc syntax and pass them in as keys which seems a little messy or is there a way to pass in post name as a key and pass in an object or an id or something for the edit / delete buttons?

posts/index.html.erb

<%= render_cached 'post',
  collection: @posts,
  replace: {
    name: -> (post) { post.name },
    ...
%>

The kind of output I'm trying to get is (simplified):

<tr>
  <td>Post name here</td>
  <td><a href="/posts/1/edit">Edit</a></td>
  <td><a href="/posts/1" data-method="delete">Delete</a></td>
</tr>

Thanks

cache_replace_key is only replaced with the value the first time it is used in a view.

Because CacheReplace::replace_from_hash uses sub! rather than gsub! if cache_replace_key is used with the same key more than once in a view only the first occurrence is replaced with the proper value.

For example:

= hidden_field_tag :person_id, cache_replace_key(:person_id)
= %span{id: "my_span_#{cache_replace_key(:person_id)}"}

Would yield something like

<input type='hidden' value='1234'/>
<span id='my_span_<cr person_id>'>

Expected output would be

<input type='hidden' value='1234'/>
<span id='my_span_1234'>

Key not getting replaced inside quotes

When passing in:

<%= render_cached 'post',
  collection: @posts,
  replace: {
    post_id: -> (post) { post.id.to_s },
    ...
%>

and trying to use it as part of a css class name:

<%= content_tag(:li, class: "js-post-#{cache_replace_key :post_id}", .... do %>

it fails to replace the key and leaves <li class="js-post-&lt;cr post_id&gt;"....> in the html.

Is it because rails is converting the angle brackets to &lt; and &gt; before cache_digest can do a replace on them?

Is there a way around this or should I just pass the class string in as a key into the view?

<%= content_tag(:li, class: (cache_replace_key :list_item_class), ... do %>

Question about collections

Hey there,

I'm running into a problem that likely has an obvious solution.

I'm trying to use render_cached with a partial and a collection like so:

= render_cached "release_listbox", :collection => @releases, replace: { read_indicator: ->(release_listbox){read_indicator_helper(release_listbox)} }
_release_listbox.html.haml (Simplified):

= release_listbox.title
= cache_replace_key 'read_indicator'

However in the partial release_listbox returns nil. However when using a standard render partial: "release_listbox" ... the variable release_listbox returns the individual release.

Am I (likely) doing something wrong?

Thank you for all your work on this gem btw.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.