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.



578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/mxrb/dsl/builder.rb', line 578

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



612
613
614
# File 'lib/mxrb/dsl/builder.rb', line 612

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

#evaluate_dir(dir) ⇒ Object



616
617
618
619
620
# File 'lib/mxrb/dsl/builder.rb', line 616

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



598
599
600
601
602
# File 'lib/mxrb/dsl/builder.rb', line 598

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



604
605
606
607
608
609
610
# File 'lib/mxrb/dsl/builder.rb', line 604

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



594
595
596
# File 'lib/mxrb/dsl/builder.rb', line 594

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

#to_hObject



622
623
624
625
626
627
628
629
# File 'lib/mxrb/dsl/builder.rb', line 622

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