opulent 1.5.0 → 1.5.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/lib/opulent/exec.rb +43 -29
 - data/lib/opulent/filters.rb +1 -1
 - data/lib/opulent/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e9300eb265cbd78d37b3320fa250ef12c91a2d54
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 924c5d00c448dcf16a099273cac90dac1bfbdfdb
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6d94c1b6835f811ad431a1eba7c3b2c5913d2c68ed900915343c1608227386f70d90fc92dbca90e2a72ca98bdf5da4057780a08342f82f0ec116a3f41ff03f26
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: efa2e8bfc1e6a552b54cf34ba0e67af139cca11751e505d22706631a38da93810ee4e9503d831453da68730564497813844a6275f18b6d4b6ba24224df4eeb21
         
     | 
    
        data/lib/opulent/exec.rb
    CHANGED
    
    | 
         @@ -6,30 +6,34 @@ require 'opulent/version' 
     | 
|
| 
       6 
6 
     | 
    
         
             
            module Opulent
         
     | 
| 
       7 
7 
     | 
    
         
             
              # @CLI
         
     | 
| 
       8 
8 
     | 
    
         
             
              class CLI
         
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
      
 9 
     | 
    
         
            +
                EXTENSION = /\.(op|opl|opulent)\Z/
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 11 
     | 
    
         
            +
                KEYWORDS = %w(context layout locals version help)
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                def initialize(arguments)
         
     | 
| 
       14 
14 
     | 
    
         
             
                  i = 0
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
      
 16 
     | 
    
         
            +
                  layout_error = 'Missing input or incorrect file extension for ' \
         
     | 
| 
      
 17 
     | 
    
         
            +
                    'layout [-l] argument. '
         
     | 
| 
      
 18 
     | 
    
         
            +
                  layout_error += "Found #{arguments[i + 1]} instead." if arguments[i + 1]
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       16 
20 
     | 
    
         
             
                  while arguments[i]
         
     | 
| 
       17 
21 
     | 
    
         
             
                    case arguments[i]
         
     | 
| 
       18 
22 
     | 
    
         | 
| 
       19 
23 
     | 
    
         
             
                    # opulent input.op output.op
         
     | 
| 
       20 
     | 
    
         
            -
                    when  
     | 
| 
      
 24 
     | 
    
         
            +
                    when EXTENSION
         
     | 
| 
       21 
25 
     | 
    
         
             
                      @input = arguments[i]
         
     | 
| 
       22 
     | 
    
         
            -
                       
     | 
| 
      
 26 
     | 
    
         
            +
                      is_keyword = KEYWORDS.include? arguments[i + 1]
         
     | 
| 
      
 27 
     | 
    
         
            +
                      unless arguments[i + 1] =~ /\A\-/ || is_keyword
         
     | 
| 
       23 
28 
     | 
    
         
             
                        @output = arguments[(i += 1)]
         
     | 
| 
       24 
29 
     | 
    
         
             
                      end
         
     | 
| 
       25 
30 
     | 
    
         | 
| 
       26 
31 
     | 
    
         
             
                    # opulent -v
         
     | 
| 
       27 
32 
     | 
    
         
             
                    when '-l', 'layout'
         
     | 
| 
       28 
     | 
    
         
            -
                      if arguments[i + 1] =~  
     | 
| 
      
 33 
     | 
    
         
            +
                      if arguments[i + 1] =~ EXTENSION
         
     | 
| 
       29 
34 
     | 
    
         
             
                        @layout = arguments[(i += 1)]
         
     | 
| 
       30 
35 
     | 
    
         
             
                      else
         
     | 
| 
       31 
     | 
    
         
            -
                        error  
     | 
| 
       32 
     | 
    
         
            -
                        "#{"Found #{arguments[i+1]} instead." if arguments[i+1] }"
         
     | 
| 
      
 36 
     | 
    
         
            +
                        error layout_error
         
     | 
| 
       33 
37 
     | 
    
         
             
                      end
         
     | 
| 
       34 
38 
     | 
    
         | 
| 
       35 
39 
     | 
    
         
             
                    # opulent -v
         
     | 
| 
         @@ -40,14 +44,18 @@ module Opulent 
     | 
|
| 
       40 
44 
     | 
    
         
             
                    # opulent -c
         
     | 
| 
       41 
45 
     | 
    
         
             
                    when '-c', 'context', '-lc', 'locals'
         
     | 
| 
       42 
46 
     | 
    
         
             
                      @locals_file = arguments[(i += 1)]
         
     | 
| 
       43 
     | 
    
         
            -
                       
     | 
