rblade 0.6.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/README.md +94 -62
- data/REFERENCE.md +138 -0
- data/examples/README.md +3 -0
- data/examples/application/home.rblade +23 -0
- data/examples/components/content/alert.rblade +6 -0
- data/examples/components/content/hero.rblade +14 -0
- data/examples/components/h1.rblade +6 -0
- data/examples/components/p.rblade +14 -0
- data/examples/layouts/app.rblade +16 -0
- data/lib/rblade/compiler/compiles_components.rb +2 -2
- data/lib/rblade/compiler/{compiles_echos.rb → compiles_prints.rb} +11 -10
- data/lib/rblade/compiler/compiles_statements.rb +3 -4
- data/lib/rblade/compiler/statements/{compiles_props.rb → compiles_component_helpers.rb} +29 -10
- data/lib/rblade/compiler/statements/compiles_conditionals.rb +5 -13
- data/lib/rblade/compiler/statements/compiles_form.rb +13 -13
- data/lib/rblade/compiler/statements/compiles_loops.rb +8 -4
- data/lib/rblade/compiler/statements/compiles_once.rb +6 -6
- data/lib/rblade/compiler/statements/compiles_stacks.rb +10 -10
- data/lib/rblade/compiler/tokenizes_statements.rb +1 -1
- data/lib/rblade/compiler.rb +3 -3
- data/lib/rblade/helpers/attributes_manager.rb +7 -11
- data/lib/rblade/helpers/slot_manager.rb +5 -2
- data/rblade.gemspec +1 -1
- metadata +12 -4
| @@ -7,7 +7,7 @@ module RBlade | |
| 7 7 |  | 
| 8 8 | 
             
                  def compileStack args
         | 
| 9 9 | 
             
                    if args&.count != 1
         | 
| 10 | 
            -
                      raise StandardError.new "Stack statement: wrong number of arguments (given #{args&.count}, expecting 1)"
         | 
| 10 | 
            +
                      raise StandardError.new "Stack statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
         | 
| 11 11 | 
             
                    end
         | 
| 12 12 |  | 
| 13 13 | 
             
                    "RBlade::StackManager.initialize(#{args[0]}, _out);_stacks.push(#{args[0]});_out = '';"
         | 
| @@ -15,7 +15,7 @@ module RBlade | |
| 15 15 |  | 
| 16 16 | 
             
                  def compilePrepend args
         | 
| 17 17 | 
             
                    if args&.count != 1
         | 
| 18 | 
            -
                      raise StandardError.new "Prepend statement: wrong number of arguments (given #{args&.count}, expecting 1)"
         | 
| 18 | 
            +
                      raise StandardError.new "Prepend statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
         | 
| 19 19 | 
             
                    end
         | 
| 20 20 |  | 
| 21 21 | 
             
                    @push_counter += 1
         | 
| @@ -24,7 +24,7 @@ module RBlade | |
| 24 24 | 
             
                  end
         | 
| 25 25 |  | 
| 26 26 | 
             
                  def compileEndPrepend args
         | 
| 27 | 
            -
                     | 
| 27 | 
            +
                    unless args.nil?
         | 
| 28 28 | 
             
                      raise StandardError.new "End prepend statement: wrong number of arguments (given #{args&.count}, expecting 0)"
         | 
| 29 29 | 
             
                    end
         | 
| 30 30 |  | 
| @@ -42,8 +42,8 @@ module RBlade | |
| 42 42 | 
             
                  end
         | 
| 43 43 |  | 
| 44 44 | 
             
                  def compileEndPrependIf args
         | 
| 45 | 
            -
                     | 
| 46 | 
            -
                      raise StandardError.new "End  | 
| 45 | 
            +
                    unless args.nil?
         | 
| 46 | 
            +
                      raise StandardError.new "End prepend if statement: wrong number of arguments (given #{args.count}, expecting 0)"
         | 
| 47 47 | 
             
                    end
         | 
| 48 48 |  | 
| 49 49 | 
             
                    "end;" + compileEndPush(nil)
         | 
| @@ -61,15 +61,15 @@ module RBlade | |
| 61 61 |  | 
| 62 62 | 
             
                  def compilePushIf args
         | 
| 63 63 | 
             
                    if args&.count != 2
         | 
| 64 | 
            -
                      raise StandardError.new "Push if statement: wrong number of arguments (given #{args&.count}, expecting 2)"
         | 
| 64 | 
            +
                      raise StandardError.new "Push if statement: wrong number of arguments (given #{args&.count || 0}, expecting 2)"
         | 
| 65 65 | 
             
                    end
         | 
| 66 66 |  | 
| 67 67 | 
             
                    "if #{args[0]};" + compilePush([args[1]])
         | 
| 68 68 | 
             
                  end
         | 
| 69 69 |  | 
| 70 70 | 
             
                  def compileEndPush args
         | 
