lib/express_templates/components/base.rb in express_templates-0.5.0 vs lib/express_templates/components/base.rb in express_templates-0.7.0
- old
+ new
@@ -3,52 +3,48 @@
module ExpressTemplates
# Components provide self-contained reusable view code meant to be shared
# within a project or across many projects through a library of components
#
- # Components gain their functionality through inclusion of Capabilities.
- #
- # Most Components are descendents of Components::Base.
- #
module Components
# Components::Base is the base class for ExpressTemplates view components.
#
- # View components are available as macros in ExpressTemplates and may be
- # used to encapsulate common view patterns, behavior and functionality in
- # reusable classes that can be shared within and across projects.
#
- # Components intended to provide a base framework for a library of reusable
- # components to cut development time across a multitude of projects.
- #
- # Components gain their functionality through including Capabilities.
- #
- # Example capabilities include:
- #
- # * Managing related ExpressTemplate fragments
- # * Compiling template fragments for evaluation in a View Context
- # * Specifying rendering logic to be executed in the View Context
- # * Potentially referencing external assets that may be required
- # for the component to work.
- #
- # Components::Base includes the following capabilities:
- #
- # * Capabilities::Templating
- # * Capabilities::Rendering
- # * Capabilities::Wrapping
- # * Capabilities::Iterating
- #
- class Base < Expander
- include ExpressTemplates::Macro
- include Capabilities::Templating
- include Capabilities::Rendering
- include Capabilities::Wrapping
- include Capabilities::Iterating
+ class Base < Arbre::Component
- def self.inherited(klass)
- ExpressTemplates::Expander.register_macros_for klass
+ def self.builder_method_and_class(method_name, klass)
+ Arbre::Element::BuilderMethods.class_eval <<-EOF, __FILE__, __LINE__
+ def #{method_name}(*args, &block)
+ insert_tag ::#{klass.name}, *args, &block
+ end
+ EOF
+ # puts "added #{method_name} -> #{klass.name}"
end
- end
+ def self.emits(proc = nil, &block)
+ define_method(:build, &(proc || block))
+ end
+ def build(*args, block)
+ raise "#build method must be overridden"
+ end
+
+ def resource
+ helpers.resource
+ end
+
+ def self.inherited(subclass)
+ builder_method_and_class subclass.to_s.demodulize.underscore, subclass
+ end
+
+ def indent_level
+ parent_indent_level = parent.try(:indent_level) || 0
+ end
+
+ def to_s
+ children.to_s
+ end
+
+ end
end
end