jektify 1.0.6 → 1.0.8

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.
data/lib/jektify/main.rb CHANGED
@@ -1,128 +1,109 @@
1
- # Required libs
2
1
  require "jekyll"
3
2
  require "yaml"
4
- require "benchmark"
5
3
  require "find"
6
4
  require "fileutils"
7
- require "open-uri"
8
-
5
+ require "liquid"
9
6
 
10
7
  module Jektify
11
-
12
- # Instance class
13
- ENGINE = Engine.new
14
- RENDER = Render.new
15
-
16
- # Variables global
17
8
  APP_NAME = "jektify"
18
- YML_LOAD = ENGINE.yml_config('_config.yml')
19
- APP_ROOT_CONFIG = YML_LOAD["#{APP_NAME}"]
20
-
21
9
 
22
10
  class Generator < Jekyll::Generator
11
+ safe true
12
+ priority :normal
23
13
 
24
14
  def generate(site)
25
- # Before, verify structure Jektify in _config.yml
26
- ENGINE.yml_verify(APP_ROOT_CONFIG)
15
+ engine = Engine.new
16
+ render_obj = Render.new
17
+ config = engine.yml_config('_config.yml')[APP_NAME]
18
+
19
+ # Verifica se a configuração existe
20
+ engine.yml_verify(config)
27
21
 
28
22
  @site = site
29
23
 
30
- # It will only generate the Javascript file for the user, if the 'Toggle' feature is enabled in the file "_config.yml".
31
- if APP_ROOT_CONFIG["enable"] == true
32
- @site.static_files.concat static_files if APP_ROOT_CONFIG["toggle"].nil? || APP_ROOT_CONFIG["toggle"]["enable"] == true
24
+ # Configura Sass para Jekyll
25
+ engine.configure_sass_for_jekyll(site)
26
+
27
+ # Copia arquivos estáticos caso toggle esteja habilitado
28
+ if config["enable"] == true
29
+ @site.static_files.concat static_files(engine) if config["toggle"].nil? || config["toggle"]["enable"] == true
33
30
  end
34
- ENGINE.copy_sass_manual(APP_ROOT_CONFIG)
35
31
  end
36
32
 
37
- # This method searches for folders and files in the assets root directory.
38
- # After searching all files stores in an array and then copying to
39
- # the folder "_site".
40
- def static_files
41
- source = File.dirname(ENGINE.assets_path)
42
- asset_files.map do |file|
33
+ private
34
+
35
+ # Lista arquivos estáticos (exceto Sass)
36
+ def static_files(engine)
37
+ source = File.dirname(engine.assets_path)
38
+ asset_files(engine).map do |file|
43
39
  dir = File.dirname(file)
44
40
  file_name = File.basename(file)
45
- Jekyll::StaticFile.new @site, source, dir, file_name
41
+ Jekyll::StaticFile.new(@site, source, dir, file_name)
46
42
  end
47
43
  end
48
44
 
49
- # Get paths and fils directory 'assets'
50
- def asset_files
51
- asset_files = []
52
- Find.find(ENGINE.assets_path).each do |path|
45
+ def asset_files(engine)
46
+ files = []
47
+ Find.find(engine.assets_path).each do |path|
53
48
  next if File.directory?(path)
54
- next if path.include?(ENGINE.stylesheets_sass_path)
55
- asset_files << path.sub(ENGINE.assets_path, 'assets')
49
+ next if path.include?(engine.stylesheets_sass_path)
50
+ files << path.sub(engine.assets_path, 'assets')
56
51
  end
57
- asset_files
52
+ files
58
53
  end
54
+ end
59
55
 
60
- end # Generator
61
-
62
- # class load SASS
63
- class << self
64
-
65
- def loadSass
66
- ENGINE.configure_sass(ENGINE)
67
- end
68
-
69
- end # self
70
-
71
- # Implement Jektify in Page
72
56
  class Main < Liquid::Tag
73
-
74
57
  def initialize(tag_name, input, tokens)
75
58
  super
76
- # Name tag in liquid
77
- # @tag_name = tag_name # DEPRECATED
78
59
  @input = input
79
60
  end
80
61
 
81
62
  def render(context)
82
- # Sets the data splitter
83
- input_split = ENGINE.split_params(@input)
63
+ engine = Engine.new
64
+ render_obj = Render.new
65
+ config = engine.yml_config('_config.yml')[APP_NAME]
84
66
 
85
- # Determines the positions of each data with the divisor
67
+ # Split do input e configurações do Spotify
68
+ input_split = engine.split_params(@input)
86
69
  spotify_user = input_split[0].strip
87
70
  spotify_embed_category = input_split[1].strip
