labml icon indicating copy to clipboard operation
labml copied to clipboard

Need to extend Slim with shortcuts

Open aishek opened this issue 9 years ago • 10 comments

I need to extend Slim with shortcuts, but Brakeman shows shortcuts in templates as errors.

shortcut = Slim::Parser.options[:shortcut]
shortcut['@']  = { attr: 'data-role' }
shortcut['@@'] = { attr: 'data-block' }
Slim::Engine.options[:merge_attrs]['data-role']  = ' '
Slim::Engine.options[:merge_attrs]['data-block'] = ' '

Is it possible to extend Slim with shortcuts for Brakeman?

aishek avatar Apr 27 '15 13:04 aishek

Hi Alexandr,

Yes, this should be possible. Where is this set? In an initializer?

presidentbeef avatar Apr 27 '15 20:04 presidentbeef

Hi Justin,

I am using initializer from engine: https://github.com/ai/evil-blocks/blob/master/lib/evil-blocks-rails.rb

aishek avatar Apr 27 '15 20:04 aishek

Oh. I'm not sure how that would work, then.

presidentbeef avatar Apr 27 '15 20:04 presidentbeef

I created initializer:

# config/initializers/brakeman_slim.rb

if defined?(Slim::Parser)
  shortcut = Slim::Parser.options[:shortcut]
  shortcut['@']  = { attr: 'data-role' }
  shortcut['@@'] = { attr: 'data-block' }
  Slim::Engine.options[:merge_attrs]['data-role']  = ' '
  Slim::Engine.options[:merge_attrs]['data-block'] = ' '
end

Run brakeman, and got Unknown line indicator error on the template:

@@test
  | Hello

aishek avatar Apr 28 '15 05:04 aishek

If the initializer is defined inside your project, then I can make Brakeman work with it.

presidentbeef avatar Apr 28 '15 15:04 presidentbeef

Justin, thank you very much, I'd like to make pull request by myself. If I add code to brakeman, which will load config/brakeman.rb if present, where developer could put slim settings or other, it will be ok?

aishek avatar Apr 28 '15 18:04 aishek

No, Brakeman cannot execute any code from the application, as that would be a security issue.

presidentbeef avatar Apr 28 '15 18:04 presidentbeef

I'm stuck, Justin, please help :) Is there any possibility to told brakeman to use Slim shortcuts?

aishek avatar Apr 28 '15 18:04 aishek

Yes, but it won't be very straightforward, sorry. Brakeman will need to read the shortcuts from the initializer and then set them when actually processing the Slim templates.

presidentbeef avatar Apr 28 '15 21:04 presidentbeef

Ok, thanks.

aishek avatar May 04 '15 07:05 aishek