Skip to content

Version 2.0.0 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.gem
Gemfile.lock
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
language: ruby
rvm:
- 2.0.0
- 1.9.3

notifications:
email:
recipients:
- dropbox+travis@ricostacruz.com
on_success: change
on_failure: change
- 2.3.0
18 changes: 0 additions & 18 deletions Gemfile.lock

This file was deleted.

7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [v2.0.0-pre1]
> May 6, 2016

- **Completely new API.** Update to use Styledown v2.0.0-pre1.

[v2.0.0-pre1]: https://github.com/styledown/styledown-rails/compare/v0.0.0...v2.0.0-pre1

## [v1.0.1]
> Apr 19, 2016

Expand Down
36 changes: 21 additions & 15 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,47 @@ Ruby integration of [Styledown].

```rb
# Gemfile
gem 'styledown'
gem 'styledown', '~> 2.0.0'
```

[![Gem](https://img.shields.io/gem/v/styledown.svg?style=flat)](http://rubygems.org/gems/styledown "View this project in Rubygems")

## Plain Ruby integration

API for `Styledown.parse` is exactly the same as the JS version ([docs]).
These are provided:

* `Styledown.parse`
* `Styledown.parse_files`
* `Styledown.render`

API them is exactly the same as the JS version ([docs]).

```rb
require 'styledown'

# Passing a Styledown sting:
Styledown.parse('### hello', bare: true)

# Parsing files from disk:
Styledown.parse([
'/path/to/input.css',
'/path/to/input.md',
'...'
data = Styledown.parse_files([
'/path/to/buttons.md',
'/path/to/forms.md',
'...'
])

# Parsing files from elsewhere:
Styledown.parse([
{ name: "input.md", data: "### hi from md" },
{ name: "input.css", data: "/**\n * hi from css:\n * world\n */" }
data = Styledown.parse([
{ name: 'buttons.md', contents: '### hi from buttons' },
{ name: 'forms.md', contents: '### hi from forms' },
])

# Rendering a page:
html = Styledown.render(data, 'buttons.md')
html = Styledown.render(data, 'forms.md')
```


[docs]: https://github.com/styledown/styledown/blob/master/docs/API.md#styledownparse
[docs]: https://github.com/styledown/styledown/blob/v2/docs/api.md#styledownparse

## :copyright:

**styledown** © 2014+, Rico Sta. Cruz. Released under the [MIT License].<br>
**styledown** © 2014-2016, Rico Sta. Cruz. Released under the [MIT License].<br>
Authored and maintained by Rico Sta. Cruz with help from [contributors].

> [ricostacruz.com](http://ricostacruz.com) &nbsp;&middot;&nbsp;
Expand Down
12 changes: 9 additions & 3 deletions lib/styledown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ def context
end

def parse(source, options = {})
source = unpack_files(source) if array_of_filenames?(source)

context.call('Styledown.parse', source, options)
end

def parse_files(source, options = {})
parse unpack_files(source), options
end

def render(data, file, options = {})
context.call('Styledown.render', data, file, options)
end

def js_version
context.eval('Styledown.version')
end

private

def unpack_files(source)
source.map { |file| { name: file, data: File.read(file) } }
source.map { |file| { name: file, contents: File.read(file) } }
end

def array_of_filenames?(source)
Expand Down
2 changes: 1 addition & 1 deletion lib/styledown/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Styledown
def self.version
'1.0.1'
'2.0.0-pre1'
end
end
6 changes: 3 additions & 3 deletions styledown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Gem::Specification.new do |s|

s.author = 'Rico Sta. Cruz'
s.email = 'hi@ricostacruz.com'
s.homepage = 'http://github.com/styledown/styledown-ruby'
s.homepage = 'http://github.com/styledown/styledown-rails'
s.license = 'MIT'

s.add_dependency 'execjs', '>= 0'
s.add_development_dependency 'rake', '>= 0'
s.add_dependency 'execjs', '>= 0', '< 3'
s.add_development_dependency 'rake', '>= 0', '< 12'
end
3 changes: 3 additions & 0 deletions test/fixtures/simple/other_sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Sample md block

Hello world.
4 changes: 0 additions & 4 deletions test/fixtures/simple/sample.css

This file was deleted.

74 changes: 35 additions & 39 deletions test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,58 @@

describe 'Basic parsing' do
before do
@output = Styledown.parse('### hi')
@data = Styledown.parse([{
name: 'buttons.md',
contents: '### hi'
}])
end

it 'produces an HTML fragment' do
@output.must_match /<h3[^>]+>hi<\/h3>/
it 'works' do
@data['files'].must_be_kind_of Hash
@data['files']['buttons.md'].must_be_kind_of Hash
@data['files']['buttons.md']['sections'].must_be_kind_of Hash
end

it "doesn't produce an HTML document" do
@output.wont_match /^<!doctype html>/
end
end
describe 'with rendering' do
before do
@output = Styledown.render(@data, 'buttons.md')
end

describe 'Working with many files' do
before do
@output = Styledown.parse([
{ name: 'input.md', data: '### hi from md' },
{ name: 'input.css', data: "/**\n * hi from css:\n * world\n */" }
])
end
it 'produces an HTML fragment' do
@output.must_match /<h3[^>]+>hi<\/h3>/
end

it 'parses the Markdown file' do
@output.must_match /<h3[^>]+>hi from md<\/h3>/
it "doesn't produce an HTML document" do
@output.wont_match /^<!doctype html>/
end
end

it 'parses the CSS file' do
@output.must_match /<h3[^>]+>hi from css<\/h3>/
end
end
describe 'with rendering with layouts' do
before do
@output = Styledown.render(@data, 'buttons.md', layout: '<!doctype html><%- body %>')
end

describe 'head options' do
before do
@output = Styledown.parse('### hi', head: '<meta>')
end

it 'includes the head text' do
@output.must_match /<meta>/
end
it 'produces HTML' do
@output.must_match /<h3[^>]+>hi<\/h3>/
end

it 'produces an HTML document' do
@output.must_match /^<!doctype html>/
it "uses the layout" do
@output.must_match /^<!doctype html>/
end
end
end

describe 'Working with arrays of strings' do
before do
@output = Styledown.parse([
fixture_path('simple/sample.css'),
fixture_path('simple/sample.md')
@output = Styledown.parse_files([
fixture_path('simple/sample.md'),
fixture_path('simple/other_sample.md')
])
end

it 'renders from .md' do
@output.must_match /Sample md block<\/h3>/
end

it 'renders from .css' do
@output.must_match /Sample CSS block<\/h3>/
it 'parses' do
@output['files'].must_be_kind_of Hash
@output['files'][fixture_path('simple/sample.md')].must_be_kind_of Hash
@output['files'][fixture_path('simple/other_sample.md')].must_be_kind_of Hash
end
end
Loading