idecoder 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5c5e8a4f9a489d91305c20b603faf3a2543f3cd0b256313d4278dbcd91d9a20
4
- data.tar.gz: 9cd14c1709edb3484fa6e2db8811da98f4f78bbd41a6fdc188fe1917acde9dfa
3
+ metadata.gz: 04f52af610cff78a702112a6639b4be104f9197dbe3d47c25df4ec3eaa5d4de0
4
+ data.tar.gz: e387e0a00a2a4842612b1e56043c9fcd2662445fe66ed39f1b1da673c73fa22d
5
5
  SHA512:
6
- metadata.gz: cfe092787cae3aa91a12ae2868aeaa111d904918cc73ce05488a2784ae80c1e81134b7679b0fde63e7b7e6c4e23853bf18068fe45e7e355377fcffa4e1ea8b50
7
- data.tar.gz: 0275ab12d520deb4eb9567d6062f3da03cd54ead6b5257f4b35888f8abccb5f8240c970d0aad23e92d9ca99cf39c510d4be60171a4b7be0befe6fcf0bc98d3ea
6
+ metadata.gz: f0698d3eb911d591567b892f659a654c3bf4df0aa87f38eccd2988306c883a570143b2fc25fdfdc51515045e57a652a1fc7abb6f68c46f650ea0069d94fe841d
7
+ data.tar.gz: 7ded7959cecdb8b98261e8a4dfc4c791b03ce6862ca153918584746217577ad357b72888a7f7b58e74fb192744699bf6e23c2f3d2e19d1304a976e62a1b2db26
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/idecoder.svg)](http://badge.fury.io/rb/idecoder)
4
4
 
5
- Idecoder was created for developers building web applications with coding editors. Idecoder.js provides a plugin that gives the developer a screen inside their own app
5
+ Idecoder was created for developers building web applications with coding editors. Idecoder provides a plugin that gives the developer a screen inside their own app
6
6
  to give the users a way to develop codes.
7
7
 
8
8
  ## Installation
@@ -21,6 +21,9 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
  Simply add the `render_idecoder` helper method to your Rails layout or to any specific page you wish.
24
+ after installing, go to "<host> / idecoder" for testing screen:
25
+
26
+ ![Alt text](app/assets/images/screen.png "Screen")
24
27
 
25
28
  <pre>
26
29
  &lt;html>
@@ -57,7 +60,7 @@ If you wish to have Idecoder in your production and/or staging environment, pass
57
60
 
58
61
  | Value | Default | Description |
59
62
  |----------|----------|------------------------------------------|
60
- | language | ruby | See Language Options List |
63
+ | mode | ruby | See Language Options List |
61
64
  | theme | monokai | See Themes Options List |
62
65
  | height | 300px | Canvas height |
63
66
  | width | 90% | Canvas width |
@@ -68,28 +71,9 @@ If you wish to have Idecoder in your production and/or staging environment, pass
68
71
 
69
72
  | Value | Description |
70
73
  |----------|------------------------------------------|
71
- | abap | ABAP Language |
72
- | asciidoc | AsciiDoc Language |
73
- | c_cpp | C / C++ |
74
- | coldfusion | Cold Fusion |
75
- | csharp | C Sharp |
76
- | css | CSS |
77
- | dart | Dart Language |
78
- | dot | .Net |
79
- | haml | HAML |
80
- | java | Java Language |
74
+ | html | Design Html |
81
75
  | javascript | Javascript |
82
- | json | Json |
83
- | objectivec | Objective C |
84
- | perl | Perl |
85
- | pgsql | Language for PostgreSQL |
86
- | php | PHP |
87
- | python | Python Language |
88
76
  | ruby | Ruby Language |
89
- | sql | SQL Scripts |
90
- | typescript | TypeScript |
91
- | xml | XML |
92
- | yaml | YAML |
93
77
 
94
78
 
95
79
  ### Theme Options
@@ -128,9 +112,8 @@ If you wish to have Idecoder in your production and/or staging environment, pass
128
112
 
129
113
  **Dependencies**
130
114
 
131
- Marx.Idecoder has a dependency on:
132
- 1. jQuery version >= 1.10.x
133
- 2. JQuery Ace Rails 1.0.1
115
+ Idecoder has a dependency on:
116
+ 1. gem execjs (sstephenson/execjs)
134
117
 
135
118
 
136
119
  ## Contributing
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/canvas .css
@@ -1,11 +1,11 @@
1
1
  window.Idecoder = function(options) {
2
2
  var _this = this;
3
- this._url = "http://marxjs.com";
4
3
  return _this.initialize(options);
5
4
  };
6
5
 
7
6
  $.extend(Idecoder.prototype, {
8
7
  settings: {
8
+ theme: 'monokai',
9
9
  language: 'ruby',
10
10
  read_only: false,
11
11
  height: "300px",
@@ -13,7 +13,8 @@ $.extend(Idecoder.prototype, {
13
13
  border: "1px solid lightgray",
14
14
  },
15
15
  initialize: function(options) {
16
- $.extend(this.settings);
16
+ let sett = this.settings
17
+ $.extend(jQuery.extend(sett, options));
17
18
  return this.create_canvas();
18
19
  },
19
20
  /*=========================
@@ -1,10 +1,27 @@
1
- .ace-clipboard{
2
- font-size: 8px;
1
+ .idecoder-button{
2
+ font-size: 10px;
3
3
  padding: 3px;
4
4
  opacity: 0.8;
5
5
  cursor: pointer;
6
- position:relative;
7
- top: 0px;
8
- right: 0px;
9
- z-index: 100;
10
6
  }
7
+
8
+ .idecoder-pre {
9
+ font-size: 14px;
10
+ border: 2px solid grey;
11
+ width: 650px;
12
+ border-left: 12px solid darkslategray;
13
+ border-radius: 5px;
14
+ padding: 14px;
15
+
16
+ /* Fixed line height */
17
+ line-height: 20px;
18
+
19
+ /* Use linear-gradient for background image */
20
+ background-color: lightgray;
21
+
22
+ /* Size background so that the height is 2x line-height */
23
+ background-size: 100% 48px;
24
+
25
+ /* Offset the background along the y-axis by top padding */
26
+ background-position: 0 14px;
27
+ }
@@ -0,0 +1,4 @@
1
+ module Idecoder
2
+ class Idecoder::ApplicationController < ::ApplicationController
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ module Idecoder
2
+
3
+ class RunnersController < ApplicationController
4
+ require_dependency "idecoder/application_controller"
5
+ require_relative '../../runners_strategy'
6
+ require_relative '../../runners_factory'
7
+
8
+ def test
9
+ @modes = RunFactory.list_types
10
+ @mode = params['mode'] || "ruby"
11
+ render layout: false
12
+ end
13
+
14
+ def run
15
+ begin
16
+ fabrica = RunFactory.for(params['mode'])
17
+ parser = CodeParser.new(params['code'], fabrica)
18
+
19
+ data = parser.parse
20
+ render json: {data: data, status: 200}, status: :ok
21
+ rescue Exception => ex
22
+ render json: {data: ex.message, status: 500}, status: :ok
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
@@ -0,0 +1,4 @@
1
+ module Idecoder
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Idecoder
2
+ module RunnersHelper
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ class RunFactory
2
+
3
+ TYPES = {
4
+ html: HTMLParser,
5
+ javascript: JAVASCRIPTParser,
6
+ ruby: RubyParser
7
+ }
8
+
9
+ def self.list_types
10
+ TYPES.keys
11
+ end
12
+
13
+ def self.for(mode)
14
+ type_c = mode && TYPES[mode.to_sym]
15
+ if type_c.nil?
16
+ raise "Invalid mode selection"
17
+ else
18
+ return type_c.new
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,51 @@
1
+ class RunParser
2
+ require 'execjs'
3
+
4
+ def parse(code)
5
+ raise 'Must implement!'
6
+ end
7
+ end
8
+
9
+ ###
10
+
11
+ class RubyParser < RunParser
12
+ def parse(code)
13
+ begin
14
+ eval(code)
15
+ rescue Exception => ex
16
+ raise ex.message
17
+ end
18
+ end
19
+ end
20
+
21
+ ###
22
+
23
+ class HTMLParser < RunParser
24
+ def parse(code)
25
+ code
26
+ end
27
+ end
28
+
29
+ ###
30
+
31
+ class JAVASCRIPTParser < RunParser
32
+ def parse(code)
33
+ ExecJS.eval('"red yellow blue".split(" ")')
34
+ end
35
+ end
36
+
37
+ ###
38
+
39
+ class CodeParser
40
+ attr_reader :code, :parser
41
+
42
+ def initialize(code, parser)
43
+ @code = code
44
+ @parser = parser
45
+ end
46
+
47
+ def parse
48
+ parser.parse(code)
49
+ end
50
+
51
+ end
@@ -0,0 +1,24 @@
1
+
2
+
3
+ <small>Example:</small>
4
+ <pre style="font-size: 10px; padding-bottom: 20px; padding-top: 20px; background-color: #eee !important; border: lightgray thin; ">
5
+ &lt;%= render_idecoder(theme: "vibrant_ink", mode: "<%= @mode %>" height: "100px", width: "90%", copy: false) %>
6
+ </pre>
7
+
8
+
9
+ Selected language:
10
+ <%= select_tag "mode", options_for_select(@modes, @mode) %>
11
+ <br /><br />
12
+ <hr>
13
+
14
+
15
+ <div style="margin: 20px;">
16
+ <%= render_idecoder(theme: "vibrant_ink", mode: @mode, height: "100px", width: "90%", copy: false) %>
17
+ </div>
18
+
19
+
20
+ <script>
21
+ $("#mode").on("change", function () {
22
+ window.location = "/idecoder?mode="+$("#mode").val();
23
+ });
24
+ </script>
@@ -1 +1,5 @@
1
- require 'idecoder/rails' if defined?(Rails)
1
+ require 'idecoder/rails' if defined?(Rails)
2
+ require "idecoder/engine"
3
+
4
+ module Idecoder
5
+ end
@@ -0,0 +1,7 @@
1
+ # require "idecoder/engine"
2
+
3
+ module Idecoder
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Idecoder
6
+ end
7
+ end
@@ -2,11 +2,10 @@ require "idecoder/rails/version"
2
2
  require "idecoder/view_helpers"
3
3
 
4
4
  module Idecoder
5
- module Rails
6
- class Engine < ::Rails::Engine
7
- initializer "idecoder.view_helpers" do
8
- ActionView::Base.send :include, ViewHelpers
9
- end
5
+ class Engine < ::Rails::Engine
6
+ initializer "idecoder.view_helpers" do
7
+ ActionView::Base.send :include, ViewHelpers
10
8
  end
9
+ # isolate_namespace Idecoder
11
10
  end
12
11
  end
@@ -1,5 +1,5 @@
1
1
  module Idecoder
2
2
  module Rails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -4,13 +4,13 @@
4
4
  <% theme = options_hash[:theme].present? ? options_hash[:theme] : "monokai" %>
5
5
  <% mode = options_hash[:mode].present? ? options_hash[:mode] : "ruby" %>
6
6
 
7
+ <%= csrf_meta_tags %>
8
+
7
9
  <script src="assets/jquery/jquery.min.js"></script>
8
10
  <script src="assets/ace/ace.js"></script>
9
11
 
10
12
  <script src="assets/ace/theme-<%= theme %>.js"></script>
11
-
12
- <script src="assets/ace/mode-ruby.js"></script>
13
- <script src="assets/jquery-ace.min.js"></script>
13
+ <script src="assets/ace/mode-<%= mode %>.js"></script>
14
14
 
15
15
  <script src="assets/idecoder.js"></script>
16
16
 
@@ -28,43 +28,56 @@
28
28
 
29
29
  if (key && key == '82' && e.shiftKey && !(e.altKey)){
30
30
  e.preventDefault();
31
+ runCode();
31
32
  return false;
32
33
  }
33
34
  return true;
34
35
  });
35
36
  </script>
36
37
 
38
+
39
+ <button id="idecoder_btn_copy" class='idecoder-button idecoder-copy border' onclick='javascrit:copyToClipboard()'>Copy source to clipboard
40
+ </button>
41
+ <button id="idecoder_btn_run" title="Run (shift+r)" class='idecoder-button idecoder-run' onclick='javascrit:runCode()'>
42
+ Run (shift+R)
43
+ </button>
44
+
37
45
  <div class="idecoder-panel">
38
- <a id="btn_copy" class='btn btn-sm btn-light border ace-clipboard' onclick='javascrit:copyToClipboard()'>Copy</a>
39
- <div style="text-align: end">
40
- <a id="btn_exec" title="Run (shift+r)" class='btn btn-sm btn-light border' style="width: 35px;" onclick='javascrit:runCode()'>
41
- <i class="fa fa-play text-success"></i>
42
- </a>
43
- </div>
44
46
  <pre id="editor-area" ></pre>
45
47
  </div>
46
48
 
47
- <div class="idecoder-result-panel" style="">
48
- <pre id="editor-result-area" ></pre>
49
+ <br />
50
+
51
+ <pre class="idecoder-pre" id="editor-result-area" ></pre>
52
+
53
+ <div id="div_error" style="background-color: lightgray; padding: 10px; display: none">
54
+ <span id="error_message" style="color: red; font-size: 12px;"></span>
49
55
  </div>
50
56
 
57
+ <input type="hidden" id="hide-editor-value">
58
+
51
59
  <script>
60
+
52
61
  var config = idecoder.settings;
62
+
53
63
  $canvas = $("#editor-area");
54
64
  $canvas.css("border", config.border);
55
65
  $canvas.css("height", config.height);
56
66
  $canvas.css("width", config.width);
57
67
  resultCanvas = $("#editor-result-area");
58
- resultCanvas.css("height", 200);
59
- resultCanvas.css("width", config.width);
60
68
  resultCanvas.css("margin-top", config.height);
61
69
 
62
- var resultEditor = ace.edit("editor-result-area");
63
- resultEditor.setReadOnly(true);
64
-
65
70
  var editor = ace.edit("editor-area");
66
71
  editor.setTheme("ace/theme/<%= theme %>")
67
72
  editor.session.setMode("ace/mode/<%= mode %>")
73
+ editor.setShowPrintMargin(false);
74
+ editor.setBehavioursEnabled(true);
75
+
76
+ var textvalue = $('#hide-editor-value');
77
+
78
+ editor.getSession().on('change', function() {
79
+ textvalue.val(editor.getValue());
80
+ });
68
81
 
69
82
  function copyToClipboard() {
70
83
  var copyText = editor.getValue();
@@ -76,7 +89,23 @@
76
89
  }
77
90
 
78
91
  function runCode(){
79
-
92
+ $.ajax({
93
+ url: '/idecoder/run',
94
+ type: 'POST',
95
+ data: {authenticity_token: $('[name="csrf-token"]')[0].content, mode: '<%= mode %>', code: textvalue.val()}
96
+ }).done(function(data) {
97
+ if(data.status == 200){
98
+ <% if mode == "html" %>
99
+ $("#editor-result-area").html(data.data)
100
+ <% else %>
101
+ $("#editor-result-area").text(data.data)
102
+ <% end %>
103
+ $("#div_error").hide();
104
+ } else {
105
+ $("#div_error").show();
106
+ $("#error_message").text(data.data)
107
+ }
108
+ });
80
109
  }
81
110
 
82
111
  <% if options_hash[:copy].nil? || !options_hash[:copy] %>
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :canvas do
3
+ # # Task goes here
4
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idecoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Popolin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-08 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: execjs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: 'Now you can easily put an editor inside your project. With environment
42
56
  variables reader and autocompletes. '
43
57
  email:
@@ -48,6 +62,8 @@ extra_rdoc_files: []
48
62
  files:
49
63
  - MIT-LICENSE
50
64
  - README.md
65
+ - app/assets/config/canvas_manifest.js
66
+ - app/assets/images/screen.png
51
67
  - app/assets/javascripts/ace/ace.js
52
68
  - app/assets/javascripts/ace/ext-static_highlight.js
53
69
  - app/assets/javascripts/ace/ext-textarea.js
@@ -152,11 +168,20 @@ files:
152
168
  - app/assets/javascripts/jquery-ace.min.js
153
169
  - app/assets/javascripts/jquery/jquery.min.js
154
170
  - app/assets/stylesheets/idecoder.css
171
+ - app/controllers/idecoder/application_controller.rb
172
+ - app/controllers/idecoder/runners_controller.rb
173
+ - app/helpers/idecoder/application_helper.rb
174
+ - app/helpers/idecoder/runners_helper.rb
175
+ - app/runners_factory.rb
176
+ - app/runners_strategy.rb
177
+ - app/views/idecoder/runners/test.html.erb
155
178
  - lib/idecoder.rb
179
+ - lib/idecoder/engine.rb
156
180
  - lib/idecoder/rails.rb
157
181
  - lib/idecoder/rails/version.rb
158
182
  - lib/idecoder/templates/idecoder.erb
159
183
  - lib/idecoder/view_helpers.rb
184
+ - lib/tasks/idecoder_tasks.rake
160
185
  homepage: https://github.com/popolin/idecoder
161
186
  licenses:
162
187
  - MIT