Class: Ruflet::DSL::App

Inherits:
Object
  • Object
show all
Includes:
UI::ControlMethods
Defined in:
lib/ruflet_ui/ruflet/dsl.rb

Constant Summary

Constants included from UI::MaterialControlMethods

UI::MaterialControlMethods::SPINKIT_VARIANTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UI::CupertinoControlMethods

#cupertino_action_sheet, #cupertino_action_sheet_action, #cupertino_activity_indicator, #cupertino_alert_dialog, #cupertino_app_bar, #cupertino_bottom_sheet, #cupertino_button, #cupertino_checkbox, #cupertino_context_menu, #cupertino_context_menu_action, #cupertino_date_picker, #cupertino_dialog_action, #cupertino_filled_button, #cupertino_list_tile, #cupertino_navigation_bar, #cupertino_picker, #cupertino_radio, #cupertino_segmented_button, #cupertino_slider, #cupertino_sliding_segmented_button, #cupertino_switch, #cupertino_text_field, #cupertino_timer_picker, #cupertino_tinted_button, #cupertinoactionsheet, #cupertinoactionsheetaction, #cupertinoactivityindicator, #cupertinoalertdialog, #cupertinoappbar, #cupertinobottomsheet, #cupertinobutton, #cupertinocheckbox, #cupertinocontextmenu, #cupertinocontextmenuaction, #cupertinodatepicker, #cupertinodialogaction, #cupertinofilledbutton, #cupertinolisttile, #cupertinonavigationbar, #cupertinopicker, #cupertinoradio, #cupertinosegmentedbutton, #cupertinoslider, #cupertinoslidingsegmentedbutton, #cupertinoswitch, #cupertinotextfield, #cupertinotimerpicker, #cupertinotintedbutton

Methods included from UI::PlatformControlMethods

#action_sheet, #action_sheet_action, #actionsheet, #actionsheetaction, #context_menu_action, #contextmenuaction, #picker, #timer_picker, #timerpicker

Methods included from UI::MaterialControlMethods

#accelerometer, #alert_dialog, #alertdialog, #animated_switcher, #animatedswitcher, #animation, #animation_style, #app_bar, #appbar, #arc, #audio, #audio_recorder, #auto_complete, #auto_complete_suggestion, #autocomplete, #autocomplete_suggestion, #autocompletesuggestion, #autofill_group, #autofillgroup, #badge, #banner, #banner_ad, #bannerad, #bar_chart, #bar_chart_group, #bar_chart_rod, #bar_chart_rod_stack_item, #barchart, #barchartgroup, #barchartrod, #barchartrodstackitem, #barometer, #base_page, #basepage, #battery, #block_picker, #blockpicker, #bottom_app_bar, #bottom_sheet, #bottomappbar, #bottomsheet, #browser_context_menu, #button, #camera, #candlestick_chart, #candlestick_chart_spot, #candlestickchart, #candlestickchartspot, #canvas, #canvas_color, #card, #center, #chart_axis, #chart_axis_label, #chartaxis, #chartaxislabel, #checkbox, #chip, #circle, #circle_avatar, #circle_layer, #circle_marker, #circleavatar, #circlelayer, #circlemarker, #clipboard, #code_editor, #codeeditor, #color, #color_picker, #colorpicker, #column, #connectivity, #container, #context_menu, #contextmenu, #data_cell, #data_column, #data_column2, #data_row, #data_row2, #data_table, #data_table2, #datacell, #datacolumn, #datacolumn2, #datarow, #datarow2, #datatable, #datatable2, #date_picker, #date_range_picker, #datepicker, #daterangepicker, #dialogs, #dismissible, #divider, #drag_target, #draggable, #dragtarget, #dropdown, #dropdown_m2, #dropdown_option, #dropdownm2, #dropdownoption, #elevated_button, #expansion_panel, #expansion_panel_list, #expansion_tile, #expansionpanel, #expansionpanellist, #expansiontile, #fab, #file_picker, #fill, #filled_button, #filled_icon_button, #filled_tonal_button, #filled_tonal_icon_button, #filledbutton, #fillediconbutton, #filledtonalbutton, #filledtonaliconbutton, #flashlight, #floating_action_button, #floatingactionbutton, #geolocator, #gesture_detector, #gesturedetector, #grid_view, #gridview, #gyroscope, #haptic_feedback, #hero, #hue_ring_picker, #hueringpicker, #icon, #icon_button, #iconbutton, #image, #image_source_attribution, #imagesourceattribution, #interactive_viewer, #interactiveviewer, #interstitial_ad, #interstitialad, #keyboard_listener, #keyboardlistener, #line, #line_chart, #line_chart_data, #line_chart_data_point, #linechart, #linechartdata, #linechartdatapoint, #list_tile, #list_view, #listtile, #listview, #lottie, #magnetometer, #map, #map_coordinate_list, #map_coordinates, #map_layer, #maplayer, #markdown, #marker, #marker_layer, #markerlayer, #material_picker, #materialpicker, #menu_bar, #menu_item_button, #menubar, #menuitembutton, #merge_semantics, #mergesemantics, #multiple_choice_block_picker, #multiplechoiceblockpicker, #native_ad, #nativead, #navigation_bar, #navigation_bar_destination, #navigation_drawer, #navigation_drawer_destination, #navigation_rail, #navigation_rail_destination, #navigationbar, #navigationbardestination, #navigationdrawer, #navigationdrawerdestination, #navigationrail, #navigationraildestination, #option, #outlined_button, #outlined_icon_button, #outlinedbutton, #outlinediconbutton, #oval, #overlay, #page_view, #pagelet, #pageview, #paint, #path, #path_arc, #path_arc_to, #path_close, #path_cubic_to, #path_line_to, #path_move_to, #path_oval, #path_quadratic_to, #path_rect, #path_sub_path, #permission_handler, #pie_chart, #pie_chart_section, #piechart, #piechartsection, #placeholder, #points, #polygon_layer, #polygon_marker, #polygonlayer, #polygonmarker, #polyline_layer, #polyline_marker, #polylinelayer, #polylinemarker, #popup_menu_button, #popup_menu_item, #popupmenubutton, #popupmenuitem, #progress_bar, #progress_ring, #progressbar, #progressring, #radar_chart, #radar_chart_title, #radar_data_set, #radar_data_set_entry, #radarchart, #radarcharttitle, #radardataset, #radardatasetentry, #radio, #radio_group, #radiogroup, #range_slider, #rangeslider, #rect, #reorderable_drag_handle, #reorderable_list_view, #reorderabledraghandle, #reorderablelistview, #responsive_row, #responsiverow, #rich_attribution, #richattribution, #rive, #rotated_box, #rotatedbox, #row, #ruflet_app, #rufletapp, #safe_area, #safearea, #scatter_chart, #scatter_chart_spot, #scatterchart, #scatterchartspot, #screen_brightness, #screenshot, #search_bar, #searchbar, #secure_storage, #segment, #segmented_button, #segmentedbutton, #selection_area, #selectionarea, #semantics, #semantics_service, #service_registry, #serviceregistry, #shader_mask, #shadermask, #shadow, #shake_detector, #share, #shared_preferences, #shimmer, #simple_attribution, #simpleattribution, #slide_picker, #slidepicker, #slider, #snack_bar, #snack_bar_action, #snackbar, #snackbaraction, #spinkit, #stack, #storage_paths, #submenu_button, #submenubutton, #switch, #tab, #tab_bar, #tab_bar_view, #tabbar, #tabbarview, #tabs, #text, #text_button, #text_field, #text_source_attribution, #text_span, #textbutton, #textfield, #textsourceattribution, #textspan, #tile_layer, #tilelayer, #time_picker, #timepicker, #transparent_pointer, #transparentpointer, #url_launcher, #user_accelerometer, #vertical_divider, #verticaldivider, #video, #view, #wakelock, #web_view, #webview, #window, #window_drag_area, #windowdragarea