| 71 | 
            -
                     | 
| 72 | 
            -
                      raise StandardError.new "End push statement: wrong number of arguments (given #{args | 
| 71 | 
            +
                    unless args.nil?
         | 
| 72 | 
            +
                      raise StandardError.new "End push statement: wrong number of arguments (given #{args.count}, expecting 0)"
         | 
| 73 73 | 
             
                    end
         | 
| 74 74 |  | 
| 75 75 | 
             
                    @push_counter -= 1
         | 
| @@ -78,8 +78,8 @@ module RBlade | |
| 78 78 | 
             
                  end
         | 
| 79 79 |  | 
| 80 80 | 
             
                  def compileEndPushIf args
         | 
| 81 | 
            -
                     | 
| 82 | 
            -
                      raise StandardError.new "End push if statement: wrong number of arguments (given #{args | 
| 81 | 
            +
                    unless args.nil?
         | 
| 82 | 
            +
                      raise StandardError.new "End push if statement: wrong number of arguments (given #{args.count}, expecting 0)"
         | 
| 83 83 | 
             
                    end
         | 
| 84 84 |  | 
| 85 85 | 
             
                    "end;" + compileEndPush(nil)
         | 
| @@ -79,7 +79,7 @@ module RBlade | |
| 79 79 | 
             
                  case segments[i][:value][:name]
         | 
| 80 80 | 
             
                  when "case"
         | 
| 81 81 | 
             
                    # Remove any whitespace before a when statement
         | 
| 82 | 
            -
                    until segments[i + 1].nil? || segments[i + 1] ==  | 
| 82 | 
            +
                    until segments[i + 1].nil? || segments[i + 1] == "@"
         | 
| 83 83 | 
             
                      segments.delete_at i + 1
         | 
| 84 84 | 
             
                    end
         | 
| 85 85 | 
             
                  end
         | 
    
        data/lib/rblade/compiler.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            require "rblade/compiler/compiles_comments"
         | 
| 2 2 | 
             
            require "rblade/compiler/compiles_components"
         | 
| 3 | 
            -
            require "rblade/compiler/ | 
| 3 | 
            +
            require "rblade/compiler/compiles_prints"
         | 
| 4 4 | 
             
            require "rblade/compiler/compiles_ruby"
         | 
| 5 5 | 
             
            require "rblade/compiler/compiles_verbatim"
         | 
| 6 6 | 
             
            require "rblade/compiler/compiles_statements"
         | 
| @@ -37,7 +37,7 @@ module RBlade | |
| 37 37 | 
             
                  CompilesRuby.new.compile! tokens
         | 
| 38 38 | 
             
                  TokenizesComponents.new.tokenize! tokens
         | 
| 39 39 | 
             
                  TokenizesStatements.new.tokenize! tokens
         | 
| 40 | 
            -
                   | 
| 40 | 
            +
                  CompilesPrints.new.compile! tokens
         | 
| 41 41 | 
             
                  CompilesStatements.new.compile! tokens
         | 
| 42 42 | 
             
                  CompilesComponents.new.compile! tokens
         | 
| 43 43 |  | 
| @@ -49,7 +49,7 @@ module RBlade | |
| 49 49 |  | 
| 50 50 | 
             
                  CompilesComments.compile!(tokens)
         | 
| 51 51 | 
             
                  CompilesRuby.compile! tokens
         | 
| 52 | 
            -
                   | 
| 52 | 
            +
                  CompilesPrints.compile!(tokens)
         | 
| 53 53 |  | 
| 54 54 | 
             
                  compileTokens tokens
         | 
| 55 55 | 
             
                end
         | 
