smalruby-editor 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481219ecbb11af4414b736a08666df8c1d4b2a98
4
- data.tar.gz: c0158c87c4892af0db1130770e55d3f8966f6a73
3
+ metadata.gz: 032387aebf20ab1d3322fee20c1c06c0f6715988
4
+ data.tar.gz: 185a9bd5170dbda9f028fd4a682d8267964ca3d3
5
5
  SHA512:
6
- metadata.gz: 8eeaa4d664ad6fa1b258798787749a831b386d66ee40fa7e323d19686352c2b9f96e11f4fee0ed300b54dc59177e69c3103ce9a408a0bddaf8351b86b301561a
7
- data.tar.gz: 4ace3c4984b24bc8f1996e11f6cbcd5de2aea320d00f5ce216b0c6ed7e47ec3128ee99b8cf396902249e0dca0b283976072397125adf01f88dc6fff4840ce7e2
6
+ metadata.gz: 730c2543f0f661896aa7933077bbfe2835629e333271cda184bd48666459e205b18c6a345caec524eb6792ea03e1101b96fb4d6e6414386fe4a58409a3d5b382
7
+ data.tar.gz: 7106464d406aaf3a4417d7bdfda48419b56884e9e9c4658c7536f2faba0aff045b11f58be001f83ac3281303d8b00f728d9adc5ad357547042f803ff3e687caf
@@ -44,6 +44,8 @@ window.Smalruby =
44
44
  model: @Collections.CharacterSet
45
45
  @Views.CharacterModalView = new Smalruby.CharacterModalView
46
46
  el: $('#character-modal')
47
+ @Views.LoadModalView = new Smalruby.LoadModalView
48
+ el: $('#load-modal')
47
49
 
48
50
  Smalruby.downloading = false
49
51
  window.onbeforeunload = (event) ->
@@ -0,0 +1,126 @@
1
+ # ロードダイアログを表現するビュー
2
+ Smalruby.LoadModalView = Backbone.View.extend
3
+ events:
4
+ 'click #load-modal-ok-button': 'onOk'
5
+
6
+ initialize: ->
7
+ @$el.find('#load-modal-find-from-computer').click (e) =>
8
+ e.preventDefault()
9
+ @onFindFromComputerClick.call(@, e)
10
+
11
+ render: ->
12
+ @type = null
13
+ @program = null
14
+ @unselect()
15
+
16
+ elLocalPrograms = @$el.find('#load-modal-local-programs')
17
+ elLocalPrograms.empty()
18
+
19
+ elDemoPrograms = @$el.find('#load-modal-demo-programs')
20
+ elDemoPrograms.empty()
21
+
22
+ @$el.find('.modal-body').block
23
+ message: null
24
+
25
+ unblock = =>
26
+ @$el.find('.modal-body').unblock()
27
+
28
+ @$el.modal('show')
29
+
30
+ dfr = $.Deferred()
31
+ $.ajax
32
+ url: '/source_codes/'
33
+ type: 'GET'
34
+ dataType: 'json'
35
+ success: (data, textStatus, jqXHR) -> dfr.resolve(data)
36
+ error: dfr.reject
37
+ dfr.promise()
38
+ .then (data) =>
39
+ for program in data.localPrograms
40
+ do (program) =>
41
+ html = @programToHtml(program, @onLocalProgramClick)
42
+ elLocalPrograms.append(html)
43
+
44
+ for program in data.demoPrograms
45
+ do (program) =>
46
+ html = @programToHtml(program, @onDemoProgramClick)
47
+ elDemoPrograms.append(html)
48
+
49
+ .then(unblock, unblock)
50
+ .fail =>
51
+ @$el.modal('hide')
52
+ errorMessage('ロードに失敗しました')
53
+
54
+ onOk: ->
55
+ switch @type
56
+ when 'local'
57
+ $.ajax
58
+ url: '/source_codes/load_local'
59
+ type: 'POST'
60
+ data:
61
+ source_code:
62
+ filename: @program.filename
63
+ dataType: 'json'
64
+ success: (data, textStatus, jqXHR) ->
65
+ Smalruby.Views.MainMenuView.load(data.source_code)
66
+
67
+ when 'demo'
68
+ $.ajax
69
+ url: '/source_codes/load_demo'
70
+ type: 'POST'
71
+ data:
72
+ source_code:
73
+ filename: @program.filename
74
+ dataType: 'json'
75
+ success: (data, textStatus, jqXHR) ->
76
+ Smalruby.Views.MainMenuView.load(data.source_code)
77
+
78
+ when 'find-from-computer'
79
+ $('input#load-file[name="source_code[file]"]').click()
80
+
81
+ @$el.modal('hide')
82
+
83
+ onLocalProgramClick: (e, program) ->
84
+ @select(e.currentTarget, 'local', program)
85
+
86
+ onDemoProgramClick: (e, program) ->
87
+ @select(e.currentTarget, 'demo', program)
88
+
89
+ onFindFromComputerClick: (e) ->
90
+ @select(e.currentTarget, 'find-from-computer')
91
+
92
+ select: (anchor, type, program = null) ->
93
+ @unselect()
94
+ $(anchor).addClass('active')
95
+ @type = type
96
+ @program = program
97
+
98
+ unselect: ->
99
+ @$el.find('a.thumbnail').removeClass('active')
100
+
101
+ programToHtml: (program, onclick) ->
102
+ if program.imageUrl
103
+ img = "<img src=\"#{program.imageUrl}\">"
104
+ else
105
+ img = "<h1 class=\"icon\"><i class=\"icon-file\" /></h1>"
106
+
107
+ html = """
108
+ <li>
109
+ <a class="thumbnail">
110
+ #{img}
111
+ <blockquote>
112
+ <p>
113
+ #{program.title}
114
+ </p>
115
+ <small>#{program.filename}</small>
116
+ </blockquote>
117
+ </div>
118
+ </li>
119
+ """
120
+
121
+ html = $(html)
122
+ html.find('a.thumbnail').click (e) =>
123
+ e.preventDefault()
124
+ onclick.call(@, e, program)
125
+
126
+ html
@@ -7,6 +7,7 @@ Smalruby.MainMenuView = Backbone.View.extend
7
7
  'click #ruby-mode-button': 'onRubyMode'
8
8
  'click #run-button': 'onRun'
9
9
  'click #download-button': 'onDownload'
10
+ 'click #load-local-button': 'onLoadLocal'
10
11
  'click #load-button': 'onLoad'
11
12
  'click #save-button': 'onSave'
12
13
  'click #check-button': 'onCheck'
@@ -23,37 +24,8 @@ Smalruby.MainMenuView = Backbone.View.extend
23
24
 
24
25
  $('#file-form').fileupload
25
26
  dataType: 'json'
26
- done: (e, data) ->
27
- info = data.result.source_code
28
- if info.error
29
- window.errorMessage(info.filename + 'は' + info.error)
30
- else
31
- filename = info.filename
32
- if filename.match(/\.xml$/)
33
- unless window.blockMode
34
- window.blockMode = true
35
- $('#tabs a[href="#block-tab"]').tab('show')
36
-
37
- filename = filename.replace(/(\.rb)?\.xml$/, '.rb')
38
- Smalruby.blocklyLoading = true
39
- Smalruby.loadXml(info.data)
40
- info.data = Blockly.Ruby.workspaceToCode()
41
- else
42
- Smalruby.Collections.CharacterSet.reset()
43
- Blockly.mainWorkspace.clear()
44
-
45
- if window.blockMode
46
- window.blockMode = false
47
- $('#tabs a[href="#ruby-tab"]').tab('show')
48
- window.textEditor.focus()
49
-
50
- $('#filename').val(filename)
51
- window.textEditor.getSession().getDocument().setValue(info.data)
52
- window.textEditor.moveCursorTo(0, 0)
53
- # TODO: window.changed -> Smalruby.Models.SourceCode.changed
54
- window.changed = false
55
- Smalruby.changedAfterTranslating = true
56
- window.successMessage('ロードしました')
27
+ done: (e, data) =>
28
+ @load(data.result.source_code)
57
29
 
58
30
  onBlockMode: (e) ->
59
31
  e.preventDefault()
@@ -187,6 +159,15 @@ Smalruby.MainMenuView = Backbone.View.extend
187
159
  .fail ->
188
160
  window.errorMessage('ダウンロードできませんでした')
189
161
 
162
+ onLoadLocal: (e) ->
163
+ e.preventDefault()
164
+
165
+ # TODO: window.changed -> Smalruby.Models.SourceCode.changed
166
+ if window.changed
167
+ return unless confirm('まだセーブしていないのでロードするとプログラムが消えてしまうよ!\nそれでもロードしますか?')
168
+
169
+ Smalruby.Views.LoadModalView.render()
170
+
190
171
  onLoad: (e) ->
191
172
  e.preventDefault()
192
173
 
@@ -336,3 +317,34 @@ Smalruby.MainMenuView = Backbone.View.extend
336
317
  else
337
318
  canceled.call()
338
319
  $.Deferred().reject().promise()
320
+
321
+ load: (info) ->
322
+ if info.error
323
+ window.errorMessage(info.filename + 'は' + info.error)
324
+ else
325
+ filename = info.filename
326
+ if filename.match(/\.xml$/)
327
+ unless window.blockMode
328
+ window.blockMode = true
329
+ $('#tabs a[href="#block-tab"]').tab('show')
330
+
331
+ filename = filename.replace(/(\.rb)?\.xml$/, '.rb')
332
+ Smalruby.blocklyLoading = true
333
+ Smalruby.loadXml(info.data)
334
+ info.data = Blockly.Ruby.workspaceToCode()
335
+ else
336
+ Smalruby.Collections.CharacterSet.reset()
337
+ Blockly.mainWorkspace.clear()
338
+
339
+ if window.blockMode
340
+ window.blockMode = false
341
+ $('#tabs a[href="#ruby-tab"]').tab('show')
342
+ window.textEditor.focus()
343
+
344
+ $('#filename').val(filename)
345
+ window.textEditor.getSession().getDocument().setValue(info.data)
346
+ window.textEditor.moveCursorTo(0, 0)
347
+ # TODO: window.changed -> Smalruby.Models.SourceCode.changed
348
+ window.changed = false
349
+ Smalruby.changedAfterTranslating = true
350
+ window.successMessage('ロードしました')
@@ -0,0 +1,56 @@
1
+ #load-modal {
2
+ $modal-frame-size: 1px;
3
+ $modal-body-margin: 15px;
4
+
5
+ $modal-margin: $modal-frame-size + $modal-body-margin;
6
+ $modal-body-width: 700px;
7
+ $modal-body-height: 400px;
8
+
9
+ $modal-width: $modal-body-width + $modal-margin * 2;
10
+ $modal-height: $modal-body-height + $modal-margin * 2;
11
+
12
+ width: $modal-width;
13
+ height: $modal-height;
14
+ margin-left: -($modal-width / 2);
15
+
16
+ .modal-body {
17
+ position: relative;
18
+ height: 100%;
19
+ max-height: $modal-height - $modal-body-margin * 2;
20
+
21
+ .list-programs {
22
+ .thumbnail {
23
+ width: 200px;
24
+ cursor: pointer;
25
+
26
+ h1.icon {
27
+ font-size: 64px;
28
+ text-align: center;
29
+ }
30
+
31
+ img {
32
+ max-width: 80px;
33
+ max-height: 80px;
34
+ }
35
+
36
+ blockquote {
37
+ margin: 0 0 0;
38
+ word-break: break-all;
39
+ }
40
+ }
41
+ a.thumbnail {
42
+ color: black;
43
+ text-decoration: none;
44
+ }
45
+
46
+ a.thumbnail.active {
47
+ color: white;
48
+ background-color: #0088cc;
49
+
50
+ blockquote small {
51
+ color: gainsboro;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
@@ -4,6 +4,6 @@ class EditorController < ApplicationController
4
4
  end
5
5
 
6
6
  def demo
7
- @filename = (File.basename(params[:filename]) || 'default') + '.xml'
7
+ @filename = (File.basename(params[:filename]) || 'default') + '.rb.xml'
8
8
  end
9
9
  end
@@ -2,7 +2,39 @@
2
2
  require 'nkf'
3
3
 
4
4
  class SourceCodesController < ApplicationController
5
- before_filter :check_whether_standalone, only: [:write, :run]
5
+ before_filter :check_whether_standalone, only: [:write, :run, :load_local]
6
+
7
+ def index
8
+ res = {
9
+ localPrograms: [],
10
+ demoPrograms: [],
11
+ }
12
+ if standalone?
13
+ local_program_paths.each do |path|
14
+ # TODO: XMLからタイトルを抽出する
15
+ # TODO: XMLからキャラクターの画像を抽出する
16
+ filename = rb_basename(path)
17
+ res[:localPrograms] << {
18
+ title: filename,
19
+ filename: filename,
20
+ }
21
+ end
22
+ end
23
+
24
+ # TODO: XMLから情報を抽出する
25
+ res[:demoPrograms] << {
26
+ title: '車のおいかけっこ',
27
+ filename: 'default.rb',
28
+ imageUrl: '/smalruby/assets/car2.png',
29
+ }
30
+ res[:demoPrograms] << {
31
+ title: 'ライトをぴかっとさせるでよ',
32
+ filename: 'rgb_led_anode.rb',
33
+ imageUrl: '/smalruby/assets/frog1.png',
34
+ }
35
+
36
+ render json: res
37
+ end
6
38
 
7
39
  def check
8
40
  render json: SourceCode.new(source_code_params).check_syntax
@@ -51,6 +83,22 @@ class SourceCodesController < ApplicationController
51
83
  render json: { source_code: info }, content_type: request.format
52
84
  end
53
85
 
86
+ def load_local
87
+ filename = source_code_params[:filename]
88
+ program_path = local_program_paths.find { |path|
89
+ rb_basename(path) == filename
90
+ }
91
+ load_local_file(program_path)
92
+ end
93
+
94
+ def load_demo
95
+ filename = source_code_params[:filename]
96
+ program_path = demo_program_paths.find { |path|
97
+ rb_basename(path) == filename
98
+ }
99
+ load_local_file(program_path)
100
+ end
101
+
54
102
  def run
55
103
  source_code = SourceCode.new(source_code_params)
56
104
  path = Pathname("~/#{source_code.filename}").expand_path
@@ -120,4 +168,36 @@ class SourceCodesController < ApplicationController
120
168
 
121
169
  session[:source_code] = nil
122
170
  end
171
+
172
+ def local_program_paths
173
+ Pathname.glob(Pathname('~/*.rb.xml').expand_path)
174
+ end
175
+
176
+ def demo_program_paths
177
+ Pathname.glob(Rails.root.join('demos/*.rb.xml'))
178
+ end
179
+
180
+ def rb_basename(path)
181
+ path = path.basename.to_s
182
+ path = path[0...-4] if /\.xml\z/ =~ path
183
+ path
184
+ end
185
+
186
+ def load_local_file(path)
187
+ if path
188
+ info = {
189
+ filename: path.basename.to_s,
190
+ type: MIME.check(path.to_s).try(:content_type) || 'text/plain',
191
+ data: NKF.nkf('-w', path.read),
192
+ size: path.size,
193
+ }
194
+ else
195
+ info = {
196
+ filename: source_code_params[:filename],
197
+ error: 'ありません',
198
+ }
199
+ end
200
+
201
+ render json: { source_code: info }, content_type: request.format
202
+ end
123
203
  end
@@ -31,6 +31,7 @@
31
31
  %div
32
32
 
33
33
  = render 'character_modal'
34
+ = render 'load_modal'
34
35
 
35
36
  %script#character-selector-template{:type => 'text/template'}
36
37
  .item
@@ -0,0 +1,35 @@
1
+ #load-modal{:class => "modal hide fade", :tabindex => "-1",
2
+ :role => "dialog", :"aria-hidden" => "true"}
3
+ .modal-body
4
+ %ul.thumbnails{:id => "load-modal-local-programs",
5
+ :class => "list-programs"}
6
+
7
+ .page-header
8
+ %h3<
9
+ %i.icon-th-large
10
+ いろいろなプログラム
11
+ %ul.thumbnails{:id => "load-modal-demo-programs",
12
+ :class => "list-programs"}
13
+
14
+ .page-header
15
+ %h3<
16
+ %i.icon-search
17
+ プログラムをさがす
18
+ %ul.thumbnails{:class => "list-programs"}
19
+ %li
20
+ %a#load-modal-find-from-computer.thumbnail
21
+ %h1.icon
22
+ %i.icon-folder-open-alt
23
+ %blockquote
24
+ %p
25
+ このコンピュータ
26
+ %small
27
+ Computer
28
+
29
+ .modal-footer
30
+ %button.btn{:"data-dismiss" => "modal", :"aria-hidden" => "true"}<
31
+ %i.icon-remove
32
+ やめる
33
+ %button#load-modal-ok-button{:class => "btn btn-primary"}<
34
+ %i.icon-circle-blank
35
+ 決めた!
@@ -29,7 +29,11 @@
29
29
  %i.icon-reorder
30
30
  %ul.dropdown-menu{:class => "pull-right"}
31
31
  %li
32
- %a#load-button
32
+ - if standalone?
33
+ - load_id = 'load-local-button'
34
+ - else
35
+ - load_id = 'load-button'
36
+ %a{:id => "#{load_id}"}
33
37
  %h4
34
38
  %i.icon-folder-open
35
39
  ロード
data/config/routes.rb CHANGED
@@ -5,10 +5,12 @@ SmalrubyEditor::Application.routes.draw do
5
5
  match '/demo(/:filename)' => 'editor#demo',
6
6
  defaults: { filename: 'default' }, via: :get
7
7
 
8
- resources :source_codes, only: [:create]
8
+ resources :source_codes, only: [:create, :index]
9
9
  post 'source_codes/check'
10
10
  delete 'source_codes/download'
11
11
  post 'source_codes/load'
12
+ post 'source_codes/load_local'
13
+ post 'source_codes/load_demo'
12
14
  delete 'source_codes/write'
13
15
  post 'source_codes/run'
14
16
  post 'source_codes/to_blocks'
@@ -1,3 +1,3 @@
1
1
  module SmalrubyEditor
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -287,10 +287,12 @@ files:
287
287
  - app/assets/javascripts/views/.keep
288
288
  - app/assets/javascripts/views/character_modal_view.js.coffee
289
289
  - app/assets/javascripts/views/character_selector_view.js.coffee
290
+ - app/assets/javascripts/views/load_modal_view.js.coffee
290
291
  - app/assets/javascripts/views/main_menu_view.js.coffee
291
292
  - app/assets/stylesheets/application.css
292
293
  - app/assets/stylesheets/editor.css.scss
293
294
  - app/assets/stylesheets/flatstrap-custom.css.scss
295
+ - app/assets/stylesheets/load-modal.css.scss
294
296
  - app/assets/stylesheets/toolbox.css.scss.erb
295
297
  - app/assets/templates/.keep
296
298
  - app/controllers/application_controller.rb
@@ -366,6 +368,7 @@ files:
366
368
  - app/models/source_code.rb
367
369
  - app/views/editor/_block_tab.html.haml
368
370
  - app/views/editor/_character_modal.html.haml
371
+ - app/views/editor/_load_modal.html.haml
369
372
  - app/views/editor/_toolbox.html.haml
370
373
  - app/views/editor/demo.html.erb
371
374
  - app/views/editor/index.html.haml
@@ -400,8 +403,8 @@ files:
400
403
  - db/migrate/20131219045113_add_filename_to_source_code.rb
401
404
  - db/schema.rb
402
405
  - db/seeds.rb
403
- - demos/default.xml
404
- - demos/rgb_led_anode.xml
406
+ - demos/default.rb.xml
407
+ - demos/rgb_led_anode.rb.xml
405
408
  - lib/assets/.keep
406
409
  - lib/smalruby_editor.rb
407
410
  - lib/smalruby_editor/version.rb
@@ -583,10 +586,10 @@ files:
583
586
  - vendor/assets/javascripts/blockly/msg/js/ja.js
584
587
  - vendor/assets/javascripts/jquery.blockUI.js
585
588
  - vendor/assets/stylesheets/.keep
586
- - public/assets/application-28b7bed56c5389dfa372e972c75b6676.css
587
- - public/assets/application-28b7bed56c5389dfa372e972c75b6676.css.gz
588
- - public/assets/application-4f747690ebc8ec4815ae36021fdb2c44.js
589
- - public/assets/application-4f747690ebc8ec4815ae36021fdb2c44.js.gz
589
+ - public/assets/application-3ee566927dc437f1406e5e903da1baf5.js
590
+ - public/assets/application-3ee566927dc437f1406e5e903da1baf5.js.gz
591
+ - public/assets/application-5f1777e683ca5d3cf4e0f0374eab6fac.css
592
+ - public/assets/application-5f1777e683ca5d3cf4e0f0374eab6fac.css.gz
590
593
  - public/assets/favicon-a37c90b368fd8ed436cb8f9e9396465c.ico
591
594
  - public/assets/jquery-ui/animated-overlay-c48c87b7a95316f4698484e3b85ee4aa.gif
592
595
  - public/assets/jquery-ui/ui-bg_flat_0_aaaaaa_40x100-58b63faadd031ca3db096dfdffd90224.png