Class: RailsCommandPalette::CommandPalette
- Inherits:
-
Object
- Object
- RailsCommandPalette::CommandPalette
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/rails_command_palette/command_palette.rb
Instance Method Summary collapse
- #flatten_commands(commands, flattened = []) ⇒ Object
-
#initialize(commands, options = {}) ⇒ CommandPalette
constructor
A new instance of CommandPalette.
- #to_html ⇒ Object
Constructor Details
#initialize(commands, options = {}) ⇒ CommandPalette
Returns a new instance of CommandPalette.
5 6 7 8 |
# File 'lib/rails_command_palette/command_palette.rb', line 5 def initialize(commands, = {}) @commands = flatten_commands(commands) @options = end |
Instance Method Details
#flatten_commands(commands, flattened = []) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails_command_palette/command_palette.rb', line 10 def flatten_commands(commands, flattened = []) commands.each do |cmd| flattened << cmd if cmd[:children].present? flatten_commands(cmd[:children], flattened) cmd[:children] = cmd[:children].map do |childCmd| childCmd[:parent] = cmd[:id] childCmd[:id] end end end flattened end |
#to_html ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rails_command_palette/command_palette.rb', line 24 def to_html tag("ninja-keys", @options.merge( data: { controller: "command-palette", command_palette_commands_value: @commands } )) end |