northpass 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.pairs +16 -0
  4. data/.rspec +2 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.ocra +7 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +100 -0
  9. data/Rakefile +36 -0
  10. data/bin/sk +10 -0
  11. data/bin/sk_gui +8 -0
  12. data/circle.yml +8 -0
  13. data/config/ca-bundle.crt +3894 -0
  14. data/config/color_scheme.css.erb +91 -0
  15. data/config/fixtures.yml +255 -0
  16. data/config/learning.html.erb +43 -0
  17. data/config/learning_color_scheme.css.erb +70 -0
  18. data/config/locale.yml +110 -0
  19. data/config/school_website.html.erb +37 -0
  20. data/lib/schoolkeep.rb +16 -0
  21. data/lib/schoolkeep/cli.rb +135 -0
  22. data/lib/schoolkeep/client.rb +54 -0
  23. data/lib/schoolkeep/fixture.rb +130 -0
  24. data/lib/schoolkeep/fixture/stubs.rb +106 -0
  25. data/lib/schoolkeep/gui_client.rb +99 -0
  26. data/lib/schoolkeep/scribble.rb +480 -0
  27. data/lib/schoolkeep/scribble/methods/app.rb +17 -0
  28. data/lib/schoolkeep/scribble/methods/collection_each.rb +3 -0
  29. data/lib/schoolkeep/scribble/methods/display_search_form.rb +28 -0
  30. data/lib/schoolkeep/scribble/methods/filter_parameter_value.rb +11 -0
  31. data/lib/schoolkeep/scribble/methods/hide_search_box.rb +17 -0
  32. data/lib/schoolkeep/scribble/methods/l.rb +13 -0
  33. data/lib/schoolkeep/scribble/methods/limit.rb +11 -0
  34. data/lib/schoolkeep/scribble/methods/no_filter_selected_class.rb +19 -0
  35. data/lib/schoolkeep/scribble/methods/pluralize.rb +32 -0
  36. data/lib/schoolkeep/scribble/methods/query_parameter_value.rb +11 -0
  37. data/lib/schoolkeep/scribble/methods/script.rb +45 -0
  38. data/lib/schoolkeep/scribble/methods/t.rb +25 -0
  39. data/lib/schoolkeep/server.rb +132 -0
  40. data/lib/schoolkeep/template.rb +67 -0
  41. data/lib/schoolkeep/template_names.rb +24 -0
  42. data/lib/schoolkeep/version.rb +3 -0
  43. data/lib/schoolkeep/views/asset_cache.rb +34 -0
  44. data/lib/schoolkeep/views/color_scheme.rb +19 -0
  45. data/lib/schoolkeep/views/layout.rb +72 -0
  46. data/media/schoolkeep.ico +0 -0
  47. data/media/sk-144.gif +0 -0
  48. data/media/sk-16.gif +0 -0
  49. data/media/sk-57.gif +0 -0
  50. data/media/sk-72.gif +0 -0
  51. data/schoolkeep.gemspec +28 -0
  52. data/spec/cli_spec.rb +70 -0
  53. data/spec/features/cli_spec.rb +51 -0
  54. data/spec/features/client_spec.rb +48 -0
  55. data/spec/fixture_spec.rb +68 -0
  56. data/spec/methods/filter_parameter_value_spec.rb +28 -0
  57. data/spec/methods/pluralize_spec.rb +41 -0
  58. data/spec/methods/query_parameter_value_spec.rb +26 -0
  59. data/spec/methods/script_spec.rb +52 -0
  60. data/spec/methods/t_spec.rb +33 -0
  61. data/spec/server_spec.rb +81 -0
  62. data/spec/spec_helper.rb +48 -0
  63. data/spec/views/asset_cache_spec.rb +24 -0
  64. data/spec/views/color_scheme_spec.rb +15 -0
  65. metadata +223 -0
