spritz_for_jekyll 1.0.0 → 1.0.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: bbc867a4513a97a66f44f24061746e5b5d367a33
4
- data.tar.gz: 0243302d5c2bf4833cc12e032a33743753a76001
3
+ metadata.gz: 2dfa0d39f5ff86f6b62d91ac3ce2d5a407c045ac
4
+ data.tar.gz: f7956d20f6398652f33a49c0e2c2e72c83798f06
5
5
  SHA512:
6
- metadata.gz: 5db8a1dd3efd2204d5f6093af3e582695b6f01782cda73a7f2d0a37a7116b8ff2421be2d93fa5d04e9c522f31e90e973127b374fc914a683b7515ab2bebb2b54
7
- data.tar.gz: 36268557ae14ebe02f3c3fdf0214527f64876e82405d22af3d49883466a244e9317627fe21c88755b92d54ea153caecfd22788075a0fac071c674148ebea5230
6
+ metadata.gz: c699a6d1cbc27e36ffee393e2348e45d38eff25590edcd86debedde8f47205668cfc106bfed883d4053c8307dc153ed6ced3e5ed3b1068deef88b003f8fc45c5
7
+ data.tar.gz: f221e1e21732725af40646394fb34a14599baa92b4224e487cd0e711d48f8d01caeb4e8b91a52664d3d7384466a3b53f550acdb3d0895fc8f9ead2ae80bf4f10
@@ -0,0 +1,24 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1" />
5
+ <title>Spritz Login Success</title>
6
+ </head>
7
+ <body>
8
+ <script type="text/javascript">
9
+ var hash=window.location.hash,origin=window.location.protocol+"//"+window.location.host;
10
+ if (typeof(localStorage)!=="undefined") {
11
+ try {
12
+ localStorage.setItem("spritz.authResponse",hash);
13
+ } catch(e) {
14
+ if(console) {
15
+ console.log(e,"Can\'t write to localStorage");
16
+ }
17
+ }
18
+ }
19
+ if (window.opener) {
20
+ window.opener.postMessage(hash,origin);
21
+ }
22
+ </script>
23
+ </body>
24
+ </html>
@@ -0,0 +1,98 @@
1
+ module Spritz
2
+ def self.script_tag(client_id, base_url, login_success)
3
+ output = <<-HEREDOC
4
+ <script>
5
+ window.jQuery || document.write('<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\">\\x3C/script>');
6
+ var SpritzSettings = {
7
+ clientId: \"#{client_id}\",
8
+ redirectUri: \"#{base_url}/#{login_success}\"
9
+ };
10
+ if (!(/^https?:\\/\\//i.test(SpritzSettings.redirectUri))) {
11
+ SpritzSettings.redirectUri = window.location.protocol + "//" + window.location.host + SpritzSettings.redirectUri;
12
+ }
13
+ </script>
14
+ <script id=\"spritzjs\" type=\"text/javascript\" src=\"//sdk.spritzinc.com/js/1.0/js/spritz.min.js\"></script>
15
+ HEREDOC
16
+ output.gsub(/^\s*/, "")
17
+ end
18
+
19
+ def self.redicle_tag(options = {})
20
+ # Set default options
21
+ options["data-role"] = "spritzer"
22
+ attributes = Spritz::get_attribute_string(options)
23
+ "<p><div #{attributes}></div></p>"
24
+ end
25
+
26
+ def self.get_attribute_string(options)
27
+ attributes = ""
28
+ options.each do |k, v|
29
+ next unless k and v
30
+ attributes += " " unless attributes.empty?
31
+ attributes += "#{k} = '#{v}'"
32
+ end
33
+ attributes
34
+ end
35
+
36
+ def self.sanitize_options(config)
37
+ return unless config["spritz"] && config["spritz"]["url"]
38
+
39
+ if config[config["spritz"]["url"]]
40
+ config["spritz"]["url"] = config[config["spritz"]["url"]]
41
+ end
42
+
43
+ unless /https?:\/\// =~ config["spritz"]["url"]
44
+ config["spritz"]["url"] = "http://" + config["spritz"]["url"]
45
+ Jekyll.logger.warn "Spritz for Jekyll:", " URL does not contain protocol. We will use HTTP by default."
46
+ end
47
+
48
+ if /\/$/ =~ config["spritz"]["url"]
49
+ config["spritz"]["url"].gsub!(/\/+$/, "")
50
+ Jekyll.logger.warn "Spritz for Jekyll:", "URL ends with a forward slash. We will remove it for you."
51
+ end
52
+ end
53
+
54
+ private
55
+ def get_options(config)
56
+ @options = {}
57
+ Spritz::sanitize_options(config)
58
+
59
+ @options[:client_id] = config["spritz"]["client_id"]
60
+ @options[:url] = config["spritz"]["url"]
61
+ @options[:login_success] = config["spritz"]["login_success_name"]
62
+ @options[:selector] = config["spritz"]["selector"]
63
+ @options[:automode] = config["spritz"]["auto_mode"]
64
+
65
+ # Redicle options
66
+ @options[:redicle] = {}
67
+ return unless config["spritz"]["redicle"]
68
+ @options[:redicle][:redicleWidth] = config["spritz"]["redicle"]["width"]
69
+ @options[:redicle][:redicleHeight] = config["spritz"]["redicle"]["height"]
70
+ @options[:redicle][:defaultSpeed] = config["spritz"]["redicle"]["default_speed"]
71
+ @options[:redicle][:speedItems] = config["spritz"]["redicle"]["speed_items"]
72
+ @options[:redicle][:controlButtons] = config["spritz"]["redicle"]["control_buttons"]
73
+ @options[:redicle][:controlTitles] = config["spritz"]["redicle"]["control_titles"]
74
+ end
75
+
76
+ def warn_and_set_default
77
+ if @options[:client_id].nil?
78
+ Jekyll.logger.warn "Spritz for Jekyll:", "You need a client ID!"
79
+ @options[:client_id] = "12345"
80
+ end
81
+
82
+ if @options[:url].nil?
83
+ Jekyll.logger.warn "Spritz for Jekyll:", "URL not set. Will guess on client side."
84
+ end
85
+
86
+ if @options[:login_success].nil?
87
+ @options[:login_success] = "login_success.html"
88
+ end
89
+
90
+ if @options[:automode].nil?
91
+ @options[:automode] = true
92
+ end
93
+
94
+ unless @options[:redicle].nil?
95
+ @options[:redicle].delete_if { |_,v| v.nil? }
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,12 @@
1
+ module Spritz
2
+ module Tags
3
+ def get_site(environments)
4
+ @site = nil
5
+ environments.each do |e|
6
+ if e.has_key?("site")
7
+ return @site = e["site"]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ module Spritz
2
+ class Generator < Jekyll::Generator
3
+ include Spritz
4
+
5
+ def initialize(*args)
6
+ super
7
+ login_success_path = args[0]["spritz"]["login_success_name"] || "login_success.html"
8
+ dirname = File.dirname(login_success_path)
9
+
10
+ FileUtils.mkdir_p(dirname)
11
+
12
+ source = File.join(File.dirname(__FILE__), "..", "login_success.html")
13
+ destination = File.join(args[0]["source"], login_success_path)
14
+ FileUtils.copy(source, destination)
15
+ end
16
+
17
+ def generate(site)
18
+ get_options(site.config)
19
+ warn_and_set_default
20
+ return unless @options[:automode]
21
+
22
+ snippet = Spritz::script_tag(@options[:client_id], @options[:url], @options[:login_success])
23
+ snippet += Spritz::redicle_tag("data-selector" => @options[:selector], "data-options" => @options[:redicle].to_json)
24
+
25
+ site.posts.each do |p|
26
+ p.content = snippet + p.content if p.data["spritz"].nil? or p.data["spritz"]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Spritz
2
+ class SpritzScriptTag < Liquid::Tag
3
+ include Spritz
4
+ include Spritz::Tags
5
+
6
+ def render(context)
7
+ get_site(context.environments)
8
+ return if @site.nil?
9
+ get_options(@site)
10
+ warn_and_set_default
11
+ Spritz::script_tag(@options[:client_id], @options[:url], @options[:login_success])
12
+ end
13
+ end
14
+
15
+ class SpritzRedicleTag < Liquid::Tag
16
+ include Spritz
17
+ include Spritz::Tags
18
+
19
+ def render(context)
20
+ get_site(context.environments)
21
+ return if @site.nil?
22
+ get_options(@site)
23
+ warn_and_set_default
24
+ Spritz::redicle_tag("data-selector" => @options[:selector], "data-options" => @options[:redicle].to_json)
25
+ end
26
+ end
27
+ end
28
+
29
+ Liquid::Template.register_tag('spritz_scripts', Spritz::SpritzScriptTag)
30
+ Liquid::Template.register_tag('spritz_redicle', Spritz::SpritzRedicleTag)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spritz_for_jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yihang Ho
@@ -58,7 +58,12 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
+ - lib/login_success.html
61
62
  - lib/spritz_for_jekyll.rb
63
+ - lib/spritz_for_jekyll/commons/spritz.rb
64
+ - lib/spritz_for_jekyll/commons/tags.rb
65
+ - lib/spritz_for_jekyll/generator.rb
66
+ - lib/spritz_for_jekyll/tags.rb
62
67
  homepage: https://github.com/yihangho/spritz-for-jekyll
63
68
  licenses:
64
69
  - MIT