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.



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/mxrb/dsl/builder.rb', line 547

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



581
582
583
# File 'lib/mxrb/dsl/builder.rb', line 581

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

#evaluate_dir(dir) ⇒ Object



585
586
587
588
589
# File 'lib/mxrb/dsl/builder.rb', line 585

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



567
568
569
570
571
# File 'lib/mxrb/dsl/builder.rb', line 567

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



573
574
575
576
577
578
579
# File 'lib/mxrb/dsl/builder.rb', line 573

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



563
564
565
# File 'lib/mxrb/dsl/builder.rb', line 563

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

#to_hObject



591
592
593
594
595
596
597
598
# File 'lib/mxrb/dsl/builder.rb', line 591

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