@@ -0,0 +1,17 @@
1
+ module Scribble
2
+ module Methods
3
+ class App < Method
4
+ register :app, String
5
+
6
+ def app name
7
+ apps.public_send(name)
8
+ end
9
+
10
+ private
11
+
12
+ def apps
13
+ @receiver.variables[:current_school].apps
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ class CollectionEach < Scribble::Methods::Each
2
+ register :each, String, on: ActiveRecord::Associations::CollectionProxy
3
+ end
@@ -0,0 +1,28 @@
1
+ module Scribble
2
+ module Methods
3
+ class DisplaySearchCoursesForm < Method
4
+ MY_CONTENT_CONTROLLER_IDENTIFIER = "school_website/my_content"
5
+ SEARCH_CONTROLLER_IDENTIFIER = "school_website/search"
6
+
7
+ register :display_search_form
8
+
9
+ def display_search_form
10
+ @receiver.variables[:current_school].search_enabled? && (my_content? || course_results?)
11
+ end
12
+
13
+ private
14
+
15
+ def my_content?
16
+ !!controller_context[MY_CONTENT_CONTROLLER_IDENTIFIER]
17
+ end
18
+
19
+ def course_results?
20
+ !!controller_context[SEARCH_CONTROLLER_IDENTIFIER]
21
+ end
22
+
23
+ def controller_context
24
+ @current_controller ||= @receiver.variables[:params].fetch(:controller, "")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Scribble
2
+ module Methods
3
+ class FilterParameterValue < Method
4
+ register :filter_parameter_value
5
+
6
+ def filter_parameter_value
7
+ CGI::escape_html @receiver.variables[:params].fetch(:filter, {}).fetch(:category_name, nil).to_s
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module Scribble
2
+ module Methods
3
+ class HideSearchBox < Method
4
+ register :hide_search_box
5
+
6
+ def hide_search_box
7
+ [params.fetch(:filter, nil), params.fetch(:q, nil)].none?
8
+ end
9
+
10
+ private
11
+
12
+ def params
13
+ @receiver.variables[:params]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require "i18n"
2
+
3
+ module Scribble
4
+ module Methods
5
+ class L < Method
6
+ register :l, Time, String
7
+
8
+ def l(time, format)
9
+ I18n.l(time, format: format.to_sym)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Scribble
2
+ module Methods
3
+ class Limit < Method
4
+ register :limit, Fixnum, on: Enumerable
5
+
6
+ def limit(count)
7
+ @receiver.first(count)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Scribble
2
+ module Methods
3
+ class NoFilterSelectedClass < Method
4
+ ACTIVE_CSS_CLASS = "uk-text-bold".freeze
5
+
6
+ register :no_filter_selected_class
7
+
8
+ def no_filter_selected_class
9
+ ACTIVE_CSS_CLASS unless filter_parameter
10
+ end
11
+
12
+ private
13
+
14
+ def filter_parameter
15
+ @receiver.variables[:params].fetch(:filter, nil)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require "i18n"
2
+ begin
3
+ gem "activesupport", ">= 4.2.0"
4
+ rescue Gem::LoadError
5
+ puts "activesupport is not installed, automatic pluralization will not work accurately"
6
+
7
+ module FakePluralize
8
+ def pluralize(locale)
9
+ self + "s"
10
+ end
11
+ end
12
+
13
+ unless defined?(ActiveSupport::Inflector)
14
+ String.include(FakePluralize)
15
+ end
16
+ end
17
+
18
+ module Scribble
19
+ module Methods
20
+ class Pluralize < Method
21
+ register :pluralize, Fixnum, String, [String, 1]
22
+
23
+ def pluralize(count, singular, plural = nil)
24
+ if (count == 1 || count =~ /^1(\.0+)?$/)
25
+ singular
26
+ else
27
+ plural || singular.pluralize(I18n.locale)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module Scribble
2
+ module Methods
3
+ class QueryParameterValue < Method
4
+ register :query_parameter_value
5
+
6
+ def query_parameter_value
7
+ CGI::escape_html @receiver.variables[:params].fetch(:q, nil).to_s
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ module Scribble
2
+ module Methods
3
+ class Script < Method
4
+ register :script, String
5
+
6
+ def script(asset_name)
7
+ "<script src='#{url(asset_name)}'></script>"
8
+ end
9
+
10
+ private
11
+
12
+ def url(asset_name)
13
+ template = custom_templates.find_by!(name: "#{asset_name}.js")
14
+
15
+ school.routes.url_helpers.custom_asset_url(
16
+ school.uuid,
17
+ "#{asset_name}-#{template.fingerprint}.js",
18
+ options
19
+ )
20
+ end
21
+
22
+ def school
23
+ @receiver.variables[:current_school]
24
+ end
25
+
26
+ def custom_templates
27
+ @receiver.variables[:custom_templates]
28
+ end
29
+
30
+ def asset_host
31
+ @receiver.variables[:asset_host]
32
+ end
33
+
34
+ def asset_host_port
35
+ @receiver.variables[:asset_host_port]
36
+ end
37
+
38
+ def options
39
+ { port: asset_host_port, protocol: false }.tap do |h|
40
+ h[:host] = asset_host if asset_host
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ require "i18n"
2
+
3
+ module Scribble
4
+ module Methods
5
+ class T < Method
6
+ register :t, String
7
+
8
+ def t key
9
+ if key[0] == '.'
10
+ key = "custom_templates.#{ template_name }#{ key }"
11
+ end
12
+
13
+ I18n.translate(key)
14
+ end
15
+
16
+ def template_name
17
+ name = (
18
+ @context.variables[:template_name] ||
19
+ @receiver.variables[:template_name]
20
+ )
21
+ name.split(".").first
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,132 @@
1
+ require "webrick"
2
+ require "schoolkeep"
3
+ require "schoolkeep/template"
4
+ require "schoolkeep/fixture"
5
+ require "schoolkeep/views/layout"
6
+ require "schoolkeep/views/color_scheme"
7
+
8
+ module Schoolkeep
9
+ class Server
10
+ attr_reader :templates_path, :port, :quiet
11
+
12
+ def initialize(dir: ".", port: 4000, quiet: false, asset_host: ASSET_HOST)
13
+ @templates_path = File.join(dir, "templates")
14
+ Template.path = templates_path
15
+ fixture_path = File.join(dir, "config/fixtures.yml")
16
+ unless File.exist?(fixture_path)
17
+ fixture_path = File.join(dir,"fixtures.yml")
18
+ end
19
+ Fixture.default_path = fixture_path
20
+ Views::Layout.asset_host = asset_host
21
+ @port = port
22
+ @quiet = quiet
23
+
24
+ webrick.mount_proc "/color_scheme.css" do |req, res|
25
+ res["content-type"] = "text/css"
26
+ res.body = Views::ColorScheme.new("color_scheme").render
27
+ end
28
+
29
+ webrick.mount_proc "/learning_color_scheme.css" do |req, res|
30
+ res["content-type"] = "text/css"
31
+ res.body = Views::ColorScheme.new("learning_color_scheme").render
32
+ end
33
+
34
+ webrick.mount_proc "/catalog/" do |req, res|
35
+ id = req.path.split("/")[2]
36
+ if id
37
+ template = Template.new("course_details.html.sktl")
38
+
39
+ res["content-type"] = template.type
40
+ res.body = Views::Layout.new(template).render(variables: { "course" => id.to_sym })
41
+ else
42
+ template = Template.new("course_index.html.sktl")
43
+
44
+ res["content-type"] = template.type
45
+ res.body = Views::Layout.new(template).render
46
+ end
47
+ end
48
+
49
+ webrick.mount_proc "/syllabus/" do |req, res|
50
+ id = req.path.split("/")[2]
51
+ template = Template.new("course_cover.html.sktl")
52
+
53
+ res["content-type"] = template.type
54
+ res.body = Views::Layout.new(template).render(variables: { "course" => id.to_sym })
55
+ end
56
+
57
+ webrick.mount_proc "/outline/" do |req, res|
58
+ id = req.path.split("/")[2]
59
+
60
+ template = Template.new("course_cover.html.sktl")
61
+ res["content-type"] = template.type
62
+ res.body = Views::Layout.new(template).render(variables: {
63
+ "course" => id.to_sym
64
+ })
65
+ end
66
+ end
67
+
68
+ def start
69
+ webrick.start
70
+ end
71
+
72
+ def shutdown
73
+ webrick.shutdown
74
+ end
75
+
76
+ private
77
+
78
+ def webrick
79
+ @webrick ||= WEBrick::HTTPServer.new config
80
+ end
81
+
82
+ def config
83
+ {
84
+ Port: port,
85
+ DocumentRoot: templates_path,
86
+ DocumentRootOptions: {
87
+ FancyIndexing: true,
88
+ HandlerTable: { "sktl" => SKTLHandler },
89
+ NondisclosureName: ["_*"]
90
+ }
91
+ }.tap do |c|
92
+ if quiet
93
+ c.merge!(
94
+ :AccessLog => [],
95
+ :Logger => WEBrick::Log::new(File::NULL, 7)
96
+ )
97
+ end
98
+ end
99
+ end
100
+
101
+ class SKTLHandler < WEBrick::HTTPServlet::AbstractServlet
102
+ def initialize(server, name)
103
+ super(server, name)
104
+ @script_filename = name
105
+ end
106
+
107
+ def do_GET(req, res)
108
+ begin
109
+ name = File.basename(@script_filename)
110
+ template = Template.new(name)
111
+ res["content-type"] = template.type
112
+
113
+ if template.type == Template::HTML_MIME
114
+ res.body = Views::Layout.new(template).render
115
+ else
116
+ res.body = template.render
117
+ end
118
+ rescue StandardError
119
+ raise
120
+ rescue Exception => ex
121
+ @logger.error(ex)
122
+ raise HTTPStatus::InternalServerError, ex.message
123
+ end
124
+ end
125
+
126
+ ##
127
+ # Handles POST requests
128
+
129
+ alias do_POST do_GET
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,67 @@
1
+ require "i18n"
2
+ require "scribble"
3
+ require "schoolkeep"
4
+ require "schoolkeep/fixture"
5
+
6
+ module Schoolkeep
7
+ I18n.load_path << File.join(GEM_ROOT, "config/locale.yml")
8
+
9
+ class Template
10
+ CSS_MIME = "text/css"
11
+ HTML_MIME = "text/html"
12
+
13
+ class << self
14
+ attr_accessor :path
15
+ end
16
+
17
+ attr_reader :name
18
+
19
+ def initialize(name)
20
+ @name = name
21
+ @partial_loader = PartialLoader.new(self.class.path)
22
+ end
23
+
24
+ def source
25
+ @source ||= File.read(
26
+ File.join(self.class.path, name)
27
+ )
28
+ end
29
+
30
+ def render(variables: {})
31
+ template.render(
32
+ variables: Fixture.for(name, overrides: variables)
33
+ )
34
+ end
35
+
36
+ def type
37
+ @type ||= case name
38
+ when /\.css\.sktl$/
39
+ CSS_MIME
40
+ when /\.html\.sktl$/
41
+ HTML_MIME
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def template
48
+ @template ||= ::Scribble::Template.new(
49
+ source,
50
+ loader: @partial_loader
51
+ )
52
+ end
53
+
54
+ class PartialLoader
55
+ attr_reader :path
56
+ def initialize(path)
57
+ @path = path
58
+ end
59
+
60
+ def load(name)
61
+ name = "_#{name}.html.sktl"
62
+ partial_path = File.join(path, name)
63
+ ::Scribble::Partial.new File.read(partial_path)
64
+ end
65
+ end
66
+ end
67
+ end