sktl_to_liquid 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6bdb2e3ac1be7e74634d32d956822123e33bd4e440ed90b0d147578eece00bbf
4
+ data.tar.gz: f5ba146f988830f1a49e8dde61cdd456f9834840a56728036321633cb2dd8851
5
+ SHA512:
6
+ metadata.gz: a0e35fe932f90988b8cab30927e4b7fa7e561f2972a9d0c6b37f892a12cfd3ee5b23516003e102dd8981e9517ac95bc91ba50e0bd7c0e774cef9b80d575021d4
7
+ data.tar.gz: 66fb0a812c37c566e3d5149d6748adff98dbfee4f7221cde0b842d75386815370323ef655f4368132ad2515382953f1a9338d25c635e72464223908a92a7b16c
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sktl_to_liquid.gemspec
4
+ gemspec
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sktl_to_liquid (0.1.0)
5
+ activesupport
6
+ pastel
7
+ scribble
8
+ tty-spinner
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (6.0.0)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 0.7, < 2)
16
+ minitest (~> 5.1)
17
+ tzinfo (~> 1.1)
18
+ zeitwerk (~> 2.1, >= 2.1.8)
19
+ concurrent-ruby (1.1.5)
20
+ diff-lcs (1.3)
21
+ equatable (0.6.1)
22
+ i18n (1.7.0)
23
+ concurrent-ruby (~> 1.0)
24
+ minitest (5.12.2)
25
+ parslet (1.8.2)
26
+ pastel (0.7.3)
27
+ equatable (~> 0.6)
28
+ tty-color (~> 0.5)
29
+ rake (10.5.0)
30
+ rspec (3.9.0)
31
+ rspec-core (~> 3.9.0)
32
+ rspec-expectations (~> 3.9.0)
33
+ rspec-mocks (~> 3.9.0)
34
+ rspec-core (3.9.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-expectations (3.9.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-mocks (3.9.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-support (3.9.0)
43
+ scribble (1.0.1)
44
+ parslet (~> 1.6)
45
+ thread_safe (0.3.6)
46
+ tty-color (0.5.0)
47
+ tty-cursor (0.7.0)
48
+ tty-spinner (0.9.1)
49
+ tty-cursor (~> 0.7)
50
+ tzinfo (1.2.5)
51
+ thread_safe (~> 0.1)
52
+ zeitwerk (2.2.0)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ bundler (~> 2.0)
59
+ rake (~> 10.0)
60
+ rspec (~> 3.0)
61
+ sktl_to_liquid!
62
+
63
+ BUNDLED WITH
64
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Adam Stomski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # SktlToLiquid
2
+
3
+ Converter for [Northpass](https://www.northpass.com/) custom templates. Converts **.sktl** files to **.liquid** files.
4
+
5
+ ## Before you start
6
+
7
+ This is **not** a fully featured .sktl -> .liquid converter. It was written to smoothly transfer our clients to **liquid** templates and covers only needed part for that. Successfully converted 99.6 % of our clients templates.
8
+
9
+ ## Installation
10
+
11
+ Run in terminal
12
+
13
+ ```bash
14
+ gem install sktl_to_liquid
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ Usage: sktl_to_liquid --sktl directory/with/.sktl --liquid directory/to/output/.liquid
21
+ -s, --sktl SKTL Location of directory with SKTL files
22
+ -l, --liquid LIQUID Location of directory to output Liquid files
23
+ ```
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SchoolKeep/sktl_to_liquid.
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sktl_to_liquid"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'pastel'
5
+ require 'tty-spinner'
6
+ require 'sktl_to_liquid'
7
+
8
+ options = {}
9
+ optparse = OptionParser.new do |opts|
10
+ opts.banner = "Usage: sktl_to_liquid --sktl directory/with/.sktl --liquid directory/to/output/.liquid"
11
+
12
+ opts.on("-s", "--sktl SKTL", "Location of directory with SKTL files") do |v|
13
+ options[:sktl] = v
14
+ end
15
+
16
+ opts.on("-l", "--liquid LIQUID", "Location of directory to output Liquid files") do |v|
17
+ options[:liquid] = v
18
+ end
19
+ end
20
+
21
+ begin
22
+ optparse.parse!
23
+ missing = [:sktl, :liquid].select{ |param| options[param].nil? }
24
+
25
+ unless missing.empty?
26
+ raise OptionParser::MissingArgument.new(missing.join(', '))
27
+ end
28
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
29
+ puts $!.to_s
30
+ puts optparse
31
+ exit
32
+ end
33
+
34
+ pastel = Pastel.new
35
+
36
+ puts <<~TEXT
37
+ @&
38
+ && &&&
39
+ && &&&
40
+ &&&&&&&& #{pastel.green("%######%")} &&&&&& &&&&&& &&&&&&&& &&&&&&&@ &&&&&&& @&&&&&& @&&&&&&&
41
+ &&& &&& #{pastel.green("##########")} &&& && &&& && && &&& &&& &&& &&&
42
+ &&& &&& #{pastel.green("### ###")} &&& && &&& &&& && &&& &&&&&&&& &&&&&@ &&&&&@
43
+ &&& &&& #{pastel.green("# %##% #")} &&& && &&& &&& && &&& && &&& && &&
44
+ &&& &&& #{pastel.green("######")} &&& &&&&&& &&& &&& &&&&&&& &&&&&&&& &&&&&&& &&&&&&&&
45
+ &&
46
+ &&
47
+ TEXT
48
+
49
+ sktl_files = Dir.entries(options[:sktl]).select do |file_name|
50
+ File.extname(file_name) == '.sktl'
51
+ end
52
+
53
+ sktl_files.each do |file_name|
54
+ new_name = file_name.gsub('sktl', 'liquid')
55
+
56
+ spinner = TTY::Spinner.new(
57
+ "[:spinner] #{file_name} ---> #{new_name}",
58
+ success_mark: pastel.green('✔'),
59
+ error_mark: pastel.red('x')
60
+ )
61
+ spinner.auto_spin
62
+
63
+ body = File.read("#{options[:sktl]}/#{file_name}")
64
+
65
+ File.open("#{options[:liquid]}/#{new_name}", 'w') do |f|
66
+ begin
67
+ f.write SktlToLiquid::Converter.new(body).convert
68
+ rescue StandardError => e
69
+ spinner.error
70
+ puts "-------------\n #{e} \n-------------"
71
+ next
72
+ end
73
+ end
74
+
75
+ spinner.success
76
+ end
@@ -0,0 +1,9 @@
1
+ require 'scribble'
2
+ require 'active_support/all'
3
+
4
+ require 'sktl_to_liquid/version'
5
+ require 'sktl_to_liquid/type'
6
+ require 'sktl_to_liquid/converter'
7
+
8
+ module SktlToLiquid
9
+ end
@@ -0,0 +1,381 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SktlToLiquid::Converter
4
+ ARRAY_EMPTY_CHECK_EXPRESSIONS = [
5
+ "courses",
6
+ "course.instructors",
7
+ "course.partnerships",
8
+ "learning_path.instructors",
9
+ "homepage.published_featured_courses",
10
+ "learning_path.items",
11
+ "current_person.filterable_catalog_categories",
12
+ "current_person.filterable_learning_path_categories",
13
+ "current_person.filterable_categories"
14
+ ].freeze
15
+
16
+ ConversionError = Class.new(StandardError)
17
+
18
+ def initialize(body)
19
+ @body = body
20
+ @scope_stack = []
21
+ end
22
+
23
+ def convert
24
+ liquid_template = ""
25
+
26
+ template.parse[:template].each do |segment|
27
+ liquid_template += convert_toplevel(segment)
28
+ end
29
+
30
+ post_process(liquid_template)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :body, :scope_stack
36
+
37
+ def template
38
+ @template ||= Scribble::Template.new(body)
39
+ end
40
+
41
+ # very specific use cases, easier to change this way
42
+ def post_process(liquid_template)
43
+ liquid_template = liquid_template.gsub(
44
+ "{{ course.progress_text | minus: ' Complete' }}",
45
+ "{{ course.progress }}%"
46
+ )
47
+ liquid_template = liquid_template.gsub(
48
+ 'class="{{ no_filter_selected_class }}"',
49
+ 'class="uk-text-bold"'
50
+ )
51
+ liquid_template
52
+ end
53
+
54
+ def convert_toplevel(segment)
55
+ result = convert_segment(segment)
56
+
57
+ case SktlToLiquid::Type.new(segment).to_sym
58
+ when :chain, :call_or_variable
59
+ "{{ #{result} }}"
60
+ when :call, :ending, :loop, :else, :partial,
61
+ :pluralize, :learning_path_item, :display_search_form
62
+ "{% #{result} %}"
63
+ else
64
+ result
65
+ end
66
+ end
67
+
68
+ def convert_segment(segment)
69
+ type = SktlToLiquid::Type.new(segment).to_sym
70
+
71
+ case type
72
+ when :text, :string, :number
73
+ convert_text(segment[type])
74
+ when :chain
75
+ convert_chain(segment[:chain])
76
+ when :call_or_variable, :else
77
+ convert_call_or_variable(segment[:call_or_variable])
78
+ when :call
79
+ convert_call(segment[:call])
80
+ when :ending
81
+ add_ending
82
+ when :loop
83
+ convert_loop(segment[:chain])
84
+ when :partial
85
+ convert_partial(segment[:call])
86
+ when :enrolled_in?
87
+ convert_enrolled_in(segment[:call])
88
+ when :access_course?
89
+ convert_access_course(segment[:call])
90
+ when :pluralize
91
+ convert_pluralize(segment[:call])
92
+ when :app
93
+ convert_app(segment[:chain])
94
+ when :learning_path_item
95
+ convert_learning_path_item(segment[:call])
96
+ when :display_search_form
97
+ convert_display_search_form(segment[:call])
98
+ when :filter
99
+ convert_filter(segment)
100
+ when *SktlToLiquid::Type::OPERATORS
101
+ convert_operator(segment)
102
+ else
103
+ raise ConversionError, "uknown segment: #{segment}"
104
+ end
105
+ end
106
+
107
+ #
108
+ # {:text=>" uk-container-center"@1838}
109
+ #
110
+ def convert_text(slice)
111
+ slice.to_s
112
+ end
113
+
114
+ #
115
+ # :chain=>[
116
+ # {:call_or_variable=>{:name=>"routes"@178}},
117
+ # {:call_or_variable=>{:name=>"my_content_path"@185}}]
118
+ #
119
+ def convert_chain(chain_segment)
120
+ chain_body = ""
121
+
122
+ chain_segment.each_with_index do |segment, index|
123
+ is_filter = SktlToLiquid::Type::FILTERS.include?(segment.dig(:call, :name)&.to_sym) ||
124
+ SktlToLiquid::Type::FILTERS.include?(segment.dig(:call_or_variable, :name)&.to_sym)
125
+
126
+ if !index.zero? && !SktlToLiquid::Type::OPERATORS.include?(segment.keys.first) && !is_filter
127
+ chain_body += "."
128
+ end
129
+
130
+ if is_filter
131
+ chain_body += " "
132
+ end
133
+
134
+ chain_body += convert_segment(segment)
135
+ end
136
+
137
+ chain_body
138
+ end
139
+
140
+ #
141
+ # :chain=>[
142
+ # {:call_or_variable=>{:name=>"course"@2197}},
143
+ # {:call_or_variable=>{:name=>"instructors"@2204}},
144
+ # {:call=>{:name=>"each"@2216, :args=>{:string=>"instructor"@2222}}}]
145
+ #
146
+ def convert_loop(segment)
147
+ scope_stack << :for
148
+
149
+ loop_segment = segment.dup
150
+
151
+ single_element_part = loop_segment.pop[:call]
152
+ single_element_part = convert_segment(single_element_part[:args])
153
+
154
+ collection_part = convert_segment(
155
+ chain: loop_segment
156
+ )
157
+
158
+ "for #{single_element_part} in #{collection_part}"
159
+ end
160
+
161
+ #
162
+ # {:call_or_variable=>{:name=>"course"@1291}}
163
+ #
164
+ def convert_call_or_variable(slice)
165
+ slice[:name].to_s
166
+ end
167
+
168
+ #
169
+ # :call=>{
170
+ # :name=>"if"@1001,
171
+ # :args=>{
172
+ # :chain=>[
173
+ # {:call_or_variable=>{:name=>"course"@1004}},
174
+ # {:call_or_variable=>{:name=>"learner_can_retake?"@1011}}]}}}
175
+ #
176
+ def convert_call(call_segment)
177
+ name = call_segment[:name].to_sym
178
+ args = Array.wrap(call_segment[:args])
179
+ call_arg = ""
180
+
181
+ args.each_with_index do |arg, index|
182
+ call_arg += convert_segment(arg)
183
+ call_arg += ", " unless args.size == index + 1
184
+ end
185
+
186
+ if [:if, :unless].include?(name)
187
+ scope_stack << name
188
+
189
+ if ARRAY_EMPTY_CHECK_EXPRESSIONS.include?(call_arg)
190
+ return "#{name} #{call_arg}.any?"
191
+ end
192
+
193
+ if ["current_person", "current_learner"].include?(call_arg)
194
+ return "#{name} #{call_arg}.signed_in?"
195
+ end
196
+ end
197
+
198
+ "#{name} #{call_arg}"
199
+ end
200
+
201
+ #
202
+ # {:ending=>"end"@1861}
203
+ #
204
+ def add_ending
205
+ "end#{scope_stack.pop}"
206
+ end
207
+
208
+ #
209
+ # :call=>{
210
+ # :name=>"partial"@2216,
211
+ # :args=>{:string=>"_learning_path"@2222}}}
212
+ #
213
+ def convert_partial(call_segment)
214
+ partial_name = call_segment.dig(:args, :string).to_sym
215
+
216
+ "include \"#{partial_name}\""
217
+ end
218
+
219
+ #
220
+ # sktl:
221
+ # current_person.enrolled_in_learning_path?(learning_path)
222
+ #
223
+ # liquid:
224
+ # current_person.enrolled_in_learning_path?
225
+ #
226
+ def convert_enrolled_in(segment)
227
+ segment[:name].to_s
228
+ end
229
+
230
+ #
231
+ # [DEPRECATED] SchoolWebsite::PersonDecorator#access_course? has been
232
+ # renamed to SchoolWebsite::PersonDecorator#enrolled_in_course?. It will remain
233
+ # available until custom templates switch to enrolled_in_course?.
234
+ #
235
+ def convert_access_course(_segment)
236
+ "enrolled_in_course?"
237
+ end
238
+
239
+ #
240
+ # sktl:
241
+ # pluralize(
242
+ # learning_path.instructors.count,
243
+ # t('.instructor_bio_title.one'),
244
+ # t('.instructor_bio_title.many')
245
+ # )
246
+ #
247
+ # liquid:
248
+ # pluralize learning_path.instructors.count, .instructor_bio_title
249
+ #
250
+ # [{:chain=>[
251
+ # {:call_or_variable=>{:name=>"learning_path"@2373}},
252
+ # {:call_or_variable=>{:name=>"instructors"@2387}},
253
+ # {:call_or_variable=>{:name=>"count"@2399}}]
254
+ # },
255
+ # {:call=>{:name=>"t"@2406, :args=>{:string=>".instructor_bio_title.one"@2409}}},
256
+ # {:call=>{:name=>"t"@2438, :args=>{:string=>".instructor_bio_title.many"@2441}}}]
257
+ #
258
+ def convert_pluralize(segment)
259
+ args = segment[:args]
260
+
261
+ first_arg = convert_segment(args.first)
262
+ second_arg = args.second.dig(:call, :args, :string).to_s.split(".").second
263
+ second_arg = ".#{second_arg}"
264
+
265
+ "pluralize #{first_arg}, #{second_arg}"
266
+ end
267
+
268
+ #
269
+ # sktl:
270
+ # app('commerce').active?
271
+ #
272
+ # liquid:
273
+ # current_school.apps.commerce.active?
274
+ #
275
+ def convert_app(segment)
276
+ name = segment.first.dig(:call, :args, :string).to_sym
277
+
278
+ "current_school.apps.#{name}.active?"
279
+ end
280
+
281
+ #
282
+ # {:greater=>{:op=>"> "@5426, :arg=>{:number=>"3"@5428}}}
283
+ #
284
+ def convert_operator(segment)
285
+ seg = segment[segment.keys.first]
286
+ op = seg[:op].to_s.strip
287
+
288
+ operator_map = {
289
+ "|" => "or",
290
+ "&" => "and",
291
+ "=" => "==",
292
+ "-" => "| minus:",
293
+ "+" => "| plus:",
294
+ "!=" => "!=",
295
+ ">" => ">",
296
+ "<" => "<"
297
+ }
298
+
299
+ arg = seg[:arg].dup
300
+
301
+ if ["=", "-", "+", "!="].include?(op) && arg[:string].present?
302
+ arg[:string] = "'#{arg[:string]}'"
303
+ end
304
+
305
+ " #{operator_map[op]} #{convert_segment(arg)}"
306
+ end
307
+
308
+ #
309
+ # {% learning_path_item learning_path.current_person_learning_path_item %}
310
+ # <button class="uk-button uk-float-right completion-button">
311
+ # {% t .continue %}
312
+ # </button>
313
+ # {% endlearning_path_item %}
314
+ #
315
+ def convert_learning_path_item(segment)
316
+ scope_stack << :learning_path_item
317
+ convert_call(segment)
318
+ end
319
+
320
+ #
321
+ # sktl:
322
+ # {{ if display_search_form }}
323
+ # <li class="uk-padding-top">
324
+ # {{ partial 'search_form' }}
325
+ # </li>
326
+ # {{ end }}
327
+ #
328
+ # liquid:
329
+ # {% search %}
330
+ # <li class="uk-padding-top">
331
+ # {% include "search_form" %}
332
+ # </li>
333
+ # {% endsearch %}
334
+ #
335
+ def convert_display_search_form(segment)
336
+ name = segment.dig(:args, :call_or_variable, :name).to_sym
337
+
338
+ if name == :display_search_form
339
+ scope_stack << :search
340
+ "search"
341
+ elsif name == :display_catalog_search_form
342
+ scope_stack << :catalog_search
343
+ "catalog_search"
344
+ end
345
+ end
346
+
347
+ #
348
+ # sktl:
349
+ # {{ course.enrollment_url.replace('catalog', 'syllabus').replace('/enrollments', '') }}
350
+ # {{ person.name.truncate_words 1, '' }}
351
+ # {{ course.name.downcase }}
352
+ #
353
+ # liquid:
354
+ # {{ course.enrollment_url | replace: 'catalog', 'syllabus' | replace: '/enrollments', '' }}
355
+ # {{ person.name | truncatewords: 1, '' }}
356
+ # {{ course.name | downcase }}
357
+ #
358
+ def convert_filter(segment)
359
+ name = segment[segment.keys.first][:name].to_sym
360
+ seg_args = segment[segment.keys.first][:args]
361
+
362
+ if seg_args.nil?
363
+ return "| #{name}"
364
+ end
365
+
366
+ args = seg_args.map { |arg|
367
+ if arg[:number].present?
368
+ arg[:number].to_s
369
+ else
370
+ "\"#{arg[:string]}\""
371
+ end
372
+ }.join(", ")
373
+
374
+ name_map = {
375
+ replace: :replace,
376
+ truncate_words: :truncatewords
377
+ }
378
+
379
+ "| #{name_map[name]}: #{args}"
380
+ end
381
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SktlToLiquid::Type
4
+ FILTERS = [:replace, :truncate_words, :downcase].freeze
5
+ OPERATORS = [:greater, :or, :and, :equals, :subtract, :differs, :add].freeze
6
+
7
+ def initialize(segment)
8
+ @segment = segment
9
+ end
10
+
11
+ def to_sym
12
+ type = segment.keys.first
13
+
14
+ if type == :chain && loop_each_segment?
15
+ :loop
16
+ elsif type == :call_or_variable && else_segment?
17
+ :else
18
+ elsif type == :call && display_search_form_segment?
19
+ :display_search_form
20
+ elsif type == :call && partial_segment?
21
+ :partial
22
+ elsif type == :call && enrolled_in_segment?
23
+ :enrolled_in?
24
+ elsif type == :call && access_course_segment?
25
+ :access_course?
26
+ elsif type == :call && pluralize_segment?
27
+ :pluralize
28
+ elsif type == :chain && app_segment?
29
+ :app
30
+ elsif type == :call && learning_path_item_segment?
31
+ :learning_path_item
32
+ elsif type == :call && filter_segment?
33
+ :filter
34
+ elsif type == :call_or_variable && filter_segment?
35
+ :filter
36
+ else
37
+ type
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :segment
44
+
45
+ def loop_each_segment?
46
+ segment[:chain].select { |s| s.key?(:call) }.any? { |s| s.dig(:call, :name).to_sym == :each }
47
+ end
48
+
49
+ def else_segment?
50
+ segment.dig(:call_or_variable, :name).to_sym == :else
51
+ end
52
+
53
+ def partial_segment?
54
+ segment.dig(:call, :name).to_sym == :partial
55
+ end
56
+
57
+ def app_segment?
58
+ segment[:chain].any? { |s| s.dig(:call, :name)&.to_sym == :app }
59
+ end
60
+
61
+ def enrolled_in_segment?
62
+ [
63
+ :enrolled_in_learning_path?,
64
+ :enrolled_in_course?,
65
+ :progress_text
66
+ ].include?(segment.dig(:call, :name).to_sym)
67
+ end
68
+
69
+ def access_course_segment?
70
+ [
71
+ :access_course?
72
+ ].include?(segment.dig(:call, :name).to_sym)
73
+ end
74
+
75
+ def pluralize_segment?
76
+ segment.dig(:call, :name).to_sym == :pluralize
77
+ end
78
+
79
+ def learning_path_item_segment?
80
+ segment.dig(:call, :name).to_sym == :learning_path_item
81
+ end
82
+
83
+ def display_search_form_segment?
84
+ return false if segment.dig(:call, :name).to_sym != :if
85
+
86
+ [
87
+ :display_search_form,
88
+ :display_catalog_search_form
89
+ ].include?(segment.dig(:call, :args, :call_or_variable, :name)&.to_sym)
90
+ end
91
+
92
+ def filter_segment?
93
+ FILTERS.include?(segment.dig(:call, :name)&.to_sym) ||
94
+ FILTERS.include?(segment.dig(:call_or_variable, :name)&.to_sym)
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module SktlToLiquid
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'sktl_to_liquid/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'sktl_to_liquid'
7
+ spec.version = SktlToLiquid::VERSION
8
+ spec.authors = ['Adam Stomski']
9
+ spec.email = ['adam.stomski@gmail.com']
10
+
11
+ spec.summary = 'SKTL to Liquid converter'
12
+ spec.description = 'SKTL to Liquid converter'
13
+ spec.homepage = 'https://github.com/SchoolKeep/sktl_to_liquid'
14
+ spec.license = 'MIT'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/SchoolKeep/sktl_to_liquid'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/SchoolKeep/sktl_to_liquid/commits/master'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+
33
+ spec.add_dependency 'activesupport'
34
+ spec.add_dependency 'pastel'
35
+ spec.add_dependency 'scribble'
36
+ spec.add_dependency 'tty-spinner'
37
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sktl_to_liquid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Stomski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pastel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: scribble
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tty-spinner
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: SKTL to Liquid converter
112
+ email:
113
+ - adam.stomski@gmail.com
114
+ executables:
115
+ - sktl_to_liquid
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - exe/sktl_to_liquid
130
+ - lib/sktl_to_liquid.rb
131
+ - lib/sktl_to_liquid/converter.rb
132
+ - lib/sktl_to_liquid/type.rb
133
+ - lib/sktl_to_liquid/version.rb
134
+ - sktl_to_liquid.gemspec
135
+ homepage: https://github.com/SchoolKeep/sktl_to_liquid
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ homepage_uri: https://github.com/SchoolKeep/sktl_to_liquid
140
+ source_code_uri: https://github.com/SchoolKeep/sktl_to_liquid
141
+ changelog_uri: https://github.com/SchoolKeep/sktl_to_liquid/commits/master
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.7.8
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: SKTL to Liquid converter
162
+ test_files: []