Sha256: 549b04c67738e21a3d3fdcf8d32150aa6860a8329af0b650943dff3b1d3eb7c5

Contents?: true

Size: 564 Bytes

Versions: 4

Compression:

Stored size: 564 Bytes

Contents

# frozen_string_literal: true

module Components
	class Example < Phlex::HTML
		def initialize
			@sandbox = Module.new
		end

		def template(&block)
			render Tabs.new do |t|
				@t = t
				yield self
			end
		end

		def tab(name, code, syntax: :ruby)
			@t.tab(name) do
				render CodeBlock.new(code, syntax: syntax)
			end

			@sandbox.class_eval(code) if syntax == :ruby
		end

		def execute(code)
			output = @sandbox.class_eval(code)

			@t.tab("👀 Output") do
				render CodeBlock.new(HtmlBeautifier.beautify(output), syntax: :html)
			end
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
phlex-0.5.3 docs/components/example.rb
phlex-0.5.2 docs/components/example.rb
phlex-0.5.1 docs/components/example.rb
phlex-0.5.0 docs/components/example.rb