| 
      
 47 
     | 
    
         
            +
                      unless File.file? @locals_file
         
     | 
| 
      
 48 
     | 
    
         
            +
                        error "Given context file #{@locals_file.inspect} does not exist" \
         
     | 
| 
      
 49 
     | 
    
         
            +
                        ' or an incorrect path has been specified.'
         
     | 
| 
      
 50 
     | 
    
         
            +
                      end
         
     | 
| 
       44 
51 
     | 
    
         | 
| 
       45 
52 
     | 
    
         
             
                      if File.extname(@locals_file) == '.json'
         
     | 
| 
       46 
53 
     | 
    
         
             
                        @locals = JSON.parse File.read(@locals_file), symbolize_keys: true
         
     | 
| 
       47 
54 
     | 
    
         
             
                      elsif File.extname(@locals_file) == '.yml'
         
     | 
| 
       48 
55 
     | 
    
         
             
                        @locals = YAML.load_file @locals_file
         
     | 
| 
       49 
56 
     | 
    
         
             
                      else
         
     | 
| 
       50 
     | 
    
         
            -
                        error "Unknown file extension #{@locals_file.inspect} given as  
     | 
| 
      
 57 
     | 
    
         
            +
                        error "Unknown file extension #{@locals_file.inspect} given as" \
         
     | 
| 
      
 58 
     | 
    
         
            +
                        ' locals file. Please use JSON or YAML as input.'
         
     | 
| 
       51 
59 
     | 
    
         
             
                      end
         
     | 
| 
       52 
60 
     | 
    
         | 
| 
       53 
61 
     | 
    
         
             
                    # opulent -h
         
     | 
| 
         @@ -63,30 +71,34 @@ module Opulent 
     | 
|
| 
       63 
71 
     | 
    
         | 
| 
       64 
72 
     | 
    
         
             
                  if @input
         
     | 
| 
       65 
73 
     | 
    
         
             
                    @locals ||= {}
         
     | 
| 
       66 
     | 
    
         
            -
                    error "Given input file #{@input.inspect} does not exist or an incorrect path has been specified." unless File.file? @input
         
     | 
| 
       67 
74 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                     
     | 
| 
      
 75 
     | 
    
         
            +
                    unless File.file? @input
         
     | 
| 
      
 76 
     | 
    
         
            +
                      error "Given input file #{@input.inspect} does not exist or " \
         
     | 
| 
      
 77 
     | 
    
         
            +
                      'an incorrect path has been specified.'
         
     | 
| 
      
 78 
     | 
    
         
            +
                    end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                    message = ''
         
     | 
| 
       69 
81 
     | 
    
         
             
                    opulent = Opulent.new
         
     | 
| 
       70 
82 
     | 
    
         
             
                    if @layout
         
     | 
| 
       71 
     | 
    
         
            -
                      output =  
     | 
| 
       72 
     | 
    
         
            -
                        opulent.render_file(@layout, @locals)  
     | 
| 
       73 
     | 
    
         
            -
                          opulent.render_file(@input, @locals){}
         
     | 
| 
       74 
     | 
    
         
            -
                         
     | 
| 
      
 83 
     | 
    
         
            +
                      output = proc do
         
     | 
| 
      
 84 
     | 
    
         
            +
                        opulent.render_file(@layout, @locals) do
         
     | 
| 
      
 85 
     | 
    
         
            +
                          opulent.render_file(@input, @locals) {}
         
     | 
| 
      
 86 
     | 
    
         
            +
                        end
         
     | 
| 
       75 
87 
     | 
    
         
             
                      end[]
         
     | 
| 
       76 
88 
     | 
    
         
             
                    else
         
     | 
| 
       77 
     | 
    
         
            -
                      output =  
     | 
| 
      
 89 
     | 
    
         
            +
                      output = proc do
         
     | 
| 
       78 
90 
     | 
    
         
             
                        opulent.render_file(@input, @locals)
         
     | 
| 
       79 
91 
     | 
    
         
             
                      end[]
         
     | 
| 
       80 
92 
     | 
    
         
             
                    end
         
     | 
| 
       81 
93 
     | 
    
         | 
| 
       82 
94 
     | 
    
         
             
                    if @output
         
     | 
| 
       83 
     | 
    
         
            -
                      File.open 
     | 
| 
       84 
     | 
    
         
            -
                      message += "Successfully rendered #{@input.inspect}  
     | 
| 
       85 
     | 
    
         
            -
                       
     | 
| 
      
 95 
     | 
    
         
            +
                      File.open(@output, 'w') { |file| file.write output }
         
     | 
