Class: Phlexing::ComponentGenerator
- Inherits:
-
Object
- Object
- Phlexing::ComponentGenerator
- Includes:
- Helpers
- Defined in:
- lib/phlexing/component_generator.rb
Constant Summary
Constants included from Helpers
Helpers::KNOWN_ELEMENTS, Helpers::SVG_ELEMENTS
Instance Attribute Summary collapse
-
#analyzer ⇒ Object
Returns the value of attribute analyzer.
-
#converter ⇒ Object
Returns the value of attribute converter.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(converter) ⇒ ComponentGenerator
constructor
A new instance of ComponentGenerator.
Methods included from Helpers
#arg, #block, #blocklist, #braces, #children?, #interpolate, #known_rails_helpers, #multiple_children?, #newline, #output, #parens, #quote, #routes_helpers, #siblings?, #string_output?, #symbol, #tag_name, #unescape, #unwrap_erb, #whitespace
Constructor Details
#initialize(converter) ⇒ ComponentGenerator
Returns a new instance of ComponentGenerator.
13 14 15 16 17 |
# File 'lib/phlexing/component_generator.rb', line 13 def initialize(converter) @converter = converter @analyzer = RubyAnalyzer.new @analyzer.analyze(converter.source) end |
Instance Attribute Details
#analyzer ⇒ Object
Returns the value of attribute analyzer.
7 8 9 |
# File 'lib/phlexing/component_generator.rb', line 7 def analyzer @analyzer end |
#converter ⇒ Object
Returns the value of attribute converter.
7 8 9 |
# File 'lib/phlexing/component_generator.rb', line 7 def converter @converter end |
Class Method Details
.call(converter) ⇒ Object
9 10 11 |
# File 'lib/phlexing/component_generator.rb', line 9 def self.call(converter) new(converter).call end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/phlexing/component_generator.rb', line 19 def call out = StringIO.new out << "class " out << .component_name out << " < " out << .parent_component out << newline analyzer.includes.sort.each do |inklude| out << "include " out << inklude out << newline end out << newline if analyzer.includes.any? if analyzer.locals.any? out << "attr_accessor " out << build_accessors out << newline out << newline end converter.custom_elements.sort.each do |element| out << "register_element :" out << element out << newline end out << newline if converter.custom_elements.any? if kwargs.any? out << "def initialize(" out << build_kwargs out << ")" out << newline kwargs.each do |dep| out << "@#{dep} = #{dep}\n" end out << "end" out << newline out << newline end out << "def #{.template_name}" out << newline out << converter.template_code out << newline out << "end" if analyzer.instance_methods.any? out << newline out << newline out << "private" out << newline out << newline analyzer.instance_methods.sort.each do |instance_method| out << "def " out << instance_method out << "(*args, **kwargs)" out << newline out << "# TODO: Implement me" out << newline out << "end" out << newline out << newline end out << newline end out << newline out << "end" out << newline Formatter.call(out.string.strip) rescue StandardError out.string.strip end |