Class: Ruflet::DSL::App

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

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::MaterialControlMethods

#alert_dialog, #alertdialog, #animated_switcher, #animatedswitcher, #animation, #animation_style, #app_bar, #appbar, #arc, #audio, #auto_complete, #auto_complete_suggestion, #autocomplete, #autocomplete_suggestion, #autocompletesuggestion, #badge, #banner, #bar_chart, #bar_chart_group, #bar_chart_rod, #bar_chart_rod_stack_item, #barchart, #barchartgroup, #barchartrod, #barchartrodstackitem, #bottom_app_bar, #bottom_sheet, #bottomappbar, #bottomsheet, #button, #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, #color, #column, #container, #context_menu, #contextmenu, #data_cell, #data_column, #data_row, #data_table, #datacell, #datacolumn, #datarow, #datatable, #date_picker, #date_range_picker, #datepicker, #daterangepicker, #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, #fill, #filled_button, #filled_icon_button, #filled_tonal_button, #filled_tonal_icon_button, #filledbutton, #fillediconbutton, #filledtonalbutton, #filledtonaliconbutton, #floating_action_button, #floatingactionbutton, #gesture_detector, #gesturedetector, #grid_view, #gridview, #icon, #icon_button, #iconbutton, #image, #interactive_viewer, #interactiveviewer, #keyboard_listener, #keyboardlistener, #line, #line_chart, #line_chart_data, #line_chart_data_point, #linechart, #linechartdata, #linechartdatapoint, #list_tile, #list_view, #listtile, #listview, #map, #markdown, #marker, #marker_layer, #markerlayer, #menu_bar, #menu_item_button, #menubar, #menuitembutton, #merge_semantics, #mergesemantics, #navigation_bar, #navigation_bar_destination, #navigation_drawer, #navigation_drawer_destination, #navigation_rail, #navigation_rail_destination, #navigationbar, #navigationbardestination, #navigationdrawer, #navigationdrawerdestination, #navigationrail, #navigationraildestination, #outlined_button, #outlined_icon_button, #outlinedbutton, #outlinediconbutton, #oval, #page_view, #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, #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, #row, #safe_area, #safearea, #scatter_chart, #scatter_chart_spot, #scatterchart, #scatterchartspot, #search_bar, #searchbar, #segment, #segmented_button, #segmentedbutton, #selection_area, #selectionarea, #semantics, #shadow, #simple_attribution, #simpleattribution, #slider, #snack_bar, #snackbar, #stack, #submenu_button, #submenubutton, #switch, #tab, #tab_bar, #tab_bar_view, #tabbar, #tabbarview, #tabs, #text, #text_button, #text_field, #textbutton, #textfield, #tile_layer, #tilelayer, #time_picker, #timepicker, #transparent_pointer, #transparentpointer, #url_launcher, #vertical_divider, #verticaldivider, #video, #view, #web_view, #webview, #window_drag_area, #windowdragarea

Constructor Details

#initialize(host:, port:) ⇒ App

Returns a new instance of App.



361
362
363
364
365
366
367
368
369
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 361

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.



359
360
361
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 359

def host
  @host
end

#page_propsObject (readonly)

Returns the value of attribute page_props.



359
360
361
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 359

def page_props
  @page_props
end

#portObject (readonly)

Returns the value of attribute port.



359
360
361
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 359

def port
  @port
end

Instance Method Details

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



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 386

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



415
416
417
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 415

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

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



376
377
378
379
380
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 376

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

#runObject



419
420
421
422
423
424
425
426
427
428
429
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 419

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?
    runtime_page.add(*app_roots)
  end.start
end

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



407
408
409
410
411
412
413
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 407

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



371
372
373
374
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 371

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

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



382
383
384
# File 'lib/ruflet_ui/ruflet/dsl.rb', line 382

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