Module: Ruflet::Rails::InstallSupport
- Defined in:
- lib/ruflet/rails/install_support.rb
Class Method Summary collapse
-
.build_args_for_platform(platform, ruflet_url: nil) ⇒ Object
ruflet_rails builds only native clients.
- .default_app_template(app_title:) ⇒ Object
- .default_backend_url ⇒ Object
- .default_entrypoint_path ⇒ Object
- .default_initializer(app_name:) ⇒ Object
- .default_ruflet_yaml(app_name:) ⇒ Object
- .host_desktop_platform ⇒ Object
- .install_next_steps(target:, entrypoint:, client:, mount_path: "/ws") ⇒ Object
- .normalize_build_platform(platform) ⇒ Object
- .route_snippet(entrypoint: default_entrypoint_path, mount_path: "/ws", helper: "app") ⇒ Object
- .ruby_desktop_flag_bootstrap ⇒ Object
- .ruby_dev_desktop_flag_bootstrap ⇒ Object
- .shell_desktop_flag_bootstrap ⇒ Object
- .web_route_snippet(entrypoint: default_entrypoint_path, mount_path: "/ruflet") ⇒ Object
Class Method Details
.build_args_for_platform(platform, ruflet_url: nil) ⇒ Object
ruflet_rails builds only native clients. The web client is installed prebuilt (rake ruflet:web), never compiled, so "web" is not a build target here.
130 131 132 133 134 135 136 |
# File 'lib/ruflet/rails/install_support.rb', line 130 def build_args_for_platform(platform, ruflet_url: nil) normalized = normalize_build_platform(platform) return [] if normalized.to_s.empty? return [] if normalized == "web" [normalized] end |
.default_app_template(app_title:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruflet/rails/install_support.rb', line 10 def default_app_template(app_title:) <<~RUBY # frozen_string_literal: true # The home screen for this Ruflet app. You own this file; nothing is # auto-discovered. It is mounted explicitly in config/routes.rb: # match "/ws", to: Ruflet::Rails.app(Rails.root.join("app/views/ruflet/main.rb")), via: :all Ruflet.run do |page| page.title = #{app_title.inspect} page.add( safe_area( container( expand: true, padding: 24, content: column( spacing: 12, controls: [ text(#{app_title.inspect}, size: 24, weight: "bold"), text("Edit app/views/ruflet/main.rb to build your app.") ] ) ), expand: true ) ) end RUBY end |
.default_backend_url ⇒ Object
107 108 109 |
# File 'lib/ruflet/rails/install_support.rb', line 107 def default_backend_url "http://localhost:3000" end |
.default_entrypoint_path ⇒ Object
138 139 140 |
# File 'lib/ruflet/rails/install_support.rb', line 138 def default_entrypoint_path File.join("app", "views", "ruflet", "main.rb") end |
.default_initializer(app_name:) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruflet/rails/install_support.rb', line 53 def default_initializer(app_name:) <<~RUBY # frozen_string_literal: true Ruflet::Rails.configure do |config| config.app_name = #{app_name.inspect} config.backend_url = ENV.fetch("RUFLET_BACKEND_URL", #{default_backend_url.inspect}) config.services = [] # Build assets. Replace these with your app artwork when ready. config.splash_screen = Rails.root.join("app/assets/images/splash.png") config.icon_launcher = Rails.root.join("app/assets/images/icon.png") end RUBY end |
.default_ruflet_yaml(app_name:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruflet/rails/install_support.rb', line 39 def default_ruflet_yaml(app_name:) <<~YAML app: name: #{app_name} backend_url: #{default_backend_url} services: [] assets: splash_screen: assets/splash.png icon_launcher: assets/icon.png YAML end |
.host_desktop_platform ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/ruflet/rails/install_support.rb', line 111 def host_desktop_platform host_os = RbConfig::CONFIG["host_os"] return "macos" if host_os.match?(/darwin/i) return "linux" if host_os.match?(/linux/i) return "windows" if host_os.match?(/mswin|mingw|cygwin/i) nil end |
.install_next_steps(target:, entrypoint:, client:, mount_path: "/ws") ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ruflet/rails/install_support.rb', line 150 def install_next_steps(target:, entrypoint:, client:, mount_path: "/ws") lines = [ "Ruflet Rails installed.", "Generated entrypoint: #{entrypoint}", "Added WebSocket route #{mount_path} to config/routes.rb", "Next steps:", " 1. Start Rails: bin/rails server", " 2. Connect your Ruflet app to ws://localhost:3000#{mount_path}" ] if %w[desktop all].include?(client.to_s) lines += [ "Desktop clients are server-driven and connect to this Rails app.", "Plain bin/dev, bin/rails server, and bin/rails s do not launch desktop.", "To launch desktop for a dev server run: bin/rails s --desktop or bin/dev --desktop", "To download the prebuilt desktop client: bin/rails ruflet:update[desktop]", "To build the host desktop client: bin/rails ruflet:build[desktop]" ] end if %w[web all].include?(client.to_s) lines += [ "Web client installed into frontend/.", "Open the mounted Ruflet web app at http://localhost:3000/ruflet" ] end lines end |
.normalize_build_platform(platform) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/ruflet/rails/install_support.rb', line 120 def normalize_build_platform(platform) value = platform.to_s.strip.downcase return host_desktop_platform if value == "desktop" value end |
.route_snippet(entrypoint: default_entrypoint_path, mount_path: "/ws", helper: "app") ⇒ Object
142 143 144 |
# File 'lib/ruflet/rails/install_support.rb', line 142 def route_snippet(entrypoint: default_entrypoint_path, mount_path: "/ws", helper: "app") %(match "#{mount_path}", to: Ruflet::Rails.#{helper}(Rails.root.join("#{entrypoint}")), via: :all) end |
.ruby_desktop_flag_bootstrap ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruflet/rails/install_support.rb', line 70 def ruby_desktop_flag_bootstrap <<~RUBY # ruflet_rails desktop flag ruflet_rails_desktop = ARGV.include?("--desktop") ruflet_rails_command = ARGV.find { |value| !value.to_s.start_with?("-") } if ruflet_rails_desktop && %w[server s].include?(ruflet_rails_command.to_s) ENV["RUFLET_RAILS_DESKTOP"] = "true" ENV["RUFLET_RAILS_DESKTOP_SERVER"] = "true" end ARGV.delete("--desktop") RUBY end |
.ruby_dev_desktop_flag_bootstrap ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ruflet/rails/install_support.rb', line 84 def ruby_dev_desktop_flag_bootstrap <<~RUBY # ruflet_rails desktop flag if ARGV.delete("--desktop") ENV["RUFLET_RAILS_DESKTOP"] = "true" ENV["RUFLET_RAILS_DESKTOP_SERVER"] = "true" end RUBY end |
.shell_desktop_flag_bootstrap ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruflet/rails/install_support.rb', line 95 def shell_desktop_flag_bootstrap <<~SH # ruflet_rails desktop flag if [ "$1" = "--desktop" ]; then export RUFLET_RAILS_DESKTOP=true export RUFLET_RAILS_DESKTOP_SERVER=true shift fi SH end |
.web_route_snippet(entrypoint: default_entrypoint_path, mount_path: "/ruflet") ⇒ Object
146 147 148 |
# File 'lib/ruflet/rails/install_support.rb', line 146 def web_route_snippet(entrypoint: default_entrypoint_path, mount_path: "/ruflet") %(mount Ruflet::Rails.web_app(app_file: Rails.root.join("#{entrypoint}")), at: "#{mount_path}") end |