markdaver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b080917017146a73b359112db742833de3ccd8b4
4
+ data.tar.gz: e00b32f7a3843470a2159accccf019b7d10624c9
5
+ SHA512:
6
+ metadata.gz: 54188bab2ee4a51c628b8827d73a5a7da47b4f511932162bcce0b3b697a5f4250724309cea681edd8edb36004b46171476a8222122cb588799cf071a5932fc95
7
+ data.tar.gz: b10c2109d3bacd7b2900282ef2e5fd686b28c81d476ebecd0eee358efc65e4fd3cecc9f141948257ea98ad5b3b595cb7a2a4dcfbec80b0cfb99752ce9d18057a
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdaver.gemspec
4
+ gemspec
5
+ gem "byebug"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ricardo Valeriano
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.
@@ -0,0 +1,38 @@
1
+ # Markdaver - A web based markdown editor
2
+
3
+ This is a (ruby) rack application that uses a GREAT web interface (thanks
4
+ https://github.com/jbt/markdown-editor) to edit new or existent markdown files
5
+ with a nice preview side by side within the editor.
6
+
7
+ ## Installation and Usage
8
+
9
+ You can install it as a gem, in the classic way:
10
+
11
+ $ gem install markdaver
12
+
13
+ This will create an executable called `markdaver`, that can be invoked to
14
+ edit a file in any path (existent or new) given by the `MARKDOWN` env var.
15
+
16
+ MARKDOWN="~/my/new/book/intro.md" markdaver
17
+
18
+ If you will prefer to clone the project, after clone, just go the main dir an
19
+ execute the `bundle exec rackup`, you can also use the environment variable
20
+ like so:
21
+
22
+ MARKDOWN="~/my/new/book/intro.md" bundle exec rackup
23
+
24
+ ## Development
25
+
26
+ 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.
27
+
28
+ 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).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ricardovaleriano/markdaver.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
@@ -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 "markdaver"
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
@@ -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,34 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require "ostruct"
3
+ require 'markdaver'
4
+ require "markdaver/inject_index_script"
5
+ require "markdaver/markdown_editor_env"
6
+
7
+ FILE = ENV['MARKDOWN'] || ENV['FILE_TO_OPEN'] || './omg.md'
8
+
9
+ app = Rack::Builder.new do
10
+ environment = Markdaver::MarkdownEditorEnv.new(
11
+ root_path: File.expand_path("../markdown-editor/"),
12
+ script_file: File.expand_path("./web/script.js"),
13
+ file_to_open: FILE
14
+ )
15
+
16
+ map '/save' do
17
+ run ->(env) {
18
+ request = Rack::Request.new(env)
19
+ # TODO:
20
+ # - add some specs!!!
21
+ # - store the edition history (create a file for each update?)
22
+ # - save after some seconds of inactivity
23
+ # - ...
24
+ File.write FILE, request.params['markdown']
25
+ [200, {'Content-Type' => 'text/plain'}, ['post received!']]
26
+ }
27
+ end
28
+
29
+ use Markdaver::InjectIndexScript, markdown_editor_env: environment
30
+ use Rack::Static, urls: [''], root: environment.root_path, index: 'index.html'
31
+ run ->(env) { [200, {'Content-Type' => 'text/plain'}, ['hi there']] }
32
+ end
33
+
34
+ run app
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ `rackup #{File.expand_path('../../config.ru', __FILE__)}`
@@ -0,0 +1,5 @@
1
+ require "markdaver/version"
2
+
3
+ module Markdaver
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,18 @@
1
+ module Markdaver
2
+ class InjectIndexScript
3
+ def initialize(app, options = {})
4
+ @app = app
5
+ @environment = options[:markdown_editor_env]
6
+ end
7
+
8
+ def call(env)
9
+ if env["PATH_INFO"] == "/"
10
+ status, header, _ = @app.call env
11
+ header["Content-Length"] = @environment.index.length.to_s
12
+ [status, header, [@environment.index]]
13
+ else
14
+ @app.call env
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ module Markdaver
2
+ class MarkdownEditorEnv
3
+ attr_reader :root_path
4
+
5
+ def initialize(
6
+ root_path: File.expand_path("../../../markdown-editor/"),
7
+ script_file: nil,
8
+ file_to_open: nil
9
+ )
10
+ @root_path = root_path
11
+ @script_file = script_file
12
+ @file_to_open = file_to_open
13
+ end
14
+
15
+ def index
16
+ @index ||= File.read(File.join @root_path, "index.html")
17
+ .gsub(/<\/body>/, "\n<script>#{script}</script>\\0")
18
+ end
19
+
20
+ private
21
+
22
+ def script
23
+ javascript_code = ''
24
+ if @file_to_open and File.exist?(@file_to_open)
25
+ javascript_code << %{ var openFile = `#{File.read(@file_to_open)}`; }
26
+ end
27
+ javascript_code + script_load
28
+ end
29
+
30
+ def script_load
31
+ (@script_file && File.read(@script_file)) ||
32
+ %{console.log("we need some script in the environment");}
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Markdaver
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markdaver/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "markdaver"
8
+ spec.version = Markdaver::VERSION
9
+ spec.authors = ["Ricardo Valeriano"]
10
+ spec.email = ["ricardo.valeriano@gmail.com"]
11
+
12
+ spec.summary = %q{Add local file autosave features to github.com/jbt/markdown-editor.}
13
+ spec.description = %q{Runs a local server so you can edit and local (auto) save markdown documents.}
14
+ spec.homepage = "https://github.com/ricardovaleriano/markdaver."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_runtime_dependency "rack"
27
+ end
@@ -0,0 +1,39 @@
1
+ function _save() {
2
+ var request = new XMLHttpRequest();
3
+ request.addEventListener("load", function(){
4
+ console.log("request done");
5
+ });
6
+ request.open("POST", "/save");
7
+ request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
8
+
9
+ var markdown = editor.getValue();
10
+ request.send("markdown=" + encodeURIComponent(markdown));
11
+ }
12
+
13
+ function timeToSave(ev) {
14
+ keyStrokes++;
15
+
16
+ if(keyStrokes == keyStrokesMax) {
17
+ keyStrokes = 0;
18
+ console.log(keyStrokesMax + " key strokes! saving...");
19
+ _save();
20
+ }
21
+ }
22
+
23
+ var _originalSaveAsMarkdown = saveAsMarkdown();
24
+
25
+ function saveAsMarkdown() {
26
+ _save();
27
+ }
28
+
29
+ var dataModifiedEventCount = 0;
30
+ var dataModifiedEventMax = 3;
31
+ var keyStrokes = 0;
32
+ var keyStrokesMax = 20;
33
+
34
+ var codeTextarea = document.getElementsByTagName("textarea")[1];
35
+ codeTextarea.addEventListener("keyup", timeToSave, false);
36
+
37
+ if(openFile != undefined) {
38
+ editor.setValue(openFile);
39
+ }
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdaver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ricardo Valeriano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-06 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: rack
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
+ description: Runs a local server so you can edit and local (auto) save markdown documents.
70
+ email:
71
+ - ricardo.valeriano@gmail.com
72
+ executables:
73
+ - markdaver
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - config.ru
88
+ - exe/markdaver
89
+ - lib/markdaver.rb
90
+ - lib/markdaver/inject_index_script.rb
91
+ - lib/markdaver/markdown_editor_env.rb
92
+ - lib/markdaver/version.rb
93
+ - markdaver.gemspec
94
+ - web/script.js
95
+ homepage: https://github.com/ricardovaleriano/markdaver.
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Add local file autosave features to github.com/jbt/markdown-editor.
119
+ test_files: []
120
+ has_rdoc: