farma_keyboard_rails 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/farma_keyboard_rails_initializer.js +7 -0
- data/app/assets/javascripts/farma_keyboard_rails_main.js +2 -0
- data/app/assets/javascripts/keyboard/keyboard.class.coffee +113 -0
- data/app/assets/javascripts/keyboard/keys.class.coffee +80 -0
- data/app/assets/javascripts/keyboard/lib/hbs.class.coffee.erb +62 -0
- data/app/assets/javascripts/keyboard/mathjax/config/mathjax_config.js +10 -0
- data/app/assets/javascripts/keyboard/screen.class.coffee +74 -0
- data/app/assets/javascripts/keyboard/validator.coffee +21 -0
- data/app/assets/javascripts/templates/formulas.hbs +12 -0
- data/app/assets/javascripts/templates/keyboard.hbs +62 -0
- data/app/assets/javascripts/templates/partials/_advanced.hbs +1 -0
- data/app/assets/javascripts/templates/partials/_element.hbs +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/farma_keyboard_rails.gemspec +39 -0
- data/lib/farma_keyboard_rails.rb +6 -0
- data/lib/farma_keyboard_rails/engine.rb +7 -0
- data/lib/farma_keyboard_rails/version.rb +3 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc91284b9475a2962acbe31e20cde874dfb625ff
|
4
|
+
data.tar.gz: da1b042757dfc5c29056265c5f2f269faf840b02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c29b5a5ee17a593db28abba645648b39b4d13c37b8f788fd0a643224f0b5dc00ce9e55b25f733f7552d2cef67d84fdf97c2a5a97777fd1a73f4e6fb031e6280
|
7
|
+
data.tar.gz: 86c4b35b73ff8abd0e01e0999ca3caca39a13483495401ae362fd140d46a1cf1684aa22fb75995c597d2a53f3d05a97412c44c4740f691d2ef314d060a1a9914
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 gzmarques90@gmail.com. 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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Guilherme Zacalusni Marques
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# FarmaKeyboardRails
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/farma_keyboard_rails`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'farma_keyboard_rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install farma_keyboard_rails
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gzmarques/farma_keyboard_rails. 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.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#= require_tree ../templates
|
2
|
+
class window.FARMA.Keyboard
|
3
|
+
|
4
|
+
@preLoad: (id) ->
|
5
|
+
obj = $(document).find("#keyboard-panel-#{id}")
|
6
|
+
if obj.hasClass("keyboard-active")
|
7
|
+
$("#keyboard-#{id}").show()
|
8
|
+
else
|
9
|
+
new window.FARMA.Keyboard(id)
|
10
|
+
|
11
|
+
constructor: (id) ->
|
12
|
+
self = $("#keyboard-panel-#{id}")
|
13
|
+
@id = id
|
14
|
+
@screen = new window.FARMA.Screen()
|
15
|
+
# @hbs = new window.FARMA.Hbs()
|
16
|
+
@tries = self.data("tries")
|
17
|
+
|
18
|
+
Handlebars.registerHelper 'log', (context) ->
|
19
|
+
console.log context
|
20
|
+
|
21
|
+
keyboard = HandlebarsTemplates['keyboard']({
|
22
|
+
id: id
|
23
|
+
tries: @tries
|
24
|
+
operators: window.FARMA.Keys.operators()
|
25
|
+
keys: window.FARMA.Keys.keys()
|
26
|
+
specialKeys: window.FARMA.Keys.specialKeys()
|
27
|
+
functions: window.FARMA.Keys.functions()
|
28
|
+
matrix: window.FARMA.Keys.matrix()
|
29
|
+
trig: window.FARMA.Keys.trig()
|
30
|
+
})
|
31
|
+
|
32
|
+
self.html keyboard
|
33
|
+
self.addClass("keyboard-active")
|
34
|
+
self.show()
|
35
|
+
@clickHandler()
|
36
|
+
@hotKeyHandler()
|
37
|
+
# @checkAnswer()
|
38
|
+
@onSubmit()
|
39
|
+
|
40
|
+
clickHandler: ->
|
41
|
+
id = @id
|
42
|
+
self = @screen
|
43
|
+
|
44
|
+
$(document).on 'click', "#keyboard-#{id} .key", (e) ->
|
45
|
+
if $(@).attr('data-value') != 'send'
|
46
|
+
self.addToJax($(@).text(), $(@).attr("data-value"), id)
|
47
|
+
if $(@).attr('data-value') == 'C'
|
48
|
+
self.cleanScreen(id)
|
49
|
+
|
50
|
+
$(document).on 'click', '#special-keys ul li', ->
|
51
|
+
$('#special-keys ul li').removeClass('active');
|
52
|
+
$(@).addClass('active')
|
53
|
+
$('#advanced-keys div').hide();
|
54
|
+
show_id = "#" + $(@).data('id')
|
55
|
+
$(show_id).show()
|
56
|
+
|
57
|
+
thisKB = @
|
58
|
+
$(document).on 'click', "#keyboard-panel-#{id} #show-direct-input", ->
|
59
|
+
editor = $("#keyboard-panel-#{id} .direct-input")
|
60
|
+
editor.toggleClass('hide')
|
61
|
+
$("#keyboard-#{id}").toggleClass('make-tall')
|
62
|
+
unless editor.hasClass('active')
|
63
|
+
thisKB.renderEditor()
|
64
|
+
editor.addClass('active')
|
65
|
+
|
66
|
+
onSubmit: (editor) ->
|
67
|
+
id = @id
|
68
|
+
self = @screen
|
69
|
+
|
70
|
+
$("#keyboard-#{id} button[type='submit']").on 'click', ->
|
71
|
+
if editor
|
72
|
+
editor.toTextArea()
|
73
|
+
|
74
|
+
$("#keyboard-#{id}").hide()
|
75
|
+
# $("#question_#{id}_response").attr("data-storage", $("#keyboard-#{id}-screen").val())
|
76
|
+
# $("#question_#{id}_response").val($("#keyboard-#{id}-screen").val())
|
77
|
+
$("#question-#{id}-show .box-response").show()
|
78
|
+
|
79
|
+
response_container = $("#keyboard-panel-#{id}").data('response-container')
|
80
|
+
$.post
|
81
|
+
url: $("#keyboard-panel-#{id}").data('bucket')
|
82
|
+
data: {
|
83
|
+
answer: {
|
84
|
+
response: $("#keyboard-#{id}-screen").val()
|
85
|
+
}
|
86
|
+
}
|
87
|
+
dataType: "json",
|
88
|
+
success: (data) ->
|
89
|
+
$(response_container).html(data.response)
|
90
|
+
$(response_container).removeClass('invalid').removeClass('valid');
|
91
|
+
cssClass = if data.correct_answer then 'valid' else 'invalid'
|
92
|
+
$(response_container).addClass(cssClass);
|
93
|
+
|
94
|
+
hotKeyHandler: ->
|
95
|
+
self = @screen
|
96
|
+
id = @id
|
97
|
+
$(document).on 'keydown', "#keyboard-#{id}-screen", (e) ->
|
98
|
+
unless e.key.length != 1
|
99
|
+
switch e.key
|
100
|
+
when 'Backspace' then console.log 'backspace'
|
101
|
+
when 'C' then self.cleanScreen(id)
|
102
|
+
else self.addToJax(e.key, e.key, id)
|
103
|
+
|
104
|
+
renderEditor: ->
|
105
|
+
editor = CodeMirror.fromTextArea(document.getElementById("keyboard-#{@id}-screen"), {
|
106
|
+
height: "150px",
|
107
|
+
parserfile: "stex.js",
|
108
|
+
path: "codemirror/js/",
|
109
|
+
textWrapping: true,
|
110
|
+
lineNumbers: true,
|
111
|
+
theme: "material"
|
112
|
+
})
|
113
|
+
@onSubmit(editor)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class window.FARMA.Keys
|
2
|
+
|
3
|
+
@operators: ->
|
4
|
+
[
|
5
|
+
{ key: "÷", value: "\\over", type: "operator" },
|
6
|
+
{ key: "x", value: "*", type: "operator" },
|
7
|
+
{ key: "-", value: "-", type: "operator" },
|
8
|
+
{ key: "+", value: "+", type: "operator" }
|
9
|
+
]
|
10
|
+
|
11
|
+
@keys: ->
|
12
|
+
[
|
13
|
+
{ key: 1, value: 1, type: "key" },
|
14
|
+
{ key: 2, value: 2, type: "key" },
|
15
|
+
{ key: 3, value: 3, type: "key" },
|
16
|
+
|
17
|
+
# { key: "", value: "", type: "special mdi mdi-sigma" },
|
18
|
+
{ key: 4, value: 4, type: "key" },
|
19
|
+
{ key: 5, value: 5, type: "key" },
|
20
|
+
{ key: 6, value: 6, type: "key" },
|
21
|
+
|
22
|
+
# { key: "", value: "", type: "special mdi mdi-function" },
|
23
|
+
{ key: 7, value: 7, type: "key" },
|
24
|
+
{ key: 8, value: 8, type: "key" },
|
25
|
+
{ key: 9, value: 9, type: "key" },
|
26
|
+
|
27
|
+
# { key: "", value: "", type: "special mdi mdi-flask-outline" },
|
28
|
+
{ key: ".", value: ".", type: "key" },
|
29
|
+
{ key: 0, value: 0, type: "key" },
|
30
|
+
{ key: "=", value: "=", type: "key" }
|
31
|
+
# { key: "", value: "\\left[\\begin{matrix}\\end{matrix}\\right]", type: "special mdi mdi-matrix" },
|
32
|
+
]
|
33
|
+
|
34
|
+
@specialKeys: ->
|
35
|
+
[
|
36
|
+
{ key: "√", value: "\\sqrt{}", type: "key" },
|
37
|
+
{ key: "(", value: "{", type: "key" },
|
38
|
+
{ key: ")", value: "}", type: "key" },
|
39
|
+
{ key: "", value: "", type: "eval mdi mdi-desktop-mac tooltipped", options: "data-tooltip=Renderizar TeX data-delay=50 data-position=bottom" },
|
40
|
+
# { key: "", value: "check", type: "eval mdi mdi-account-check" }
|
41
|
+
# { key: "", value: "\\left[\\begin{matrix}\\end{matrix}\\right]", type: "operator mdi mdi-matrix" },
|
42
|
+
# { key: "&", value: "&", type: "key" },
|
43
|
+
# { key: "𝑥²", value: "^2", type: "key" },
|
44
|
+
# { key: "%", value: "*100", type: "key" },
|
45
|
+
# { key: "", value: "\\\\", type: "operator mdi mdi-keyboard-return" }
|
46
|
+
]
|
47
|
+
|
48
|
+
@functions: ->
|
49
|
+
[
|
50
|
+
{ key: "√", value: "\\sqrt{}", type: "key" },
|
51
|
+
{ key: "ϰ^y^", value: "{", type: "key" },
|
52
|
+
{ key: "1/ϰ", value: "{", type: "key" },
|
53
|
+
{ key: "y√ϰ", value: "{", type: "key" },
|
54
|
+
{ key: "x/y", value: "{", type: "key" },
|
55
|
+
{ key: "ln(ϰ)", value: "{", type: "key" },
|
56
|
+
{ key: "e^ϰ^", value: "{", type: "key" },
|
57
|
+
{ key: "log(ϰ)", value: "{", type: "key" },
|
58
|
+
{ key: "n!", value: "{", type: "key" },
|
59
|
+
{ key: "|ϰ|", value: "}", type: "key" }
|
60
|
+
]
|
61
|
+
|
62
|
+
@matrix: ->
|
63
|
+
[
|
64
|
+
{ key: "", value: "\\left[\\begin{matrix}\n\t\n\\end{matrix}\\right]", type: "operator mdi mdi-matrix" },
|
65
|
+
{ key: "&", value: "&", type: "key" },
|
66
|
+
{ key: "", value: "\\\\\n\t", type: "operator mdi mdi-keyboard-return" }
|
67
|
+
]
|
68
|
+
|
69
|
+
@trig: ->
|
70
|
+
[
|
71
|
+
{ key: "sin(ϰ)", value: "\\sin", type: "key" },
|
72
|
+
{ key: "sin-¹(ϰ)", value: "\\arcsin", type: "key" },
|
73
|
+
{ key: "π", value: "π", type: "key" },
|
74
|
+
{ key: "cos(ϰ)", value: "\\cos", type: "key" },
|
75
|
+
{ key: "cos-¹(ϰ)", value: "\\arccos", type: "key" },
|
76
|
+
{ key: "θ", value: "θ", type: "key" },
|
77
|
+
{ key: "tan(ϰ)", value: "\\tan", type: "key" },
|
78
|
+
{ key: "tan-¹(ϰ)", value: "\\arctan", type: "key" },
|
79
|
+
{ key: "α", value: "α", type: "key" }
|
80
|
+
]
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<%
|
2
|
+
@partial_path = '/assets/lib/keyboard/views/partials'
|
3
|
+
@template_path = '/assets/lib/keyboard/views/templates'
|
4
|
+
|
5
|
+
def asset_partial(file)
|
6
|
+
asset_file(file, @partial_path, 'partial')
|
7
|
+
end
|
8
|
+
|
9
|
+
def asset_template(file)
|
10
|
+
asset_file(file, @template_path, 'hbs')
|
11
|
+
end
|
12
|
+
|
13
|
+
def asset_file(file, path, extension)
|
14
|
+
return file unless Rails.env.production?
|
15
|
+
p = path.gsub('/assets/', '')
|
16
|
+
f = "#{p}/#{file}.#{extension}"
|
17
|
+
asset = asset_path(f)
|
18
|
+
asset.gsub!("#{path}/", '')
|
19
|
+
asset.gsub(".#{extension}", '')
|
20
|
+
end
|
21
|
+
%>
|
22
|
+
|
23
|
+
class window.FARMA.Hbs
|
24
|
+
|
25
|
+
constructor: ->
|
26
|
+
$.handlebars(@options)
|
27
|
+
@changeIncludePartial()
|
28
|
+
|
29
|
+
options:
|
30
|
+
templateExtension: 'hbs'
|
31
|
+
partialPath: '<%= @partial_path %>'
|
32
|
+
templatePath: '<%= @template_path %>'
|
33
|
+
partials:
|
34
|
+
[
|
35
|
+
"<%= asset_partial('element') %>"
|
36
|
+
"<%= asset_partial('advanced') %>"
|
37
|
+
]
|
38
|
+
|
39
|
+
render: (template) ->
|
40
|
+
templates =
|
41
|
+
keyboard: "<%= asset_template('keyboard') %>"
|
42
|
+
formulas: "<%= asset_template('formulas') %>"
|
43
|
+
|
44
|
+
templates[template]
|
45
|
+
|
46
|
+
partialMap: (partial) ->
|
47
|
+
partials =
|
48
|
+
element: "<%= asset_partial('element') %>",
|
49
|
+
advanced: "<%= asset_partial('advanced') %>"
|
50
|
+
|
51
|
+
partials[partial]
|
52
|
+
|
53
|
+
changeIncludePartial: ->
|
54
|
+
map = @partialMap
|
55
|
+
Handlebars.registerHelper 'render', (templateName, options) ->
|
56
|
+
templateName = map(templateName)
|
57
|
+
partial = Handlebars.partials[templateName]
|
58
|
+
if (typeof partial is "string")
|
59
|
+
partial = Handlebars.compile(partial)
|
60
|
+
Handlebars.partials[templateName] = partial
|
61
|
+
context = $.extend({}, this, options.hash)
|
62
|
+
new Handlebars.SafeString partial(context)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class window.FARMA.Screen
|
2
|
+
|
3
|
+
decimalAdded: false
|
4
|
+
equation: 0
|
5
|
+
matrix: 0
|
6
|
+
cursorIndex: 0
|
7
|
+
|
8
|
+
construct: () ->
|
9
|
+
|
10
|
+
addToJax: (key, what, where) ->
|
11
|
+
newTex = @expressionMerge(@getScreenTex(where), what)
|
12
|
+
newValue = @getResponseValue(where) + key
|
13
|
+
if window.FARMA.Validator.isNumeric(newTex)
|
14
|
+
@switchClass(where, true)
|
15
|
+
else
|
16
|
+
@switchClass(where, false)
|
17
|
+
@updateInputsWith(newValue, newTex, where)
|
18
|
+
@renderTex(newTex, where)
|
19
|
+
|
20
|
+
getScreenTex: (where) ->
|
21
|
+
$("#keyboard-#{where}-screen").val()
|
22
|
+
|
23
|
+
getResponseValue: (where) ->
|
24
|
+
$("#keyboard-panel-#{where}").attr("data-storage")
|
25
|
+
|
26
|
+
cleanScreen: (id) ->
|
27
|
+
@updateInputsWith("", "", id)
|
28
|
+
@renderTex("", id)
|
29
|
+
$("#keyboard-#{id} .jax").removeClass('valid-expression')
|
30
|
+
$("#keyboard-#{id} .jax").removeClass('invalid-expression')
|
31
|
+
$("#keyboard-#{id}-screen").removeClass('invalid-expression')
|
32
|
+
$("#keyboard-#{id}-screen").removeClass('valid-expression')
|
33
|
+
|
34
|
+
chop: (id) ->
|
35
|
+
actual = @getScreenTex(id)
|
36
|
+
return actual.slice(0, (actual.length - 1))
|
37
|
+
|
38
|
+
renderTex: (expression, where) ->
|
39
|
+
MathJax.Hub.Queue(["Typeset", MathJax.Hub])
|
40
|
+
tex = MathJax.Hub.getAllJax("MathOutput-#{where}")[0]
|
41
|
+
MathJax.Hub.queue.Push [
|
42
|
+
'Text'
|
43
|
+
tex
|
44
|
+
'\\displaystyle{' + expression + '}'
|
45
|
+
]
|
46
|
+
|
47
|
+
expressionMerge: (oldValue, newValue) ->
|
48
|
+
if @recognizeMatrix(oldValue)
|
49
|
+
return oldValue.split("\n\\end{matrix}").join("#{newValue}\n\\end{matrix}")
|
50
|
+
if @recognizeBrackets(oldValue)
|
51
|
+
return oldValue.replace "}", newValue + "}"
|
52
|
+
oldValue + newValue
|
53
|
+
|
54
|
+
recognizeMatrix: (expression) ->
|
55
|
+
findMatrix = ///\{matrix\}///
|
56
|
+
(expression.match findMatrix)?
|
57
|
+
|
58
|
+
recognizeBrackets: (expression) ->
|
59
|
+
findBrackets = ///\}$///
|
60
|
+
(expression.match findBrackets)?
|
61
|
+
|
62
|
+
updateInputsWith: (newValue, newTex, where) ->
|
63
|
+
$("#keyboard-#{where}-screen").val(newTex)
|
64
|
+
# $("#keyboard-panel-#{where}").attr("data-storage", newValue)
|
65
|
+
if window.FARMA.Validator.isNumeric(newValue)
|
66
|
+
$("#response-#{where}").val(newValue)
|
67
|
+
|
68
|
+
switchClass: (where, state) ->
|
69
|
+
if (state)
|
70
|
+
$("#keyboard-#{where}-screen").addClass('valid-expression')
|
71
|
+
$("#keyboard-#{where}-screen").removeClass('invalid-expression')
|
72
|
+
else
|
73
|
+
$("#keyboard-#{where}-screen").addClass('invalid-expression')
|
74
|
+
$("#keyboard-#{where}-screen").removeClass('valid-expression')
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class window.FARMA.Validator
|
2
|
+
|
3
|
+
|
4
|
+
@isAlgebraic: (expression) ->
|
5
|
+
|
6
|
+
@isNumeric: (expression) ->
|
7
|
+
# regex = ///(\s*\d+\s*(\*|\/|\-|\+|\^|)\s*\d+\s*(\*|\/|\-|\+|\^|))+\s*///
|
8
|
+
regex = /(^[-]?)(\b(([\(]?(?:(?:(?:\d+\.)?\d+)[\)]?(?:\^|over|sqrt|\*|\/|\+|\-)?[\(]?)+\d)|\d{1})\b)$/gm
|
9
|
+
(expression.match regex)?
|
10
|
+
|
11
|
+
@isMatrix: (expression) ->
|
12
|
+
regex = ///\{matrix\}///
|
13
|
+
(expression.match regex)?
|
14
|
+
|
15
|
+
@isFunction: (expression) ->
|
16
|
+
regex = //////
|
17
|
+
(expression.match regex)?
|
18
|
+
|
19
|
+
@isFormula: (expression) ->
|
20
|
+
regex = //////
|
21
|
+
(expression.match regex)?
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<div id="keyboard-{{id}}" class="keyboard">
|
2
|
+
|
3
|
+
<div class="top">
|
4
|
+
<button type="button" class="btn key waves-effect waves-light clear" data-value="C">Limpar</button>
|
5
|
+
<div class="jax" id="MathOutput-{{id}}">$${}$$</div>
|
6
|
+
<button type="submit" class="btn key waves-effect waves-light submit" data-value="send">Enviar<i class="material-icons right">send</i></button>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="clearfix" id="board">
|
10
|
+
|
11
|
+
<div id="tries">{{tries}}</div>
|
12
|
+
|
13
|
+
<div class="keys" id="default-keys">
|
14
|
+
<div id="operators">
|
15
|
+
{{#each operators}}
|
16
|
+
{{> partials/_element }}
|
17
|
+
{{/each}}
|
18
|
+
</div>
|
19
|
+
<div id="keys">
|
20
|
+
{{#each keys}}
|
21
|
+
{{> partials/_element }}
|
22
|
+
{{/each}}
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div id="special-keys">
|
27
|
+
|
28
|
+
<div id="separator"></div>
|
29
|
+
|
30
|
+
<div class="modifiers">
|
31
|
+
<ul>
|
32
|
+
<li data-id="functions-keys">FUNÇÕES</li>
|
33
|
+
<li data-id="matrix-keys">MATRIZES</li>
|
34
|
+
<li data-id="trig-keys">TRIGONOMETRIA</li>
|
35
|
+
</ul>
|
36
|
+
<div id="advanced-keys">
|
37
|
+
<div id="functions-keys">
|
38
|
+
{{#each functions}}
|
39
|
+
{{> partials/_advanced}}
|
40
|
+
{{/each}}
|
41
|
+
</div>
|
42
|
+
<div id="matrix-keys" hidden>
|
43
|
+
{{#each matrix}}
|
44
|
+
{{> partials/_advanced}}
|
45
|
+
{{/each}}
|
46
|
+
</div>
|
47
|
+
<div id="trig-keys" hidden>
|
48
|
+
{{#each trig}}
|
49
|
+
{{> partials/_advanced}}
|
50
|
+
{{/each}}
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
</div>
|
57
|
+
|
58
|
+
<div id="show-direct-input"><></div>
|
59
|
+
|
60
|
+
<div class="direct-input hide">
|
61
|
+
<textarea id="keyboard-{{id}}-screen" class="screen" value="" placeholder="Fórmulas LaTeX"></textarea>
|
62
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<button type="button" class="btn key waves-effect waves-light {{this.type}} advanced" data-value="{{this.value}}">{{this.key}}</button>
|
@@ -0,0 +1 @@
|
|
1
|
+
<button type="button" class="btn key waves-effect waves-light {{this.type}}" {{this.options}} data-value="{{this.value}}">{{this.key}}</button>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "farma_keyboard_rails"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'farma_keyboard_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "farma_keyboard_rails"
|
8
|
+
spec.version = FarmaKeyboardRails::VERSION
|
9
|
+
spec.authors = ["Guilherme Zacalusni Marques"]
|
10
|
+
spec.email = ["gzmarques90@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "This gem is intended to create a js keyboard to make a MathJax interface for sending answers and stuff."
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/gzmarques/farma_keyboard_rails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
|
37
|
+
spec.add_dependency "mathjax-rails"
|
38
|
+
spec.add_dependency "handlebars_assets"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: farma_keyboard_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guilherme Zacalusni Marques
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mathjax-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: handlebars_assets
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- gzmarques90@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- app/assets/javascripts/farma_keyboard_rails_initializer.js
|
99
|
+
- app/assets/javascripts/farma_keyboard_rails_main.js
|
100
|
+
- app/assets/javascripts/keyboard/keyboard.class.coffee
|
101
|
+
- app/assets/javascripts/keyboard/keys.class.coffee
|
102
|
+
- app/assets/javascripts/keyboard/lib/hbs.class.coffee.erb
|
103
|
+
- app/assets/javascripts/keyboard/mathjax/config/mathjax_config.js
|
104
|
+
- app/assets/javascripts/keyboard/screen.class.coffee
|
105
|
+
- app/assets/javascripts/keyboard/validator.coffee
|
106
|
+
- app/assets/javascripts/templates/formulas.hbs
|
107
|
+
- app/assets/javascripts/templates/keyboard.hbs
|
108
|
+
- app/assets/javascripts/templates/partials/_advanced.hbs
|
109
|
+
- app/assets/javascripts/templates/partials/_element.hbs
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- farma_keyboard_rails.gemspec
|
113
|
+
- lib/farma_keyboard_rails.rb
|
114
|
+
- lib/farma_keyboard_rails/engine.rb
|
115
|
+
- lib/farma_keyboard_rails/version.rb
|
116
|
+
homepage: https://github.com/gzmarques/farma_keyboard_rails
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.6.8
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: This gem is intended to create a js keyboard to make a MathJax interface
|
140
|
+
for sending answers and stuff.
|
141
|
+
test_files: []
|