88
71
  spotify_id = input_split[2].strip
89
72
  spotify_embed_theme = input_split[3].strip
73
+ spotify_embed_theme = spotify_embed_theme == "light" ? "white" : spotify_embed_theme
90
74
 
91
- # Transpiler variable "theme"
92
- spotify_embed_theme == "light" ? spotify_embed_theme = "white" : spotify_embed_theme = input_split[3].strip
75
+ engine.error_different_string(
76
+ spotify_embed_theme,
77
+ "dark",
78
+ "white",
79
+ "[x] Error: Parameter incorrect in {% spotify [user]/[type]/[id]/[theme] %}."
80
+ )
93
81
 
94
- # Checks a series of error values in the settings of Jektify in sctructure {% spotify [user]/[type]/[id]/[theme] %}
95
- ENGINE.error_different_string(spotify_embed_theme, "dark", "white", "[x] Error: Parameter incorrect in {% spotify [user]/[type]/[id]/[theme] %}.")
82
+ player_color = spotify_embed_theme == "dark" ? "0" : "1"
83
+ spotify_embed_url = "https://open.spotify.com/embed/#{spotify_embed_category}/#{spotify_id}?theme=#{player_color}"
96
84
 
97
- # Customizing Url Spotify
98
- # E.g: { % spotify [user]/[type]/[id]/[theme] % }
99
- spotify_embed_url = "https://embed.spotify.com/?uri=spotify:#{spotify_embed_category}:#{spotify_id}&theme=#{spotify_embed_theme}"
100
- spotify_embed_url = "https://embed.spotify.com/?uri=spotify:user:#{spotify_user}:#{spotify_embed_category}:#{spotify_id}&theme=#{spotify_embed_theme}" unless spotify_embed_category != "playlist"
101
-
102
-
103
- # Checks a series of error values in the settings of Jektify in _config.yml
104
- ENGINE.error_different_true_false(APP_ROOT_CONFIG["enable"], "[x] Error: The property 'spotify => enable' in file '_config.yml' does not exist or its value is incorrect. Use: [ true | false ]") unless APP_ROOT_CONFIG["enable"].nil?
105
-
106
-
107
- ENGINE.error_different_true_false(APP_ROOT_CONFIG["open"], "[x] Error: The property 'spotify => open' in file '_config.yml' does not exist or its value is incorrect. Use: [ true | false ]") unless APP_ROOT_CONFIG["open"].nil?
108
-
109
- ENGINE.error_different_true_false(APP_ROOT_CONFIG["title"]["enable"], "[x] Error: The property 'spotify => title => enable' in file '_config.yml' does not exist or its value is incorrect. Use: [ true | false ]") unless APP_ROOT_CONFIG["title"].nil?
110
-
111
- ENGINE.error_different_true_false(APP_ROOT_CONFIG["description"]["enable"], "[x] Error: The property 'spotify => description => enable' in file '_config.yml' does not exist or its value is incorrect. Use: [ true | false ]") unless APP_ROOT_CONFIG["description"].nil?
112
-
113
- ENGINE.error_different_true_false(APP_ROOT_CONFIG["toggle"]["enable"], "[x] Error: The property 'spotify => toggle => enable' in file '_config.yml' does not exist or its value is incorrect. Use: [ true | false ]") unless APP_ROOT_CONFIG["toggle"].nil?
85
+ # Validações das configs
86
+ %w[enable open].each do |key|
87
+ engine.error_different_true_false(config[key], "[x] Error: The property 'spotify => #{key}' in '_config.yml' is missing or invalid.") unless config[key].nil?
88
+ end
114
89
 
115
- # If there are no errors starting the plugin
116
- RENDER.rendering(APP_NAME, APP_ROOT_CONFIG, spotify_embed_category, spotify_embed_url, spotify_embed_theme)
90
+ if config["title"]
91
+ engine.error_different_true_false(config["title"]["enable"], "[x] Error: The property 'spotify => title => enable' in '_config.yml' is missing or invalid.") unless config["title"].nil?
92
+ end
117
93
 
118
- end # def render
94
+ if config["description"]
95
+ engine.error_different_true_false(config["description"]["enable"], "[x] Error: The property 'spotify => description => enable' in '_config.yml' is missing or invalid.") unless config["description"].nil?
96
+ end
119
97
 
120
- end # class Main
98
+ if config["toggle"]
99
+ engine.error_different_true_false(config["toggle"]["enable"], "[x] Error: The property 'spotify => toggle => enable' in '_config.yml' is missing or invalid.") unless config["toggle"].nil?
100
+ end
121
101
 
