styledown2-rails 2.0.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: df323d809dbb7a979351c5ea908c05dac8b75009
4
+ data.tar.gz: 1eabf0f30e4ce5c5d524434a30073978abe58e7d
5
+ SHA512:
6
+ metadata.gz: d952a6143a4ef4ed5fe0825b3fd9b73e73499580536d538134de57a0508e720de86e41895e2ad039a4d967b5046c7ca3b1c547211e151ce0a2f8f00168af0b09
7
+ data.tar.gz: f8290b9856ffcc9a5629f368677bcf8e5b5fbbe43f054feed5691e5bdb631254352be648be4653403c78d1f6e88f5ebd0fafb0d068d5135ac243855ca43e2e7c
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ /.bundle
3
+ /pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem 'styledown2', github: 'styledown/styledown2-ruby', branch: 'master'
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Styledown for Rails
2
+
3
+ > Write maintainable CSS styleguides using Markdown
4
+
5
+
6
+ ## Install
7
+
8
+ Add the gem to your `Gemfile` and type `bundle install`.
9
+
10
+ ```rb
11
+ gem 'styledown2-rails'
12
+ ```
13
+
14
+ Use the `styledown:install` generator to add the default files.
15
+
16
+ ```rb
17
+ rails g styledown:install
18
+ ```
19
+
20
+ You can also skip using the generator and write the files yourself. See [Manual install](docs/manual_install.md) for details.
21
+
22
+ ## Writing styleguides
23
+
24
+ See Styledown2 documentation.
25
+
26
+ ## API
27
+
28
+ See [API documentation](docs/api.md).
29
+
30
+ ## Thanks
31
+
32
+ **styledown2-rails** © 2017+, Rico Sta. Cruz. Released under the [MIT] License.<br>
33
+ ** © 2017+, Rico Sta. Cruz. Released under the [MIT] License.<br>
34
+ Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).
35
+
36
+ > [ricostacruz.com](http://ricostacruz.com) &nbsp;&middot;&nbsp;
37
+ > GitHub [@rstacruz](https://github.com/rstacruz) &nbsp;&middot;&nbsp;
38
+ > Twitter [@rstacruz](https://twitter.com/rstacruz)
39
+
40
+ [contributors]: http://github.com/styledown/styledown2-rails/contributors
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ task default: :test
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc 'Runs tests'
7
+ task :test do
8
+ $:.unshift(File.expand_path(__FILE__, '../lib'))
9
+ Dir['test/**/*test.rb'].each { |fn| require_relative fn }
10
+ end
data/docs/api.md ADDED
@@ -0,0 +1,3 @@
1
+ # API
2
+
3
+ I'll explain later :-)
@@ -0,0 +1,50 @@
1
+ # Manual install
2
+
3
+ If you prefer not to use the `styledown:install` generator, you can install Styledown manually by making the files yourself.
4
+
5
+ 0. **Controller** — Make a controller to host your styleguides.
6
+
7
+ ```rb
8
+ # app/controllers/styleguides_controller.rb
9
+ class StyleguidesController < ApplicationController
10
+ include Styledown::Rails::Controller
11
+
12
+ styledown.root = 'docs/styleguides'
13
+ styledown.append_template :head, 'styleguides/head'
14
+ styledown.use_template_engine :erb, :haml
15
+ end
16
+ ```
17
+
18
+ 0. **Routes** — Add routes for your new controller.
19
+
20
+ ```rb
21
+ # config/routes.rb
22
+ resource 'styleguides', only: [:show] do
23
+ get '*page', action: :show, as: :page
24
+ end
25
+ ```
26
+
27
+ 0. **View (optional)** — Create the `styleguides/head` partial. This will be injected into the `<head>` section. Optional: you can skip this by changing the controller's `styleguide.append_template` options to use a different partial instead.
28
+
29
+ ```erb
30
+ <!-- app/views/styleguides/_head.html.erb -->
31
+ <%= stylesheet_link_tag 'application' %>
32
+ <%= javascript_include_tag 'application' %>
33
+ ```
34
+
35
+ 0. **Styleguides** — Make your first styleguide in `docs/styleguides`.
36
+
37
+ <!-- docs/styleguides/index.md -->
38
+ # Styleguides
39
+
40
+ These are example styleguides.
41
+
42
+ ### buttons
43
+ These are buttons. And since we defined :haml in `use_template_engine`,
44
+ these haml examples will be rendered within Rails.
45
+
46
+ ```example.haml
47
+ %a.btn.btn-default Click me
48
+ ```
49
+
50
+ 0. **Try it out** — you should now have <http://localhost:3000/styleguides>. Enjoy!
@@ -0,0 +1,3 @@
1
+ require 'styledown/rails/controller'
2
+ require 'styledown/rails/controller_integration'
3
+ require 'styledown/rails/version'
@@ -0,0 +1,29 @@
1
+ class Styledown
2
+ module Rails
3
+ module Controller
4
+ def self.included(klass)
5
+ klass.extend ClassMethods
6
+ klass.include InstanceMethods
7
+
8
+ # Initialize the ControllerIntegration instance
9
+ klass.styledown
10
+ end
11
+
12
+ module ClassMethods
13
+ def styledown
14
+ @styledown ||= ControllerIntegration.new(self)
15
+ end
16
+ end
17
+
18
+ module InstanceMethods
19
+ def styledown
20
+ self.class.styledown
21
+ end
22
+
23
+ def show
24
+ styledown.show self
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,126 @@
1
+ class Styledown
2
+ module Rails
3
+ # Accessible via `#styledown`.
4
+ #
5
+ # class StyleguidesController < ApplicationController
6
+ # include Styledown::Rails::Controller
7
+ #
8
+ # styledown.root = 'docs/styleguides'
9
+ # styledown.options = { skipAssets: true }
10
+ # end
11
+ #
12
+ class ControllerIntegration
13
+ attr_reader :controller_class
14
+ attr_reader :controller_instance
15
+ attr_reader :instance
16
+
17
+ DEFAULT_OPTIONS = { extension: '' }
18
+
19
+ def initialize(controller_class)
20
+ @controller_class = controller_class
21
+ @controller_instance = nil
22
+ @instance = Styledown.new
23
+ @instance.options = DEFAULT_OPTIONS
24
+ end
25
+
26
+ def root=(path)
27
+ path = ::Rails.root.join(path) unless Pathname.new(path).absolute?
28
+ @instance.paths = path
29
+ path
30
+ end
31
+
32
+ def options=(options)
33
+ @instance.options = options
34
+ end
35
+
36
+ # Reloads data, if needed.
37
+ def reload
38
+ # TODO: styledown.no_reload = -> { !::Rails.env.development? }
39
+ if ::Rails.env.development?
40
+ instance.render
41
+ else
42
+ instance.fast_render
43
+ end
44
+ end
45
+
46
+ def show(controller)
47
+ @controller_instance = controller
48
+
49
+ # If there's no trailing slash, add it
50
+ return if redirect_with_trailing_slash(controller)
51
+
52
+ # Find what to be rendered (eg, 'buttons')
53
+ page = get_page(controller.params)
54
+
55
+ # Re-render (if needed), and get the final output
56
+ reload
57
+ file = instance.output[page]
58
+
59
+ raise ActiveRecord::RecordNotFound unless file
60
+ controller.render body: file['contents'], content_type: file['type']
61
+ end
62
+
63
+ # Appends to Styledown template `template` the contents from partial `partial`.
64
+ def append_template(template, partial)
65
+ use_template template, partial, append: true
66
+ end
67
+
68
+ # Replaces Styledown template `template` with contents from partial `partial`.
69
+ def use_template(template, partial, options = {})
70
+ template_name = template.to_s # 'head'
71
+
72
+ instance.add_data_filter do |data|
73
+ html = controller_instance.render_to_string(
74
+ partial: partial, formats: [:html])
75
+
76
+ if options[:append]
77
+ data['templates'][template_name] ||= ''
78
+ data['templates'][template_name] += "\n" + html
79
+ else
80
+ data['templates'][template_name] = html
81
+ end
82
+
83
+ data
84
+ end
85
+ end
86
+
87
+ # Allows the use of a given template engine.
88
+ def use_template_engine(*engines)
89
+ engines.each do |engine|
90
+ instance.add_figure_filter engine do |contents|
91
+ html = controller_instance.render_to_string(
92
+ inline: contents, type: engine.to_sym)
93
+
94
+ ['html', html]
95
+ end
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ # Returns the page to be rendered
102
+ def get_page(params)
103
+ if params[:page]
104
+ page = params[:page]
105
+ page += ".#{params[:format]}" if params[:format]
106
+ page
107
+ else
108
+ 'index'
109
+ end
110
+ end
111
+
112
+ # If there's no trailing slash, add it
113
+ def redirect_with_trailing_slash(controller)
114
+ # Don't use request.path, because that will always be missing a trailing slash.
115
+ path = controller.request.env['REQUEST_PATH']
116
+
117
+ # Check if there's no page and no trailing slash (eg, /styleguides and not
118
+ # /styleguides/ or /styleguides/foo)
119
+ if !controller.params[:page] && path[-1] != '/'
120
+ controller.redirect_to "#{path}/"
121
+ true
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,5 @@
1
+ class Styledown
2
+ module Rails
3
+ VERSION = '2.0.0.pre5'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'styledown/rails'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/styledown/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'styledown2-rails'
6
+ spec.version = Styledown::Rails::VERSION
7
+ spec.authors = ['Rico Sta. Cruz']
8
+ spec.email = ['rstacruz@users.noreply.github.com']
9
+
10
+ spec.summary = 'Write maintainable CSS styleguides using Markdown'
11
+ spec.description = 'Styledown lets you write maintainable CSS styleguides using Markdown.'
12
+ spec.homepage = 'https://github.com/styledown/styledown2'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|example)/}) }
16
+
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'styledown2', '< 3.0.0'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest'
24
+ spec.add_development_dependency 'rails', '< 6.0.0'
25
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: styledown2-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.pre5
5
+ platform: ruby
6
+ authors:
7
+ - Rico Sta. Cruz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: styledown2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "<"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.0.0
69
+ description: Styledown lets you write maintainable CSS styleguides using Markdown.
70
+ email:
71
+ - rstacruz@users.noreply.github.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - docs/api.md
81
+ - docs/manual_install.md
82
+ - lib/styledown/rails.rb
83
+ - lib/styledown/rails/controller.rb
84
+ - lib/styledown/rails/controller_integration.rb
85
+ - lib/styledown/rails/version.rb
86
+ - lib/styledown2-rails.rb
87
+ - styledown2-rails.gemspec
88
+ homepage: https://github.com/styledown/styledown2
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">"
104
+ - !ruby/object:Gem::Version
105
+ version: 1.3.1
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Write maintainable CSS styleguides using Markdown
112
+ test_files: []