yield 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42f793b0009f6fae3875c945302b563eae95c07b
4
- data.tar.gz: 5a578c3af1ea313dc0473376513d5665fc473087
3
+ metadata.gz: 02a641621a62dc49014f39bce2a1e6caba8d3f03
4
+ data.tar.gz: 07d5e89234624f95f581e3a03b72e15a56e6a8b0
5
5
  SHA512:
6
- metadata.gz: 95ec477cd689600e1280ca3b288061dafdab632a5dd8fa5d0d695a0b6f6a0cc360a00460796b6f4a090d093cf8cbc23a0d3ad36a322b6f65aafd3e1974306917
7
- data.tar.gz: 5235056ce67a1aa88b38e8833f47d086c73c72f9795929e9467527d0fa8c225cf1675a951c2e9bac53346b0f912330ae17b57318ba341bb10c6246d79a3d57a3
6
+ metadata.gz: 2ff9bcfe989f1ed2f827b14a80f640d35a0e4457f5bf9f70d547c1359cc6785cf340d689b07d572fe5622ce2820fb8839304c1ca3dd2729345783011cb86e8b3
7
+ data.tar.gz: a171350d8f9ca629f6b4231ff2df32dcf300e3143eb06d428ef062234ad72b26aa81596e0eea91e4b11c03ef50f209dede6f11c8a0646ada41206718dbf57fa4
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- .DS_Store
18
+ .DS_Store
19
+ /versions
data/README.md CHANGED
@@ -32,16 +32,22 @@ $ yield
32
32
  You may also specify a path to a markdown file you'd like to render, such as:
33
33
 
34
34
  ```bash
35
+ # Render a specific file
35
36
  $ yield UPDATES.md
36
37
  ```
37
38
 
38
39
  Then navigate to [localhost:4000](http://localhost:4000) in your browser to view the preview of the file. You can stop the server by pressing Control+C.
39
40
 
40
- ## Issues
41
+ Yield also supports relative URLs in the same directory, so you can preview other files by navigating to them in the URL bar. For example, you can preview the CHANGELOG.md file by navigating to [localhost:4000/CHANGELOG.md](http://localhost:4000/CHANGELOG.md).
41
42
 
42
- ### API Rate Limit Exceeded
43
+ Finally, you can specify the port for the server to run on using the `-p` or `--port` option:
43
44
 
44
- GitHub's API only allows only 60 unauthenticated requests per hour from a single IP address. If you are hitting this limit, then you must really like yield!
45
+ ```bash
46
+ # Run the server on port 8080
47
+ $ yield -p 8080
48
+ ```
49
+
50
+ ## Potential Errors
45
51
 
46
52
  ### OpenSSL Error
47
53
 
data/bin/yield CHANGED
@@ -1,16 +1,31 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rbconfig'
3
+ require 'optparse'
3
4
  require_relative '../lib/yield'
4
5
 
6
+ # Determine if OS is Windows, and disable echo of characters in hat notation (^C) if it is not.
5
7
  is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
6
-
7
8
  `stty -echoctl` unless is_windows
8
9
 
9
- if ARGV.length == 1
10
- filename = ARGV[0]
11
- Yield::Markdown.init(filename)
12
- else
13
- Yield::Markdown.init
10
+ port = 4000
11
+
12
+ OptionParser.new do |o|
13
+ o.banner = "Usage: #{o.program_name} MARKDOWN_FILE.md"
14
+
15
+ o.on('-h', '--help', 'View the help menu') { puts o; Kernel.exit }
16
+ o.on('-p PORT', '--port PORT', 'Specify port to run Yield on') { |o| port = o }
17
+ o.on('-v', '--version', 'Display version number') do
18
+ puts 'yield version ' + Yield::VERSION
19
+ Kernel.exit
20
+ end
21
+
22
+ begin
23
+ o.parse!
24
+ rescue OptionParser::InvalidOption => o
25
+ puts o.message
26
+ end
14
27
  end
15
28
 
16
- Yield::Server.run!
29
+ # Parse a specific file if given, otherwise parse README.md.
30
+ ARGV.length == 1 ? Yield::Markdown.init(ARGV[0]) : Yield::Markdown.init
31
+ Yield::Server.run!(port)
@@ -2,17 +2,16 @@ module Yield
2
2
  class Server < Sinatra::Base
3
3
 
4
4
  set :server, 'webrick'
5
- set :port, 4000
6
5
 
7
6
  # Override run! method from Sinatra
8
- def self.run!()
7
+ def self.run!(port)
9
8
  settings = {}
10
9
  detect_rack_handler.run self, settings.merge(Port: port, Host: bind, Logger: WEBrick::Log.new('/dev/null'), AccessLog: []) do |server|
11
10
  $stderr.puts "=* Yield is serving your markdown at http://localhost:#{port}/"
12
11
  [:INT, :TERM].each { |sig| trap(sig) { quit!(server) } }
13
12
  server.threaded = settings.threaded if server.respond_to? :threaded=
14
13
  set :running, true
15
- open_in_browser
14
+ open_in_browser(port)
16
15
  yield server if block_given?
17
16
  end
18
17
  rescue Errno::EADDRINUSE
@@ -31,9 +30,24 @@ module Yield
31
30
  erb :index, locals: { content: content, filename: filename }
32
31
  end
33
32
 
34
- not_found { erb :'404' }
33
+ get '/:filename' do
34
+ filename = params[:filename]
35
+ begin
36
+ content = Markdown.convert_to_html(File.read(filename))
37
+ erb :index, locals: { content: content, filename: filename }
38
+ rescue Errno::EISDIR
39
+ raise Sinatra::NotFound
40
+ rescue Errno::ENOENT
41
+ raise Sinatra::NotFound
42
+ end
43
+ end
44
+
45
+ not_found do
46
+ filename = request.fullpath.split('/')[-1]
47
+ erb :'404', locals: { filename: filename }
48
+ end
35
49
 
36
- def self.open_in_browser
50
+ def self.open_in_browser(port)
37
51
  Launchy.open("http://localhost:#{port}/")
38
52
  end
39
53
 
@@ -1,3 +1,3 @@
1
1
  module Yield
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -7,10 +7,10 @@
7
7
  <body>
8
8
  <div class="page">
9
9
  <div id="readme" class="clearfix announce instapaper_body md">
10
- <span class="name"><span class="octicon octicon-book"></span> OOPS.md</span>
10
+ <span class="name"><span class="octicon octicon-book"></span> <%= filename %></span>
11
11
  <article class="markdown-body entry-content">
12
- <h2>Yield could not find your file</h2>
13
- <p>Try going <a href="/">here</a>!</p>
12
+ <h3>Oops, Yield could not find that file.</h3>
13
+ <p>Make sure the file exists, or try going <a href="/">here</a>.</p>
14
14
  </article>
15
15
  </div>
16
16
  </div>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey Scarborough
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2013-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.0.6
109
+ rubygems_version: 2.0.5
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Yield is a command line utility written in Ruby that allows a user to render