Git Product home page Git Product logo

Comments (9)

mkastner avatar mkastner commented on August 16, 2024 1

@apotonick This is really great news. I've been using cells for years and it has served me wonderfully. Thank you for all the work you and the others have put into it. I'm looking forward to the new version. I really mean it: thank you!!!

from cells.

mkastner avatar mkastner commented on August 16, 2024 1

Foremost encapsulation. I've created created messy frontends with rails partials. That never happened to me while i was using cells. Especially, when creating them in the controller. I am actually considering rails for some future projects again - just because of cells.

Nesting? I've had only a few cases, where I had actually missed it in terms of composition. Usually I try to keep the components simple and flat. But that's me.

In my line of work so far, I haven't run into any issues with html escaping or maybe I have, but then it hasn't bothered me as much to really remember it.

Yes, I use context, when it's the only feasible solution. If overused, it can turn into messy solutions from a standpoint of code readability.

I am sorry, i can't be more specific at the moment.

from cells.

samstickland avatar samstickland commented on August 16, 2024 1

For me, the best feature is the encapsulation.

Not really ever missed 'proper' nesting - in fact I'm not really sure what this would be?

Not having easy control over the initializer is a little bit odd at times. Or rather I guess always having to have a model is. Sometimes we have cells that have no model, but do take a variety of options to alter their rendering. We also pretty much always do alias something model in every cell in order to have better documentation as to what the cell's model is.

Escaping was a problem for us, but we actually put in for ourselves (see attached code)

We use context , but not in the way you might think. We fetch current_user via context[:current_user] || context[:controller].current_user (which allows us to pass in current_user in tests where the controller method isn't available.

module Cell
  # Cells do not escape any html by default, which might be dangerous.
  # Overriding setting below re-enables escaping and html_safe? feature
  module Slim
    def template_options_for(_options)
      {
        template_class: ::Slim::Template,
        suffix: "slim",
        disable_escape: false,
        escape_code: false,
        use_html_safe: true,
        buffer: "@output_buffer",
        generator: Temple::Generators::RailsOutputBuffer
      }
    end

    module Helpers
      def with_output_buffer(block_buffer = ActionView::OutputBuffer.new)
        old_buffer = @output_buffer
        @output_buffer = block_buffer
        yield
        @output_buffer = old_buffer

        block_buffer
      end
    end

    Cell::ViewModel.include(Helpers)
  end

  module HtmlSafetyFixes
    module HtmlSafe
      def html_safe?
        true
      end
    end

    module CollectionJoin
      def join(separator = '')
        separator = ''.html_safe + separator

        outputs = @ary.map.with_index do |model, i|
          cell = @cell_class.build(model, @options)
          block_given? ? yield(cell, i) : cell
        end

        outputs
          .map { |output| ''.html_safe + output }
          .join(separator)
          .html_safe
      end
    end

    ::Cell::ViewModel.include(HtmlSafe)
    ::Cell::Collection.include(HtmlSafe)
    ::Cell::Collection.prepend(CollectionJoin)
  end
end

from cells.

yogeshjain999 avatar yogeshjain999 commented on August 16, 2024

@mkastner fixed it, thanks for pointing it out. We released new website for TRB which made this URL invalid.

from cells.

apotonick avatar apotonick commented on August 16, 2024

Hey @mkastner we actually have some goodies planned for Cells 5.

from cells.

apotonick avatar apotonick commented on August 16, 2024

😊 Thanks @mkastner! Since you're here, can you answer me a few questions?

  • What do you like about Cells? (e.g. encapsulation?)
  • What is definitely missing? (e.g. proper nesting)
  • Have you had issues with HTML escaping? (we're working on a different approach here)
  • Do you use "advanced" features such as :context?

from cells.

apotonick avatar apotonick commented on August 16, 2024

@samstickland Oh cool, thanks! One thing I want to change is that cells always receive one object only in the initializer, one that responds to a hash interface.

from cells.

samstickland avatar samstickland commented on August 16, 2024

@apotonick We also ended up adding a module to make the option handling easier.. The purpose was so that the code ends up self-documenting the options the cell supports. It looks like this:

class SomeCell < Trailblazer::Cell
  include ::Cell::OptionHandling

  option :option_one
  option :option_two, required: true
  option :option_three, default: 'something'

And the methods option_one, option_two are available in the cell.

from cells.

yogeshjain999 avatar yogeshjain999 commented on August 16, 2024

BTW, we've deployed a change on documentation website which handles broken URLs and suggests new page links 🍻

from cells.

Related Issues (20)

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.