jekyll-attendease 0.3.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +29 -4
  2. data/lib/jekyll-attendease.rb +117 -57
  3. metadata +3 -3
data/README.md CHANGED
@@ -17,8 +17,7 @@ Or install it yourself as:
17
17
  $ gem install jekyll-attendease
18
18
 
19
19
 
20
- Next, make sure to require it. Common practice is to add following line
21
- into `_plugins/ext.rb` file:
20
+ Next, make sure to require it. Add the following file `_plugins/attendease.rb` and content:
22
21
 
23
22
  ``` ruby
24
23
  require "jekyll-attendease"
@@ -34,7 +33,7 @@ You will need to configure by editing your `_config.yml`:
34
33
  #
35
34
  attendease:
36
35
  api_host: https://your-event-subdomain.attendease.com/
37
- test_mode: true
36
+ test_mode: true # this generates pages for /regsister, /schedule, and /presenters for local development and styling.
38
37
  ```
39
38
 
40
39
  Remember to replace `https://your-event-subdomain.attendease.com/` with your actual event url, or crazy things will happen!
@@ -57,6 +56,21 @@ We can also use logical expressions like so:
57
56
  {% endif %}
58
57
  ```
59
58
 
59
+ ## Magic Auth Tag
60
+
61
+ Simply add the auth script tag and the auth action and account tags and our system will know if you logged in or out and will be able to link to your account!
62
+
63
+ The script tag sets up an ajax callback to the server to determine if we are online or offline.
64
+ `{% attendease_auth_script %}`
65
+
66
+ This is simple a div with the id `attendease-auth-account`, maybe more in the future. When used with the `attendease_auth_script` tag it will populate with the link to the account of the attendee.
67
+
68
+ `{% attendease_auth_account %}`
69
+
70
+ This is simple a div with the id `attendease-auth-action`, maybe more in the future. When used with the `attendease_auth_script` tag it will populate with a `login` or `logout` action.
71
+
72
+ `{% attendease_auth_action %}`
73
+
60
74
  ## Contributing
61
75
 
62
76
  1. Fork it
@@ -65,6 +79,17 @@ We can also use logical expressions like so:
65
79
  4. Push to the branch (`git push origin my-new-feature`)
66
80
  5. Create new Pull Request
67
81
 
82
+ ## Testing
83
+
84
+ During development, you can create and install local builds:
85
+
86
+ `gem build jekyll-attendease.gemspec`
87
+
88
+ And then install it:
89
+
90
+ `gem install jekyll-attendease-``cat jekyll-attendease.gemspec|grep s.version|awk '{print $3}'|sed s/\'//g```
91
+
92
+ (where `x.x.x` is the version you've defined in the gemspec)
68
93
 
69
94
  ## License
70
95
 
@@ -88,4 +113,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
88
113
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
89
114
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
90
115
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
91
- SOFTWARE.
116
+ SOFTWARE.
@@ -7,89 +7,65 @@ module Jekyll
7
7
  class EventData < Generator
8
8
  safe true
9
9
 
10
+ include HTTParty
11
+
12
+ def get(url, options = {})
13
+ begin
14
+ self.class.get(url, options)
15
+ rescue => e
16
+ puts "Could not connect to #{url}."
17
+ puts e.inspect
18
+ end
19
+ end
20
+
10
21
  def generate(site)
11
- if attendease_config = site.config['attendease']
22
+ if @attendease_config = site.config['attendease']
12
23
 
13
- if attendease_config['api_host'] && !attendease_config['api_host'].match(/^http(.*).attendease.com/)
24
+ if @attendease_config['api_host'] && !@attendease_config['api_host'].match(/^http(.*).attendease.com/)
14
25
  raise "Is your Attendease api_host site properly in _config.yml? Needs to be something like https://myevent.attendease.com/"
15
26
  else
16
27
  # add a trailing slash if we are missing one.
17
- if attendease_config['api_host'][-1, 1] != '/'
18
- attendease_config['api_host'] += '/'
28
+ if @attendease_config['api_host'][-1, 1] != '/'
29
+ @attendease_config['api_host'] += '/'
19
30
  end
20
31
 
21
- attendease_data_path = "#{site.config['source']}/_attendease_data"
32
+ @attendease_data_path = "#{site.config['source']}/_attendease_data"
22
33
 
23
- FileUtils.mkdir_p(attendease_data_path)
34
+ FileUtils.mkdir_p(@attendease_data_path)
24
35
 
25
36
  update_data = true
26
37
 
27
- if File.exists?("#{attendease_data_path}/site.json")
28
- if (Time.now.to_i - File.mtime("#{attendease_data_path}/site.json").to_i) <= 30 # file is less than 30 seconds old
38
+ if File.exists?("#{@attendease_data_path}/site.json")
39
+ if (Time.now.to_i - File.mtime("#{@attendease_data_path}/site.json").to_i) <= 30 # file is less than 30 seconds old
29
40
  update_data = false
30
41
 
31
- site_json = File.read("#{attendease_data_path}/site.json")
42
+ site_json = File.read("#{@attendease_data_path}/site.json")
32
43
 
33
44
  event_data = JSON.parse(site_json)
34
45
  end
35
46
  end
36
47
 
37
48
  if update_data
38
- event_data = HTTParty.get("#{attendease_config['api_host']}api/site.json")
49
+ event_data = get("#{@attendease_config['api_host']}api/site.json")
39
50
 
40
51
  if !event_data['error']
41
- puts " [Attendease] Saving event data..."
52
+ puts "[Attendease] Saving event data..."
42
53
 
43
- File.open("#{attendease_data_path}/site.json", 'w+') { |file| file.write(event_data.parsed_response.to_json) }
54
+ File.open("#{@attendease_data_path}/site.json", 'w+') { |file| file.write(event_data.parsed_response.to_json) }
44
55
  else
45
56
  raise "Event data not found, is your Attendease api_host site properly in _config.yml?"
46
57
  end
47
58
 
59
+ #pages_to_fetch = ['choose_pass', 'checkout', 'dashboard']
48
60
 
49
61
  # Registration test pages, so we can style the forms!
50
- pages_to_fetch = ['choose_pass', 'checkout', 'dashboard']
51
-
52
- pages_to_fetch.each do |page|
53
- page_data = HTTParty.get("#{attendease_config['api_host']}attendease/preview/#{page}.html")
54
-
55
- if page_data.response.code.to_i == 200
56
- puts " [Attendease] Saving test data for register page (#{page})..."
57
-
58
- File.open("#{attendease_data_path}/attendease_test_register_#{page}.html", 'w+') { |file| file.write(page_data.parsed_response) }
59
- else
60
- raise "Event data not found, is your Attendease api_host site properly in _config.yml?"
61
- end
62
- end
62
+ fetch_pages ['choose_pass', 'checkout', 'dashboard'], 'register'
63
63
 
64
64
  # Schedule test pages, so we can style the forms!
65
- pages_to_fetch = ['schedule', 'session']
66
-
67
- pages_to_fetch.each do |page|
68
- page_data = HTTParty.get("#{attendease_config['api_host']}attendease/preview/#{page}.html")
69
-
70
- if page_data.response.code.to_i == 200
71
- puts " [Attendease] Saving test data for schedule page (#{page})..."
72
-
73
- File.open("#{attendease_data_path}/attendease_test_#{page}.html", 'w+') { |file| file.write(page_data.parsed_response) }
74
- else
75
- raise "Event data not found, is your Attendease api_host site properly in _config.yml?"
76
- end
77
- end
65
+ fetch_pages ['schedule', 'session', 'session_instance']
78
66
 
79
67
  # Presenter test pages, so we can style the forms!
80
- pages_to_fetch = ['presenters', 'presenter']
81
-
82
- pages_to_fetch.each do |page|
83
- page_data = HTTParty.get("#{attendease_config['api_host']}attendease/preview/#{page}.html")
84
-
85
- if page_data.response.code.to_i == 200
86
- puts " [Attendease] Saving test data for presenter page (#{page})..."
87
-
88
- File.open("#{attendease_data_path}/attendease_test_#{page}.html", 'w+') { |file| file.write(page_data.parsed_response) }
89
- else
90
- raise "Event data not found, is your Attendease api_host site properly in _config.yml?"
91
- end
92
- end
68
+ fetch_pages ['presenters', 'presenter']
93
69
  end
94
70
 
95
71
  # Adding to site config so we can access these variables globally wihtout using a Liquid Tag so we can use if/else
@@ -104,6 +80,29 @@ module Jekyll
104
80
  raise "Please set the Attendease event data in your _config.yml"
105
81
  end
106
82
  end
83
+
84
+ private
85
+
86
+ def fetch_pages(pages_to_fetch, prefix = nil)
87
+
88
+ pages_to_fetch.each do |page|
89
+ url = "#{@attendease_config['api_host']}attendease/preview/#{page}.html"
90
+ page_data = get(url)
91
+
92
+ if page_data.response.code.to_i == 200
93
+ puts " [Attendease] Saving test data for #{page} page..."
94
+
95
+ filename = []
96
+ filename << prefix unless prefix.nil?
97
+ filename << page
98
+
99
+ File.open("#{@attendease_data_path}/attendease_test_#{filename.join('_')}.html", 'w') { |file| file.write(page_data.parsed_response) }
100
+ else
101
+ raise "Could not retrieve #{url}. Is your Attendease api_host site properly in _config.yml?"
102
+ end
103
+ end
104
+
105
+ end
107
106
  end
108
107
 
109
108
 
@@ -149,9 +148,9 @@ layout: layout
149
148
  safe true
150
149
 
151
150
  def generate(site)
152
- if attendease_config = site.config['attendease']
151
+ if @attendease_config = site.config['attendease']
153
152
 
154
- if attendease_config['test_mode']
153
+ if @attendease_config['test_mode']
155
154
  puts " [Attendease] Generating pages to test the layouts..."
156
155
 
157
156
  puts " [Attendease] Generating /register/index.html"
@@ -174,6 +173,9 @@ layout: layout
174
173
 
175
174
  puts " [Attendease] Generating /schedule/session.html"
176
175
  site.pages << RegisterTestPage.new(site, site.source, File.join('schedule'), {:name => 'session.html', :liquid_tag => 'attendease_test_session'})
176
+
177
+ puts " [Attendease] Generating /schedule/session_instance.html"
178
+ site.pages << RegisterTestPage.new(site, site.source, File.join('schedule'), {:name => 'session_instance.html', :liquid_tag => 'attendease_test_session_instance'})
177
179
  end
178
180
 
179
181
  end
@@ -207,16 +209,70 @@ layout: layout
207
209
  end
208
210
 
209
211
  def render(context)
210
- attendease_data_path = "#{context['site']['source']}/_attendease_data"
212
+ @attendease_data_path = "#{context['site']['source']}/_attendease_data"
211
213
 
212
- if File.exists?("#{attendease_data_path}/#{@tag_name}.html")
213
- File.read("#{attendease_data_path}/#{@tag_name}.html")
214
+ if File.exists?("#{@attendease_data_path}/#{@tag_name}.html")
215
+ File.read("#{@attendease_data_path}/#{@tag_name}.html")
214
216
  else
215
- raise "Please set the Attendease event data in your _config.yml or read documentation about how to use this tag."
217
+ raise "#{@attendease_data_path}/#{@tag_name}.html not found."
216
218
  end
217
219
  end
218
220
  end
219
221
 
222
+ class AttendeaseAuthScriptTag < Liquid::Tag
223
+ def render(context)
224
+ content = <<-eos
225
+ <script type="text/javascript">
226
+ function handleAuthState()
227
+ {
228
+ var xmlhttp;
229
+ if (window.XMLHttpRequest)
230
+ {
231
+ xmlhttp=new XMLHttpRequest();
232
+ xmlhttp.onreadystatechange=function()
233
+ {
234
+ if (xmlhttp.readyState==4 && xmlhttp.status==200)
235
+ {
236
+ logout = '<a class="attendease-auth-logout" href="/attendease/logout">Logout</a>';
237
+ document.getElementById("attendease-auth-action").innerHTML = logout;
238
+
239
+ account = JSON.parse(xmlhttp.responseText);
240
+ account = '<a class="attendease-auth-account" href="/attendease/account">' + account.name + '</a>';
241
+ document.getElementById("attendease-auth-account").innerHTML = account;
242
+ }
243
+ else
244
+ {
245
+ login = '<a class="attendease-auth-logout" href="/attendease/login">Login</a>';
246
+ document.getElementById("attendease-auth-action").innerHTML = login;
247
+ }
248
+ }
249
+ xmlhttp.open("GET","/attendease/verify_credentials.json",true);
250
+ xmlhttp.send();
251
+ }
252
+ }
253
+
254
+ document.addEventListener('DOMContentLoaded',function(){
255
+ handleAuthState();
256
+ });
257
+
258
+ </script>
259
+ eos
260
+
261
+ content
262
+ end
263
+ end
264
+
265
+ class AttendeaseAuthAccountTag < Liquid::Tag
266
+ def render(context)
267
+ '<div id="attendease-auth-account"></div>'
268
+ end
269
+ end
270
+
271
+ class AttendeaseAuthActionTag < Liquid::Tag
272
+ def render(context)
273
+ '<div id="attendease-auth-action"></div>'
274
+ end
275
+ end
220
276
 
221
277
  class AttendeaseContent < Liquid::Tag
222
278
  def render(context)
@@ -228,10 +284,14 @@ layout: layout
228
284
  end
229
285
 
230
286
  Liquid::Template.register_tag('attendease_content', Jekyll::Attendease::AttendeaseContent)
287
+ Liquid::Template.register_tag('attendease_auth_script', Jekyll::Attendease::AttendeaseAuthScriptTag)
288
+ Liquid::Template.register_tag('attendease_auth_account', Jekyll::Attendease::AttendeaseAuthAccountTag)
289
+ Liquid::Template.register_tag('attendease_auth_action', Jekyll::Attendease::AttendeaseAuthActionTag)
231
290
  Liquid::Template.register_tag('attendease_test_register_choose_pass', Jekyll::Attendease::AttendeaseTest)
232
291
  Liquid::Template.register_tag('attendease_test_register_checkout', Jekyll::Attendease::AttendeaseTest)
233
292
  Liquid::Template.register_tag('attendease_test_register_dashboard', Jekyll::Attendease::AttendeaseTest)
234
293
  Liquid::Template.register_tag('attendease_test_schedule', Jekyll::Attendease::AttendeaseTest)
235
294
  Liquid::Template.register_tag('attendease_test_session', Jekyll::Attendease::AttendeaseTest)
295
+ Liquid::Template.register_tag('attendease_test_session_instance', Jekyll::Attendease::AttendeaseTest)
236
296
  Liquid::Template.register_tag('attendease_test_presenters', Jekyll::Attendease::AttendeaseTest)
237
297
  Liquid::Template.register_tag('attendease_test_presenter', Jekyll::Attendease::AttendeaseTest)
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: jekyll-attendease
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Wood
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-15 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,5 +74,5 @@ rubyforge_project:
74
74
  rubygems_version: 1.8.23
75
75
  signing_key:
76
76
  specification_version: 3
77
- summary: Attendease event helper for Jekyll!
77
+ summary: Attendease event helper for Jekyll
78
78
  test_files: []