trailblazer/cells

Confusing file structure - views or view?

Fodoj opened this issue · 7 comments

Fodoj commented

The getting started guide for cells talks about using view, like app/concepts/pro/view/navigation.haml. But everywhere else views is used, like in Load docs: http://trailblazer.to/gems/trailblazer/loader.html. And yet when I follow getting started guide, but use views instead of view, I get this error when Rails is trying to load assets:

Error: File to import not found or unreadable: header.
       Parent style sheet: /home/kshirinkin/work/mkdev/application/app/assets/stylesheets/application.scss
        on line 28 of app/assets/stylesheets/application.scss
>> @import "header";
   ^

So what's the convention here?

Just use this: http://trailblazer.to/gems/cells/trailblazer.html and nothing else (no ViewModel or Concept because we're ditching the old styles in Cells 5).

Doc restructuring coming, too 😜

Fodoj commented

@apotonick that's exactly what I use! I have:

app/concents/myapp/cell/base.rb
app/concents/myapp/cell/navigation.rb
app/concepts/myapp/view/navigation.erb

base cell is simple:

require "cell/translation"

module MyApp::Cell
  class Base < Trailblazer::Cell
    include ActionView::Helpers::TranslationHelper
    include ::Cell::Translation
    include ::Cell::Erb
    include Devise::Controllers::Helpers

    def self.translation_path
     "concepts.#{name.downcase.gsub("::", ".")}"
    end

    def current_user
      UserDecorator.decorate(super) unless super.nil?
    end

    def default_url_options
      { locale: I18n.locale }.merge(super)
    end

  end
end

Navigation cell has a couple of methods, but that does't matter. And view/navigation.erb is an erb template, of course. And so when I change view to views, it breaks with error in my initial post.

On top of that, I have another concept - app/concepts/payment:

app/concepts/payment/cell/form.rb
app/concepts/payment/viewS/form.erb

And Payment::Cell:Form inherits from MyApp::Cell::Base:

module Payment::Cell

  class Form < MyApp::Cell::Base
  end
end

And so another error I have, when I try to use this cell like this:

<%= cell(Payment::Cell::Form, nil, current_user: current_user) %>

Is this:

uninitialized constant Cell::Form

I guess it is also related to the way trailblazer loads code.

Gemfile:

gem "trailblazer-cells"
gem "cells-rails"
gem "cells-erb"
Fodoj commented

Note that I have rails model Payment, and if I rename Payment module to be, I dunno, "Mpayment", then it seems to work. :\

Welcome to the great world of Rails autoloading! With the trailblazer-rails gem it should automatically load your cells. Can you test?

Fodoj commented

Yep, trailblazer-rails fixed it. Good that I planned to use couple of other trailblazer components, otherwise pulling all these deps into project is meh

Yeah, actually there should be something like trailblazer-rails-loader!