ruql-html 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 609d2fd3609ed8e40a791c88a23617e4a49e9dd1cf7b5ee6125f200fab5c33fb
4
+ data.tar.gz: 077f63c28b10ad3003b9e1b56f7553db001e782ffd425cc511507b4b484ea045
5
+ SHA512:
6
+ metadata.gz: 30148cdcda674a872e46ec12e4fd6ffd707ca286faa663e7e809b79d66dd347946672b4917c7b5ea6ec5a74a0cea1e00b21d51e3573cd0dfd7bd842ab1f819f0
7
+ data.tar.gz: 2e7017afa3eed0f302b42acfb78c22dd187807ecbde09ab91e4736df162b811735bfa811637984156a78ea8d355517302b01df1015970b3d77400d83727e7c7b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at fox@cs.berkeley.edu. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ruql-html.gemspec
6
+ gemspec
@@ -0,0 +1,40 @@
1
+ # Ruql::Html
2
+
3
+ This formatter requires [ruql](https://github.com/saasbook/ruql) and
4
+ allows formatting RuQL quizzes as HTML.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ruql-html'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ruql-html
21
+
22
+ ## Usage
23
+
24
+ The simplest usage is `ruql html quizfile.rb > output.html`.
25
+ `ruql html -h` shows options that let you specify a different HTML/CSS
26
+ template, among other things.
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruql-html. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## Code of Conduct
39
+
40
+ Everyone interacting in the Ruql::Html project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ruql-html/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruql/html"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "ruql/html/version"
2
+ require "ruql/html/html"
3
+
@@ -0,0 +1,184 @@
1
+ module Ruql
2
+ class Html
3
+ require 'builder'
4
+ require 'erb'
5
+
6
+ attr_reader :output
7
+
8
+ def initialize(quiz,options={})
9
+ @gem_root = Gem.loaded_specs['ruql-html'].full_gem_path rescue '.'
10
+ @show_solutions = options.delete('--solutions')
11
+ @show_tags = options.delete('--html-tags') || options.delete('--show-tags')
12
+ @template = options.delete('--html-template') ||
13
+ File.join(@gem_root, 'templates/simple.html.erb')
14
+ @output = ''
15
+ @quiz = quiz
16
+ @h = Builder::XmlMarkup.new(:target => @output, :indent => 2)
17
+ end
18
+
19
+ def self.allowed_options
20
+ opts = [
21
+ ['--html-tags', GetoptLong::NO_ARGUMENT],
22
+ ['--html-template', GetoptLong::REQUIRED_ARGUMENT]
23
+ ]
24
+ help = <<eos
25
+ The HTML renderer uses supports these options:
26
+ --html-tags
27
+ Show question's tags in HTML output, within an element <div class="tags">.
28
+ --html-template=file.html.erb
29
+ Use file.html.erb as HTML template, which has <%= yield %> where questions should go.
30
+ Default is #{@gem_root}/templates/simple.html.erb
31
+ You can use the local variables in the .erb template:
32
+ <%= quiz.title %> - the quiz title
33
+ <%= quiz.num_questions %> - total number of questions
34
+ <%= quiz.points %> - total number of points for whole quiz
35
+ NOTE: If there is more than one quiz (collection of questions) in the file,
36
+ a complete <html>...</html> block is produced in the output for EACH quiz.
37
+ eos
38
+ return [help, opts]
39
+ end
40
+
41
+ def render_quiz
42
+ render_with_template do
43
+ render_questions
44
+ @output
45
+ end
46
+ self
47
+ end
48
+
49
+ def render_with_template
50
+ # local variables that should be in scope in the template
51
+ quiz = @quiz
52
+ # the ERB template includes 'yield' where questions should go:
53
+ output = ERB.new(IO.read(File.expand_path @template)).result(binding)
54
+ @output = output
55
+ end
56
+
57
+ # this is what's called when the HTML template yields:
58
+ def render_questions
59
+ render_random_seed
60
+ @h.ol :class => 'questions' do
61
+ @quiz.questions.each_with_index do |q,i|
62
+ case q
63
+ when MultipleChoice, SelectMultiple, TrueFalse then render_multiple_choice(q,i)
64
+ when FillIn then render_fill_in(q, i)
65
+ else
66
+ raise Ruql::QuizContentError.new "Unknown question type: #{q}"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+
73
+ def render_multiple_choice(q,index)
74
+ render_question_text(q, index) do
75
+ answers =
76
+ if q.class == TrueFalse then q.answers.sort.reverse # True always first
77
+ elsif q.randomize then q.answers.sort_by { rand }
78
+ else q.answers
79
+ end
80
+ @h.ol :class => 'answers' do
81
+ answers.each do |answer|
82
+ if @show_solutions
83
+ render_answer_for_solutions(answer, q.raw?, q.class == TrueFalse)
84
+ else
85
+ if q.raw? then @h.li { |l| l << answer.answer_text } else @h.li answer.answer_text end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ self
91
+ end
92
+
93
+ def render_fill_in(q, idx)
94
+ render_question_text(q, idx) do
95
+ if @show_solutions
96
+ answer = q.answers[0]
97
+ if answer.has_explanation?
98
+ if q.raw? then @h.p(:class => 'explanation') { |p| p << answer.explanation }
99
+ else @h.p(answer.explanation, :class => 'explanation') end
100
+ end
101
+ answers = (answer.answer_text.kind_of?(Array) ? answer.answer_text : [answer.answer_text])
102
+ @h.ol :class => 'answers' do
103
+ answers.each do |answer|
104
+ if answer.kind_of?(Regexp)
105
+ answer = answer.inspect
106
+ if !q.case_sensitive
107
+ answer += 'i'
108
+ end
109
+ end
110
+ @h.li do
111
+ if q.raw? then @h.p { |p| p << answer } else @h.p answer end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ def render_answer_for_solutions(answer,raw,is_true_false = nil)
120
+ args = {:class => (answer.correct? ? 'correct' : 'incorrect')}
121
+ if is_true_false
122
+ answer.answer_text.prepend(
123
+ answer.correct? ? "CORRECT: " : "INCORRECT: ")
124
+ end
125
+ @h.li(args) do
126
+ if raw then @h.p { |p| p << answer.answer_text } else @h.p answer.answer_text end
127
+ if answer.has_explanation?
128
+ if raw then @h.p(:class => 'explanation') { |p| p << answer.explanation }
129
+ else @h.p(answer.explanation, :class => 'explanation') end
130
+ end
131
+ end
132
+ end
133
+
134
+ def render_question_text(question,index)
135
+ html_args = {
136
+ :id => "question-#{index}",
137
+ :class => ['question', question.class.to_s.downcase, (question.multiple ? 'multiple' : '')]
138
+ .join(' ')
139
+ }
140
+ @h.li html_args do
141
+ @h.div :class => 'text' do
142
+ qtext = "[#{question.points} point#{'s' if question.points>1}] " <<
143
+ ('Select ALL that apply: ' if question.multiple).to_s <<
144
+ if question.class == FillIn then question.question_text.gsub(/\-+/, '_____________________________')
145
+ else question.question_text
146
+ end
147
+ if @show_tags
148
+ @h.div(:class => 'text') do
149
+ question.tags.join(',')
150
+ end
151
+ end
152
+ if question.raw?
153
+ @h.p { |p| p << qtext }
154
+ else
155
+ qtext.each_line do |p|
156
+ @h.p do |par|
157
+ par << p # preserves HTML markup
158
+ end
159
+ end
160
+ end
161
+ end
162
+ yield # render answers
163
+ end
164
+ self
165
+ end
166
+
167
+ def quiz_header
168
+ @h.div(:id => 'student-name') do
169
+ @h.p 'Name:'
170
+ @h.p 'Student ID:'
171
+ end
172
+ if @quiz.options[:instructions]
173
+ @h.div :id => 'instructions' do
174
+ @quiz.options[:instructions].each_line { |p| @h.p p }
175
+ end
176
+ end
177
+ self
178
+ end
179
+
180
+ def render_random_seed
181
+ @h.comment! "Seed: #{@quiz.seed}"
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,5 @@
1
+ module Ruql
2
+ class Html
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ruql/html/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruql-html"
8
+ spec.version = Ruql::Html::VERSION
9
+ spec.authors = ["Armando Fox"]
10
+ spec.email = ["fox@cs.berkeley.edu"]
11
+
12
+ spec.summary = "HTML 5 renderer for RuQL"
13
+ spec.description = "HTML 5 renderer for RuQL"
14
+ spec.authors = ["Armando Fox"]
15
+ spec.email = 'fox@berkeley.edu'
16
+ spec.homepage = 'https://github.com/saasbook/ruql-html'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = spec.homepage
25
+ #spec.metadata["changelog_uri"] = ''
26
+ else
27
+ raise "RubyGems 2.0 or newer is required to protect against " \
28
+ "public gem pushes."
29
+ end
30
+ spec.add_runtime_dependency 'builder', '~> 3.0'
31
+
32
+ # Specify which files should be added to the gem when it is released.
33
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
35
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
36
+ end
37
+ spec.bindir = "exe"
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ["lib"]
40
+
41
+ spec.add_development_dependency "bundler", "~> 1.17"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ end
45
+
@@ -0,0 +1,32 @@
1
+ <html>
2
+ <head>
3
+ <title><%= quiz.title %></title>
4
+ <style type="text/css" media="all">
5
+ body { font-family: Times, serif; }
6
+ .header { text-align: right; font-weight: bold; padding-right: 30%; line-height: 300%; }
7
+ h1 { text-align: center; }
8
+ ol.questions { list-style-type: number; }
9
+ li.question { page-break-inside: avoid; border-bottom: 1px solid grey; }
10
+ li.question .tags { font-weight: bold; background-color: yellow; display: block; margin: 2px; padding: 2px; }
11
+ li.multiplechoice ol.answers { list-style-type: lower-alpha; }
12
+ li.selectmultiple ol.answers { vertical-align: center; list-style-type: none; list-style-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUAQMAAAC3R49OAAAABlBMVEUAAAD///+l2Z/dAAAAEklEQVQImWNgAIL6/w+ogoEAAKI4Kp2NVIeDAAAAAElFTkSuQmCC'); }
13
+ li.truefalse ol.answers { list-style-type: none; }
14
+ .correct { color: green; font-weight: bold; border: 1px solid black; padding: 0.2ex; }
15
+ .incorrect { color: red }
16
+ .explanation { font-style: italic }
17
+ .instructions { clear: both; border: 1px solid black; align: center; padding: 2ex; margin: 2ex; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div class="header">
22
+ <div id="name">Name:</div>
23
+ <div id="sid">Student ID:</div>
24
+ </div>
25
+ <h1><%= quiz.title %></h1>
26
+ <div align="center">
27
+ <%= quiz.num_questions %> questions, points indicated per question,
28
+ <%= quiz.points %> points total.
29
+ </div>
30
+ <%= yield %>
31
+ </body>
32
+ </html>
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruql-html
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Armando Fox
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: HTML 5 renderer for RuQL
70
+ email: fox@berkeley.edu
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/ruql/html.rb
85
+ - lib/ruql/html/html.rb
86
+ - lib/ruql/html/version.rb
87
+ - ruql-html.gemspec
88
+ - templates/simple.html.erb
89
+ homepage: https://github.com/saasbook/ruql-html
90
+ licenses: []
91
+ metadata:
92
+ allowed_push_host: https://rubygems.org
93
+ homepage_uri: https://github.com/saasbook/ruql-html
94
+ source_code_uri: https://github.com/saasbook/ruql-html
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.0.8
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: HTML 5 renderer for RuQL
114
+ test_files: []