Sha256: e3fe3e141e28242c527cf1360e7ffeac5956ecaaa27fffe3742f825b7d8477a7

Contents?: true

Size: 1.95 KB

Versions: 23

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require 'glimmer-dsl-libui'
require 'facets'

class MetaExample
  include Glimmer
  
  def examples
    if @examples.nil?
      example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '**', '*.rb'))
      example_file_names = example_files.map { |f| File.basename(f, '.rb') }
      example_file_names = example_file_names.reject { |f| f == 'meta_example' }
      @examples = example_file_names.map { |f| f.underscore.titlecase }
    end
    @examples
  end
  
  def file_path_for(example)
    File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
  end
  
  def glimmer_dsl_libui_file
    File.expand_path('../lib/glimmer-dsl-libui', __dir__)
  end
  
  def launch
    window('Meta-Example', 700, 500) { |w|
      margined true
      
      horizontal_box {
        vertical_box {
          @rbs = radio_buttons {
            stretchy false
            items examples
            selected 0
            
            on_selected do
              @nwme.text = File.read(file_path_for(@examples[@rbs.selected]))
            end
          }
          button('Launch') {
            stretchy false
            
            on_clicked do
              begin
                meta_example_file = File.join(Dir.home, '.meta_example.rb')
                File.write(meta_example_file, @nwme.text)
                result = `ruby -r #{glimmer_dsl_libui_file} #{meta_example_file} 2>&1`
                msg_box(w, 'Error Running Example', result) if result.include?('error')
              rescue => e
                puts 'Unable to write code changes! Running original example...'
                system "ruby -r #{glimmer_dsl_libui_file} #{file_path_for(@examples[@rbs.selected])}"
              end
            end
          }
        }
        vertical_box {
          @nwme = non_wrapping_multiline_entry {
            text File.read(file_path_for(@examples[@rbs.selected]))
          }
        }
      }
    }.show
  end
end

MetaExample.new.launch

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
glimmer-dsl-libui-0.1.5 examples/meta_example.rb
glimmer-dsl-libui-0.1.4 examples/meta_example.rb
glimmer-dsl-libui-0.1.3 examples/meta_example.rb
glimmer-dsl-libui-0.1.2 examples/meta_example.rb
glimmer-dsl-libui-0.1.1 examples/meta_example.rb
glimmer-dsl-libui-0.1.0 examples/meta_example.rb
glimmer-dsl-libui-0.0.28 examples/meta_example.rb
glimmer-dsl-libui-0.0.27 examples/meta_example.rb
glimmer-dsl-libui-0.0.26 examples/meta_example.rb
glimmer-dsl-libui-0.0.25 examples/meta_example.rb
glimmer-dsl-libui-0.0.24 examples/meta_example.rb
glimmer-dsl-libui-0.0.23 examples/meta_example.rb
glimmer-dsl-libui-0.0.22 examples/meta_example.rb
glimmer-dsl-libui-0.0.21 examples/meta_example.rb
glimmer-dsl-libui-0.0.20 examples/meta_example.rb
glimmer-dsl-libui-0.0.19 examples/meta_example.rb
glimmer-dsl-libui-0.0.18 examples/meta_example.rb
glimmer-dsl-libui-0.0.17 examples/meta_example.rb
glimmer-dsl-libui-0.0.16 examples/meta_example.rb
glimmer-dsl-libui-0.0.15 examples/meta_example.rb