| 
      
 96 
     | 
    
         
            +
                      message += "Successfully rendered #{@input.inspect} " \
         
     | 
| 
      
 97 
     | 
    
         
            +
                      "to #{@output.inspect}."
         
     | 
| 
       86 
98 
     | 
    
         
             
                    else
         
     | 
| 
       87 
99 
     | 
    
         
             
                      message += "Successfully rendered #{@input.inspect}.\n\n"
         
     | 
| 
       88 
     | 
    
         
            -
                       
     | 
| 
       89 
     | 
    
         
            -
                       
     | 
| 
      
 100 
     | 
    
         
            +
                      message += 'No output file specified. Writing result to ' \
         
     | 
| 
      
 101 
     | 
    
         
            +
                      "terminal.\n\n#{output}"
         
     | 
| 
       90 
102 
     | 
    
         
             
                    end
         
     | 
| 
       91 
103 
     | 
    
         | 
| 
       92 
104 
     | 
    
         
             
                    write message
         
     | 
| 
         @@ -95,12 +107,16 @@ module Opulent 
     | 
|
| 
       95 
107 
     | 
    
         
             
                  end
         
     | 
| 
       96 
108 
     | 
    
         
             
                end
         
     | 
| 
       97 
109 
     | 
    
         | 
| 
       98 
     | 
    
         
            -
                def help( 
     | 
| 
       99 
     | 
    
         
            -
                   
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
            opulent  
     | 
| 
      
 110 
     | 
    
         
            +
                def help(_extra = '')
         
     | 
| 
      
 111 
     | 
    
         
            +
                  <<-HELP #{_extra} You can use the following commands with the Opulent
         
     | 
| 
      
 112 
     | 
    
         
            +
                   Command  Line Interface: \n\n
         
     | 
| 
      
 113 
     | 
    
         
            +
            opulent input.op output.op      Render an input file and write the result to
         
     | 
| 
      
 114 
     | 
    
         
            +
            the output file.\n
         
     | 
| 
      
 115 
     | 
    
         
            +
            opulent layout [-l] layout.op   Render an input file using given input
         
     | 
| 
      
 116 
     | 
    
         
            +
            layout file.\n
         
     | 
| 
       102 
117 
     | 
    
         
             
            opulent help [-h]               Show available command line options.\n
         
     | 
| 
       103 
118 
     | 
    
         
             
            opulent version [-v]            Show installed version.\n"
         
     | 
| 
      
 119 
     | 
    
         
            +
                  HELP
         
     | 
| 
       104 
120 
     | 
    
         
             
                end
         
     | 
| 
       105 
121 
     | 
    
         | 
| 
       106 
122 
     | 
    
         
             
                # Give an explicit response for the given input arguments
         
     | 
| 
         @@ -110,8 +126,7 @@ opulent version [-v]            Show installed version.\n" 
     | 
|
| 
       110 
126 
     | 
    
         
             
                def write(message)
         
     | 
| 
       111 
127 
     | 
    
         
             
                  # Reconstruct lines to display where errors occur
         
     | 
| 
       112 
128 
     | 
    
         
             
                  puts "\nOpulent " + Logger.green('[Engine]') +
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                  "#{message}\n\n\n"
         
     | 
| 
      
 129 
     | 
    
         
            +
                    "\n---\n#{message}\n\n\n"
         
     | 
| 
       115 
130 
     | 
    
         
             
                end
         
     | 
| 
       116 
131 
     | 
    
         | 
| 
       117 
132 
     | 
    
         
             
                # Give an explicit error report where an unexpected sequence of tokens
         
     | 
| 
         @@ -122,8 +137,7 @@ opulent version [-v]            Show installed version.\n" 
     | 
|
| 
       122 
137 
     | 
    
         
             
                def error(message)
         
     | 
| 
       123 
138 
     | 
    
         
             
                  # Reconstruct lines to display where errors occur
         
     | 
| 
       124 
139 
     | 
    
         
             
                  fail "\nOpulent " + Logger.red('[Engine]') +
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                  "#{message}\n\n#{help}\n\n\n"
         
     | 
| 
      
 140 
     | 
    
         
            +
                    "\n---\n#{message}\n\n#{help}\n\n\n"
         
     | 
| 
       127 
141 
     | 
    
         
             
                end
         
     | 
| 
       128 
142 
     | 
    
         
             
              end
         
     | 
| 
       129 
143 
     | 
    
         
             
            end
         
     | 
    
        data/lib/opulent/filters.rb
    CHANGED
    
    
    
        data/lib/opulent/version.rb
    CHANGED