Class: TailwindUi::JsxToErb
- Inherits:
-
Object
- Object
- TailwindUi::JsxToErb
- Defined in:
- lib/tailwind_ui/jsx_to_erb.rb
Class Method Summary collapse
Instance Method Summary collapse
- #full ⇒ Object
-
#initialize(file_contents) ⇒ JsxToErb
constructor
A new instance of JsxToErb.
Constructor Details
#initialize(file_contents) ⇒ JsxToErb
Returns a new instance of JsxToErb.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tailwind_ui/jsx_to_erb.rb', line 26 def initialize(file_contents) if file_contents.include?("This example requires updating your template") raise Special end unless file_contents.lines.first.start_with?("export default function") raise NotYetSupported end if file_contents.include?("clipPath") raise ClipPathNotYetSupported end @file_contents = file_contents end |
Class Method Details
.from_path(path) ⇒ Object
21 22 23 24 |
# File 'lib/tailwind_ui/jsx_to_erb.rb', line 21 def self.from_path(path) file_contents = File.read(path) new(file_contents) end |
Instance Method Details
#full ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tailwind_ui/jsx_to_erb.rb', line 42 def full = @file_contents.match(/(?<tags> *<.*>)/m)[:tags] result = without_indentation() result = handle_style_attributes(result) result = with_jsx_keywords_updated(result) result = convert_camelcase_attributes(result) (result) result = handle_jsx_comments(result) result = handle_brace_attributes(result) result = handle_inner_braces(result) raise UnconvertedBraces if result.include?("{") || result.include?("}") # Parse the ERB to ensure it's valid ERB.new(result).result result end |