| @@ -15,15 +15,17 @@ module RBlade | |
| 15 15 | 
             
                  @attributes[key]
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 | 
            -
                def has?( | 
| 19 | 
            -
                   | 
| 18 | 
            +
                def has?(*keys)
         | 
| 19 | 
            +
                  keys.map!(&:to_sym)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  keys.all? { |key| @attributes.has_key? key }
         | 
| 20 22 | 
             
                end
         | 
| 21 23 |  | 
| 22 | 
            -
                def method_missing(method, *, & | 
| 24 | 
            +
                def method_missing(method, *, &)
         | 
| 23 25 | 
             
                  if [:select, :filter, :slice].include? method
         | 
| 24 | 
            -
                    AttributesManager.new @attributes.send(method, *, & | 
| 26 | 
            +
                    AttributesManager.new @attributes.send(method, *, &)
         | 
| 25 27 | 
             
                  else
         | 
| 26 | 
            -
                    @attributes.send(method, *, & | 
| 28 | 
            +
                    @attributes.send(method, *, &)
         | 
| 27 29 | 
             
                  end
         | 
| 28 30 | 
             
                end
         | 
| 29 31 |  | 
| @@ -91,12 +93,6 @@ module RBlade | |
| 91 93 | 
             
                  AttributesManager.new new_attributes
         | 
| 92 94 | 
             
                end
         | 
| 93 95 |  | 
| 94 | 
            -
                def has?(*keys)
         | 
| 95 | 
            -
                  keys.map!(&:to_sym)
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                  keys.all? { |key| @attributes.has_key? key }
         | 
| 98 | 
            -
                end
         | 
| 99 | 
            -
             | 
| 100 96 | 
             
                def has_any?(*keys)
         | 
| 101 97 | 
             
                  keys.map!(&:to_sym)
         | 
| 102 98 |  | 
| @@ -24,8 +24,11 @@ module RBlade | |
| 24 24 | 
             
                  @content.respond_to?(method_name)
         | 
| 25 25 | 
             
                end
         | 
| 26 26 |  | 
| 27 | 
            -
                 | 
| 28 | 
            -
             | 
| 27 | 
            +
                # Wraps var in a slot manager, if it isn't already
         | 
| 28 | 
            +
                def self.wrap var
         | 
| 29 | 
            +
                  var.is_a?(self) ? var : new(var)
         | 
| 29 30 | 
             
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                attr_reader :attributes
         | 
| 30 33 | 
             
              end
         | 
| 31 34 | 
             
            end
         | 
    
        data/rblade.gemspec
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |s|
         | 
| 2 2 | 
             
              s.name = "rblade"
         | 
| 3 | 
            -
              s.version = "0. | 
| 3 | 
            +
              s.version = "1.0.1"
         | 
| 4 4 | 
             
              s.summary = "A component-first templating engine for Rails"
         | 
| 5 5 | 
             
              s.description = "RBlade is a simple, yet powerful templating engine for Ruby on Rails, inspired by Laravel Blade."
         | 
| 6 6 | 
             
              s.authors = ["Simon J"]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rblade
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 1.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Simon J
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-08- | 
| 11 | 
            +
            date: 2024-08-09 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: minitest
         | 
| @@ -79,24 +79,32 @@ files: | |
| 79 79 | 
             
            - Gemfile
         | 
| 80 80 | 
             
            - LICENSE.md
         | 
| 81 81 | 
             
            - README.md
         | 
| 82 | 
            +
            - REFERENCE.md
         | 
| 82 83 | 
             
            - Rakefile
         | 
| 83 84 | 
             
            - do
         | 
| 84 85 | 
             
            - docker-compose.yml
         | 
| 86 | 
            +
            - examples/README.md
         | 
| 87 | 
            +
            - examples/application/home.rblade
         | 
| 88 | 
            +
            - examples/components/content/alert.rblade
         | 
| 89 | 
            +
            - examples/components/content/hero.rblade
         | 
| 90 | 
            +
            - examples/components/h1.rblade
         | 
| 91 | 
            +
            - examples/components/p.rblade
         | 
| 92 | 
            +
            - examples/layouts/app.rblade
         | 
| 85 93 | 
             
            - lib/rblade.rb
         | 
| 86 94 | 
             
            - lib/rblade/compiler.rb
         | 
| 87 95 | 
             
            - lib/rblade/compiler/compiles_comments.rb
         | 
| 88 96 | 
             
            - lib/rblade/compiler/compiles_components.rb
         | 
| 89 | 
            -
            - lib/rblade/compiler/ | 
| 97 | 
            +
            - lib/rblade/compiler/compiles_prints.rb
         | 
| 90 98 | 
             
            - lib/rblade/compiler/compiles_ruby.rb
         | 
| 91 99 | 
             
            - lib/rblade/compiler/compiles_statements.rb
         | 
| 92 100 | 
             
            - lib/rblade/compiler/compiles_verbatim.rb
         | 
| 101 | 
            +
            - lib/rblade/compiler/statements/compiles_component_helpers.rb
         | 
| 93 102 | 
             
            - lib/rblade/compiler/statements/compiles_conditionals.rb
         | 
| 94 103 | 
             
            - lib/rblade/compiler/statements/compiles_form.rb
         | 
| 95 104 | 
             
            - lib/rblade/compiler/statements/compiles_html_attributes.rb
         | 
| 96 105 | 
             
            - lib/rblade/compiler/statements/compiles_inline_ruby.rb
         | 
| 97 106 | 
             
            - lib/rblade/compiler/statements/compiles_loops.rb
         | 
| 98 107 | 
             
            - lib/rblade/compiler/statements/compiles_once.rb
         | 
| 99 | 
            -
            - lib/rblade/compiler/statements/compiles_props.rb
         | 
| 100 108 | 
             
            - lib/rblade/compiler/statements/compiles_stacks.rb
         | 
| 101 109 | 
             
            - lib/rblade/compiler/tokenizes_components.rb
         | 
| 102 110 | 
             
            - lib/rblade/compiler/tokenizes_statements.rb
         |