122
- # Load files: (SASS)
123
- Jektify.loadSass
102
+ # Renderiza o player
103
+ render_obj.rendering(APP_NAME, config, spotify_embed_category, spotify_embed_url, spotify_embed_theme)
104
+ end
105
+ end
124
106
 
125
- # Register plugin (tag)
107
+ # Registra a tag Liquid
126
108
  Liquid::Template.register_tag(APP_NAME, Jektify::Main)
127
-
128
- end # module Jektify
109
+ end
@@ -1,85 +1,59 @@
1
1
  module Jektify
2
-
3
2
  class Render
4
-
5
- $DATETIME = Time.new
6
-
7
- def rendering(app_name, app_root_config, spotify_embed_category, spotify_embed_url, spotify_embed_theme)
8
-
9
- # Checks the state of the description" property in the file "_config.yml"
10
- # jektify__description = app_root_config["title"]["enable"] == false and app_root_config["description"]["enable"] == false ? jektify__description = "none" : jektify__description = "block"
11
-
12
- # Checks the state of the "title => enable" property in the file "_config.yml"
13
- jektify__title = app_root_config["title"]["enable"] == true ? jektify__title = "block" : jektify__title = "none"
14
-
15
- # Checks the state of the "title => enable" property in the file "_config.yml"
16
- jektify__description = app_root_config["description"]["enable"] == true ? jektify__description = "block" : jektify__description = "none"
17
-
18
- # Sets the size of the box where the tracks will stay.
19
- spotify_embed_category == "album" || spotify_embed_category == "playlist" || spotify_embed_category == "artist" ? box_height = 380 : box_height = 80
20
-
21
- # Sets whether the Jektify box will start open or closed
22
- open_track = app_root_config["open"] == true ? open_track = "block" : open_track = "none"
23
-
24
- # If the option to open the box at startup is enabled, the toggle button will also undergo open and close actions.
25
- jektify__button_action = app_root_config["open"] == true ? jektify__button_action = "jektify__button--open" : jektify__button_action = "jektify__button--closed"
26
-
27
- # Checks whether the user will use the Toggle feature or not.
28
- # If do not use it, JavaScript will not be generated for the user. Because it is he who does the Toggle feature.
29
- # The block generating Javascript is in the "Generator" class in the "generate" method. Version 3.0.1
30
- # NOTe: If the user uses the previous version of the "_config.yml" file, there will be no conflict.
31
- jektify__toggle_button = "<span class=\"jektify__button jektify__button--#{spotify_embed_theme} jektify__button--custom #{jektify__button_action}\">+</span>" if app_root_config["toggle"].nil? || app_root_config["toggle"]["enable"] == true
32
-
33
- open_track = "block" if !app_root_config["toggle"].nil? && app_root_config["toggle"]["enable"] == false
34
- jektify__toggle_button = "" if !app_root_config["toggle"].nil? && app_root_config["toggle"]["enable"] == false
35
-
36
- # This is a feature for adding a Spotify user link. Version 3.0.1
37
- # NOTe: If the user uses the previous version of the "_config.yml" file, there will be no conflict.
38
- if app_root_config["spotify"].nil?
39
- jektify__spotify_user = ""
40
- else
41
- jektify__spotify_user = "<div class=\"jektify__user\"><a href=\"https://open.spotify.com/user/#{app_root_config["spotify"]["user"]}\" target=\"_blank\" class=\"jektify__user-link jektify__user-link--#{spotify_embed_theme} jektify__user-link--custom\" title=\"#{app_root_config["spotify"]["text"]}\"><span class=\"jektify__user-text jektify__user-text--#{spotify_embed_theme} jektify__user-text--custom\">#{app_root_config["spotify"]["text"]}</span></a></div>" if !app_root_config["spotify"]["user"].nil? && !app_root_config["spotify"]["text"].nil?
3
+ $DATETIME = Time.now
4
+
5
+ def rendering(app_name, app_root_config, category, url, theme)
6
+ jektify_title = app_root_config.dig("title", "enable") ? "block" : "none"
7
+ jektify_description = app_root_config.dig("description", "enable") ? "block" : "none"
8
+ box_height = %w[album playlist artist].include?(category) ? 380 : 80
9
+ open_track = app_root_config["open"] ? "block" : "none"
10
+ button_action = app_root_config["open"] ? "jektify__button--open" : "jektify__button--closed"
11
+
12
+ toggle_button = if app_root_config.dig("toggle", "enable").nil? || app_root_config.dig("toggle", "enable")
13
+ "<span class=\"jektify__button jektify__button--#{theme} jektify__button--custom #{button_action}\">+</span>"
14
+ else
15
+ ""
16
+ end
17
+
18
+ open_track = "block" if app_root_config.dig("toggle", "enable") == false
19
+
20
+ spotify_user_html = ""
21
+ if app_root_config["spotify"]
22
+ user = app_root_config["spotify"]["user"]
23
+ text = app_root_config["spotify"]["text"]
24
+ if user && text
25
+ spotify_user_html = <<~HTML
26
+ <div class="jektify__user">
27
+ <a href="https://open.spotify.com/user/#{user}" target="_blank" class="jektify__user-link jektify__user-link--#{theme} jektify__user-link--custom" title="#{text}">
28
+ <span class="jektify__user-text jektify__user-text--#{theme} jektify__user-text--custom">#{text}</span>
29
+ </a>
30
+ </div>
31
+ HTML
32
+ end
42
33
  end