Constructor Details

#initialize(host:, port:) ⇒ App

Returns a new instance of App.



458
459
460
461
462
463
464
465
466
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 458

def initialize(host:, port:)
  @host = host
  @port = port
  @roots = []
  @services = []
  @stack = []
  @page_props = { "route" => "/" }
  @seq = 0
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



456
457
458
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 456

def host
  @host
end

#page_propsObject (readonly)

Returns the value of attribute page_props.



456
457
458
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 456

def page_props
  @page_props
end

#portObject (readonly)

Returns the value of attribute port.



456
457
458
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 456

def port
  @port
end

Instance Method Details

#control(type, **props, &block) ⇒ Object



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 483

def control(type, **props, &block)
  mapped_props = props.dup
  prop_children = extract_children_prop(mapped_props)

  id = mapped_props.delete(:id)&.to_s || next_id(type)
  c = Ruflet::UI::ControlFactory.build(type.to_s, id: id, **normalize_props(mapped_props))
  attach(c)

  if block
    @stack.push(c)
    instance_eval(&block)
    @stack.pop
  end

  if prop_children
    Array(prop_children).each { |child| c.children << child if child.is_a?(Ruflet::Control) }
  end

  c
end

#duration(**parts) ⇒ Object



512
513
514
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 512

def duration(**parts)
  DSL.duration(**parts)
end

#page(**props, &block) ⇒ Object



473
474
475
476
477
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 473

def page(**props, &block)
  @page_props.merge!(normalize_props(props))
  instance_eval(&block) if block
  self
end

#runObject



516
517
518
519
520
521
522
523
524
525
526
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 516

def run
  app_roots = @roots
  app_services = @services
  page_props = @page_props.dup

  Ruflet::Server.new(host: host, port: port) do |runtime_page|
    runtime_page.set_view_props(page_props)
    runtime_page.add_service(*app_services) if app_services.any?
    app_roots.each { |control| runtime_page.add(control) }
  end.start
end

#service(type, **props, &block) ⇒ Object



504
505
506
507
508
509
510
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 504

def service(type, **props, &block)
  mapped_props = props.dup
  id = mapped_props.delete(:id)&.to_s || next_id(type)
  svc = Ruflet::UI::ControlFactory.build(type.to_s, id: id, **normalize_props(mapped_props))
  @services << svc unless @services.include?(svc)
  svc
end

#set_endpoint!(host:, port:) ⇒ Object



468
469
470
471
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 468

def set_endpoint!(host:, port:)
  @host = host
  @port = port
end

#widget(type, **props, &block) ⇒ Object



479
480
481
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 479

def widget(type, **props, &block)
  control(type.to_s, **props, &block)
end