Sha256: a308db761d61eaf1b7b966fc646235f31842f5e2b4d6afaeac8c5cbc054d68b5

Contents?: true

Size: 982 Bytes

Versions: 3

Compression:

Stored size: 982 Bytes

Contents

require 'singleton'
require 'forwardable'

module Lissio

class Application < Component
	def self.inherited(klass)
		super

		klass.include Singleton

		$document.on :load do
			klass.start
		end
	end

	def self.expose(what, options = {})
		if what.start_with?(?@)
			name = what[1 .. -1]

			define_singleton_method name do
				instance.__send__ name
			end

			attr_reader name
		else
			define_singleton_method what do |*args, &block|
				instance.__send__ what, *args, &block
			end
		end
	end

	expose :start
	expose :refresh
	expose :navigate
	expose :@router

	extend Forwardable
	def_delegators :@router, :navigate, :route

	def initialize
		@router = Lissio::Router.new(fragment: false)
	end

	def start
		render

		@router.update
	end

	def refresh
		@router.update
	end

	element :body

	on :click, 'a[href^="/"]' do |e|
		unless e.alt? || e.ctrl? || e.meta? || e.shift?
			e.stop!

			navigate e.target[:href] || e.target.ancestors('a').first[:href]
		end
	end
end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lissio-0.1.0.beta3 opal/lissio/application.rb
lissio-0.1.0.beta2 opal/lissio/application.rb
lissio-0.1.0.beta1 opal/lissio/application.rb