opulent 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 400a61b79e430257b8e78d35a00168abf0b25b2a
4
- data.tar.gz: f50f10dfe3f7673cf35eeb197bb06a62dfcaedb5
3
+ metadata.gz: e9300eb265cbd78d37b3320fa250ef12c91a2d54
4
+ data.tar.gz: 924c5d00c448dcf16a099273cac90dac1bfbdfdb
5
5
  SHA512:
6
- metadata.gz: 14774d95d2d98deab955e1c62131e6ff6cee05c82aa79d4362aea9c2738f4e244628d05f886e08207e396d2875d43571db33ab030f68a9e6833f6d86857a6d12
7
- data.tar.gz: 89f0081dd1d91648e877a6aa77efab4e3b70002f581ff739e83bc1bd5d8f51991346b5467d09affa0b2fa1fd83dbc8d7217b3d5204f4dd28cdb126c2d08323f9
6
+ metadata.gz: 6d94c1b6835f811ad431a1eba7c3b2c5913d2c68ed900915343c1608227386f70d90fc92dbca90e2a72ca98bdf5da4057780a08342f82f0ec116a3f41ff03f26
7
+ data.tar.gz: efa2e8bfc1e6a552b54cf34ba0e67af139cca11751e505d22706631a38da93810ee4e9503d831453da68730564497813844a6275f18b6d4b6ba24224df4eeb21
@@ -6,30 +6,34 @@ require 'opulent/version'
6
6
  module Opulent
7
7
  # @CLI
8
8
  class CLI
9
- Extension = /\.(op|opl|opulent)\Z/
9
+ EXTENSION = /\.(op|opl|opulent)\Z/
10
10
 
11
- Keywords = %w(context layout locals version help)
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 Extension
24
+ when EXTENSION
21
25
  @input = arguments[i]
22
- unless arguments[i + 1] =~ /\A\-/ || Keywords.include?(arguments[i+1])
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] =~ Extension
33
+ if arguments[i + 1] =~ EXTENSION
29
34
  @layout = arguments[(i += 1)]
30
35
  else
31
- error "Missing input or incorrect file extension for layout [-l] argument. " +
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
- error "Given context file #{@locals_file.inspect} does not exist or an incorrect path has been specified." unless File.file? @locals_file
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 locals file. Please use JSON or YAML as input."
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
- message = ""
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 = Proc.new do
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 = Proc.new do
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 @output, 'w' do |file| file.write output end
84
- message += "Successfully rendered #{@input.inspect} to #{@output.inspect}."
85
- #message += "Used #{@locals_file.inspect} as local context file." if @locals_file
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
- #message += "Used #{@locals_file.inspect} as local context file.\n\n" if @locals_file
89
- message += "No output file specified. Writing result to terminal.\n\n#{output}"
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(extra = "")
99
- "#{extra}You can use the following commands with the Opulent Command Line Interface: \n\n
100
- opulent input.op output.op Render an input file and write the result to the output file.\n
101
- opulent layout [-l] layout.op Render an input file using given input layout file.\n
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
- "\n---\n" +
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
- "\n---\n" +
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
@@ -39,7 +39,7 @@ module Opulent
39
39
  # Error output in case the filter does not exist
40
40
  #
41
41
  def load_filter
42
- return unless gem_name.nil? || @loaded
42
+ return if gem_name.nil? || @loaded
43
43
 
44
44
  # Try to load the library associated to the chosen filter
45
45
  begin
@@ -1,4 +1,4 @@
1
1
  # @Opulent
2
2
  module Opulent
3
- VERSION = '1.5.0'
3
+ VERSION = '1.5.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opulent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Grozav