Class: Sinatra::Kagero::Page

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/sinatra/kagero/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**props) ⇒ Page

Returns a new instance of Page.



39
40
41
42
43
# File 'lib/sinatra/kagero/page.rb', line 39

def initialize(**props)
  @kagero_props = self.class.kagero_props_schema.coerce(props)
  @kagero_props.each { |name, value| instance_variable_set(:"@#{name}", value) }
  super()
end

Instance Attribute Details

#kagero_propsObject (readonly)

Returns the value of attribute kagero_props.



37
38
39
# File 'lib/sinatra/kagero/page.rb', line 37

def kagero_props
  @kagero_props
end

Class Method Details

.inherited(subclass) ⇒ Object



9
10
11
12
# File 'lib/sinatra/kagero/page.rb', line 9

def inherited(subclass)
  super
  subclass.instance_variable_set(:@kagero_props_schema, kagero_props_schema.dup)
end

.kagero_component_nameObject



28
29
30
# File 'lib/sinatra/kagero/page.rb', line 28

def kagero_component_name
  name.to_s.sub(/\APages::/, "").gsub("::", "/")
end

.kagero_props_schemaObject



32
33
34
# File 'lib/sinatra/kagero/page.rb', line 32

def kagero_props_schema
  @kagero_props_schema ||= Props::Schema.new
end

.prop(name, type = nil, **options) ⇒ Object



19
20
21
# File 'lib/sinatra/kagero/page.rb', line 19

def prop(name, type = nil, **options)
  kagero_props_schema.prop(name, type, **options)
end

.props(&block) ⇒ Object



14
15
16
17
# File 'lib/sinatra/kagero/page.rb', line 14

def props(&block)
  kagero_props_schema.instance_eval(&block) if block
  kagero_props_schema
end

.title(value = nil, &block) ⇒ Object



23
24
25
26
# File 'lib/sinatra/kagero/page.rb', line 23

def title(value = nil, &block)
  @kagero_title = block || value unless value.nil? && block.nil?
  @kagero_title
end

Instance Method Details

#kagero_titleObject



45
46
47
48
49
50
51
# File 'lib/sinatra/kagero/page.rb', line 45

def kagero_title
  configured = self.class.title
  return instance_exec(&configured).to_s if configured.respond_to?(:call)
  return configured.to_s unless configured.nil?

  self.class.kagero_component_name
end