Class: Jektify::Main

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jektify/main.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, input, tokens) ⇒ Main

Returns a new instance of Main.



57
58
59
60
# File 'lib/jektify/main.rb', line 57

def initialize(tag_name, input, tokens)
  super
  @input = input
end

Instance Method Details

#render(context) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/jektify/main.rb', line 62

def render(context)
  engine = Engine.new
  render_obj = Render.new
  config = engine.yml_config('_config.yml')[APP_NAME]

  # Split do input e configurações do Spotify
  input_split = engine.split_params(@input)
  spotify_user = input_split[0].strip
  spotify_embed_category = input_split[1].strip
  spotify_id = input_split[2].strip
  spotify_embed_theme = input_split[3].strip
  spotify_embed_theme = spotify_embed_theme == "light" ? "white" : spotify_embed_theme

  engine.error_different_string(
    spotify_embed_theme,
    "dark",
    "white",
    "[x] Error: Parameter incorrect in {% spotify [user]/[type]/[id]/[theme] %}."
  )

  player_color = spotify_embed_theme == "dark" ? "0" : "1"
  spotify_embed_url = "https://open.spotify.com/embed/#{spotify_embed_category}/#{spotify_id}?theme=#{player_color}"

  # Validações das configs
  %w[enable open].each do |key|
    engine.error_different_true_false(config[key], "[x] Error: The property 'spotify => #{key}' in '_config.yml' is missing or invalid.") unless config[key].nil?
  end

  if config["title"]
    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?
  end

  if config["description"]
    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?
  end

  if config["toggle"]
    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?
  end

  # Renderiza o player
  render_obj.rendering(APP_NAME, config, spotify_embed_category, spotify_embed_url, spotify_embed_theme)
end