Class: Mxrb::Dsl::NavigationProfileBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/dsl/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ NavigationProfileBuilder

Returns a new instance of NavigationProfileBuilder.



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/mxrb/dsl/builder.rb', line 466

def initialize(name, **options)
  @name = name.to_s
  @home_page = optional_string(options, :home_page)
  @home_microflow = optional_string(options, :home_microflow)
  @sign_in_page = optional_string(options, :sign_in_page)
  @menu = optional_string(options, :menu)
  @offline = options[:offline] == true
  @kind = optional_string(options, :kind)
  @app_icon = optional_string(options, :app_icon)
  @app_title = normalize_translations(options[:app_title])
  @role_homes = options.fetch(:role_homes, {}).to_h.transform_keys(&:to_s)
                       .transform_values(&:to_s)
  @role_home_details = []
  @items = []
end

Instance Method Details

#evaluate(path) ⇒ Object



500
501
502
# File 'lib/mxrb/dsl/builder.rb', line 500

def evaluate(path)
  instance_eval(File.read(path), path, 1)
end

#evaluate_dir(dir) ⇒ Object



504
505
506
507
508
# File 'lib/mxrb/dsl/builder.rb', line 504

def evaluate_dir(dir)
  return unless File.directory?(dir)

  Dir[File.join(dir, '*.rb')].sort.each { |path| evaluate(path) }
end

#home_for(role, page: nil, microflow: nil) ⇒ Object



486
487
488
489
490
# File 'lib/mxrb/dsl/builder.rb', line 486

def home_for(role, page: nil, microflow: nil)
  @role_home_details << {
    role: role.to_s, page: page&.to_s, microflow: microflow&.to_s
  }.compact
end

#item(caption, page: nil, microflow: nil, icon: nil, translations: {}, &block) ⇒ Object



492
493
494
495
496
497
498
# File 'lib/mxrb/dsl/builder.rb', line 492

def item(caption, page: nil, microflow: nil, icon: nil, translations: {}, &block)
  builder = NavigationMenuItemBuilder.new(
    caption, page:, microflow:, icon:, translations:
  )
  builder.instance_eval(&block) if block
  @items << builder.to_h
end

#title(locale, text) ⇒ Object



482
483
484
# File 'lib/mxrb/dsl/builder.rb', line 482

def title(locale, text)
  @app_title[locale.to_s] = text.to_s
end

#to_hObject



510
511
512
513
514
515
516
517
# File 'lib/mxrb/dsl/builder.rb', line 510

def to_h
  {
    name: @name, home_page: @home_page, home_microflow: @home_microflow,
    sign_in_page: @sign_in_page, menu: @menu, role_homes: @role_homes,
    role_home_details: @role_home_details, offline: @offline, kind: @kind,
    app_title: @app_title, app_icon: @app_icon, items: @items
  }
end