43
34
 
44
-
45
- # Render template if enable == true
46
- if app_root_config["enable"] == true
47
- %(<dl class="jektify jektify--#{spotify_embed_theme} jektify--custom">
48
-
49
- <dt class="jektify__header jektify__header--#{spotify_embed_theme} jektify__header--custom">
50
-
51
- <a class="jektify__brand jektify__brand--#{spotify_embed_theme} jektify__brand--custom" href="https://#{app_name}.github.io" target="_blank">#{app_name}</a>
35
+ return unless app_root_config["enable"]
52
36
 
53
- <i class="jektify__year jektify__year--#{spotify_embed_theme} jektify__year--custom">&copy;&nbsp;#{$DATETIME.strftime("%Y")}&nbsp;</i>
54
- #{jektify__toggle_button}
37
+ <<~HTML
38
+ <dl class="jektify jektify--#{theme} jektify--custom">
39
+ <dt class="jektify__header jektify__header--#{theme} jektify__header--custom">
40
+ <a class="jektify__brand jektify__brand--#{theme} jektify__brand--custom" href="https://#{app_name}.github.io" target="_blank">#{app_name}</a>
41
+ <i class="jektify__year jektify__year--#{theme} jektify__year--custom">&copy;&nbsp;#{$DATETIME.year}&nbsp;</i>
42
+ #{toggle_button}
55
43
  </dt>
56
-
57
- <dd class="jektify__body jektify__body--#{spotify_embed_theme} jektify__body--custom" style="display: #{open_track}">
58
-
59
- #{jektify__spotify_user}
60
-
61
- <h1 class="jektify__title jektify__title--#{spotify_embed_theme} jektify__user--#{spotify_embed_theme} jektify__title--custom" style="display: #{jektify__title};">#{app_root_config["title"]["text"]}</h1>
62
-
63
- <p class="jektify__description jektify__description--#{spotify_embed_theme} jektify__description--custom" style="display: #{jektify__description};">#{app_root_config["description"]["text"]}</p>
64
-
65
- <div class="jektify__tracklist jektify__tracklist--#{spotify_embed_theme} jektify__tracklist--custom">
66
- <iframe id="jektify__track"
67
- class="jektify__track jektify__track--#{spotify_embed_theme}
68
- jektify__track--custom"
69
- src="#{spotify_embed_url}"
70
- width="100%"
71
- height="#{box_height}"
72
- frameborder="0"
73
- allowtransparency="true"
74
- allow="encrypted-media">
44
+ <dd class="jektify__body jektify__body--#{theme} jektify__body--custom" style="display: #{open_track}">
45
+ #{spotify_user_html}
46
+ <h1 class="jektify__title jektify__title--#{theme} jektify__title--custom" style="display: #{jektify_title};">#{app_root_config.dig("title", "text")}</h1>
47
+ <p class="jektify__description jektify__description--#{theme} jektify__description--custom" style="display: #{jektify_description};">#{app_root_config.dig("description", "text")}</p>
48
+ <div class="jektify__tracklist jektify__tracklist--#{theme} jektify__tracklist--custom">
49
+ <iframe id="jektify__track" class="jektify__track jektify__track--#{theme} jektify__track--custom"
50
+ src="#{url}" width="100%" height="#{box_height}" frameborder="0"
51
+ allowtransparency="true" allow="encrypted-media">
75
52
  </iframe>
76
53
  </div>
77
54
  </dd>
78
- </dl>)
79
- end
80
-
81
- end # def content
82
-
83
- end # class Render
84
-
85
- end # module Jektify
55
+ </dl>
56
+ HTML
57
+ end
58
+ end
59
+ end
@@ -8,7 +8,7 @@ module Jektify
8
8
 
9
9
  MAJOR = 1
10
10
  MINOR = 0
11
- PATCH = 6
11
+ PATCH = 8
12
12
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
13
13
 
14
14
  end