markdown_to_html 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/index.md ADDED
@@ -0,0 +1,227 @@
1
+ # ViewAssets
2
+ ViewAssets(VA) 是一个简单的 Javascript, Stylesheets 依赖管理器。 根据 Rails 3.2 中的 asset pipeline,它会默认加载所有的 assets 资源,这样其实对于富 JS 应用而言并不是特别有利。因为每个页面有可能都包含着大量其它页面都需要用到的文件资源。VA 就是为了解决这个问题而提出来的。它支持每个页面都能够加载自己需要的 assets 资源,同时也保留了 assets pipeline 自动处理依赖的优点。
3
+
4
+ 简单的概括这个 <span style='color:red;'>gem</span> 就是它将在 view 中 *.html.erb 中声明的依赖转移到 js/css 文件中。在特定的文件(manifest file)中使用规定的语法(directive)声明依赖。
5
+
6
+ ## Example
7
+
8
+ 下面的目录是一个 rails 项目的 public 文件夹。
9
+
10
+ .
11
+ ├── 404.html
12
+ ├── 422.html
13
+ ├── 500.html
14
+ ├── app
15
+ │   ├── javascripts
16
+ │   │   ├── application.js
17
+ │   │   ├── bar
18
+ │   │   │   ├── index
19
+ │   │   │   │   ├── index.js
20
+ │   │   │   │   └── others.js
21
+ │   │   │   └── show.js
22
+ │   │   └── foo
23
+ │   │   ├── foo.js
24
+ │   │   ├── index
25
+ │   │   │   ├── index.js
26
+ │   │   │   └── others.js
27
+ │   │   └── show.js
28
+ │   └── stylesheets
29
+ │   ├── application.css
30
+ │   ├── bar
31
+ │   │   ├── index
32
+ │   │   │   ├── index.css
33
+ │   │   │   └── others.css
34
+ │   │   └── show.css
35
+ │   └── foo
36
+ │      ├── foo.css
37
+ │   ├── index
38
+ │   │   ├── index.css
39
+ │   │   └── others.css
40
+ │   └── show.css
41
+ ├── favicon.ico
42
+ ├── lib
43
+ │   ├── javascripts
44
+ │   │   ├── lib1.js
45
+ │   │   └── lib2.js
46
+ │   └── stylesheets
47
+ │   ├── lib1.css
48
+ │   └── lib2.css
49
+ └── vendor
50
+ ├── javascripts
51
+ │   ├── vendor1.js
52
+ │   └── vendor2.js
53
+ └── stylesheets
54
+ ├── vendor1.css
55
+ └── vendor2.css
56
+
57
+ 有如下的依赖声明:
58
+
59
+ /vendor/javascripts/vendor1.js
60
+
61
+ ```js
62
+ //= require_vendor vendor2
63
+ ```
64
+
65
+ /lib/javascripts/lib1.js
66
+
67
+ ```js
68
+ //= require_vendor lib2
69
+ ```
70
+
71
+ /app/javascripts/application.js
72
+
73
+ ```js
74
+ /**
75
+ *= require_vendor vendor1
76
+ *= require_lib lib1
77
+ */
78
+ ```
79
+
80
+ /app/javascripts/bar/show.js
81
+
82
+ ```js
83
+ //= reuquire index/others.js
84
+ ```
85
+
86
+ 当访问 `bar/show`(比如:`localhost:3000/bar/show`) 时,可以看到在其 `html` 文件中的 `head` 有下面的几个 `script` 自动插入了:
87
+
88
+ <script src="vendor2.js" type="text/javascript"></script>
89
+ <script src="vendor1.js" type="text/javascript"></script>
90
+ <script src="lib2.js" type="text/javascript"></script>
91
+ <script src="lib1.js" type="text/javascript"></script>
92
+ <script src="application.js" type="text/javascript"></script>
93
+ <script src="index/others.js" type="text/javascript"></script>
94
+
95
+
96
+ ## CONVENTIONS/RULES
97
+
98
+ 使用 rake view_assets:init 任务,VA 会在 public 目录中添加下面的文件结构:
99
+
100
+ |- vendor
101
+ |- javascripts
102
+ |- stylesheets
103
+ |- lib
104
+ |- javascripts
105
+ |- stylesheets
106
+ |- app
107
+ |- javascripts
108
+ |-application.js
109
+ |- stylesheets
110
+ |-application.css
111
+
112
+ 和 rails assets pipeline 相似,它有三种目录存放 js 以及 css 文件。每种类型的含义都和 pipeline 相同。
113
+
114
+ vendor
115
+ 用于存放如 Extjs, JQuery 等外部库。
116
+
117
+ lib
118
+ 用于存放自己拓展的功能,比如一些拓展于 Extjs 的库或者一些其它公用的拓展功能等。
119
+
120
+ app
121
+ 用于存放每个页面需要用到的资源。
122
+
123
+ ### manifest file
124
+
125
+ **NOTE**
126
+ 下面例子讲述的时候大都直接使用 javascript 当例子,stylesheets 的所有规则几乎和 javascripts 一致。如有不同会单独提示。
127
+
128
+ manifest file 指的是用于声明文件依赖的文件,**只有在这个文件中声明依赖才是有效的**,因为 VA 只会解析 manifest file,并为你关联好依赖。
129
+
130
+ 三个不同的目录有各自特点的 manifest file。
131
+
132
+ #### In Vendor & Lib
133
+
134
+ 对于 vendor 和 lib 资源,manifest file 可以是如下形式:
135
+
136
+ 如果该资源只有一个文件,且直接放置于资源根目录下(即 vendor/javascritps 或者 lib/javascritps),则这个文件本身就是 manifest file,我们可以在文件的头部直接添加其文件依赖。
137
+
138
+ 如果该资源有多个文件,且存放于同一个文件夹中,则该文件夹中的 index.js 文件被定义为 manifest file。
139
+
140
+ **NOTE**
141
+ 注意同一个文件夹内的依赖不需要声明,因为 VA 会自动将文件中所有的 assets 文件加载进来。
142
+
143
+ #### In App
144
+
145
+ 对于 app 目录,它有两种 manifest file,一种是 controller 级别的,另一种是 action 级别的。
146
+
147
+ 对于 controlle 级别的 manifest file,VA 类似 rails 的 views,如果这个 controller 本身存在自己的依赖,即( 存在这个文件 /app/javascripts/:controller/:controller.js),则不会使用 /app/javascripts/application.js。
148
+
149
+ 对于 action,则和 vendor、lib 相似,如果只有一个文件,则 manifest file 为 /app/javascripts/:controller/:action.js,如果该 action 有多个文件,则需要将其组织在以 action 为名的文件夹中,同时在这些中以 index 为名的文件为 manifest file。
150
+
151
+ **NOTE** VA 会自动将 `/app/javascripts/:controller/:action` 中所有的 assets 文件加载进来。
152
+
153
+ #### Others
154
+
155
+ 在开发过程中并不一定要使用 manifest file,要注意的是如果有特别依赖要声明的时候,要声明于该文件中,这样 VA 才能正确的为你关联好依赖。
156
+
157
+ ## DIRECTIVE
158
+
159
+ 同样,VA 也可以在文件中声明依赖,声明的规则基本业余 pipeline 相似。js 中支持三种声明方式,css 中支持两种。
160
+
161
+ for javascript
162
+ double-slash syntax => "//= require_vendor xxx"
163
+ space-asterisk syntax => " *= require_vendor xxx"
164
+ slash-asterisk syntax => "/*= require_vendor xxx */"
165
+
166
+ for stylesheets
167
+ space-asterisk syntax => " *= require_vendor xxx"
168
+ slash-asterisk syntax => "/*= require_vendor xxx */"
169
+
170
+ 上面列出的三种声明方式,而声明指令也有三个,分别是:
171
+
172
+ * `require_vendor` 会在 vendor 文件夹中寻找目的资源
173
+ * `require_lib` 会在 lib 文件夹中寻找目的资源
174
+ * `require` 会在 app 文件夹中寻找目的资源
175
+
176
+ 对于 `require` 指令,AV 主要提供的是对同一个 controller 下和不同 controller 下的资源进行加载,这些文件都不会被视为 manifest file,所以不会对其进行解析。
177
+
178
+ 加载同一个 controller 的资源时,参数不要包含 controller 名字以及不能以 `/` 开头,任何以 `/` 开头的参数在 `require` 中会视为加载其他 controller 文件。
179
+
180
+ `require path/to/file`
181
+
182
+ 加载不同 controller 的资源时
183
+
184
+ `require /other_controller/path/to/file`
185
+
186
+ ## Arguments/Path
187
+
188
+ 在 Directive 后跟着的依赖的参数。如:
189
+
190
+ ```js
191
+ /**
192
+ * require_vendor vendor1, vendor2 => <script src="/vendor/javascripts/vendor1.js" type="text/javascript"></script>
193
+ * <script src="/vendor/javascripts/vendor2.js" type="text/javascript"></script>
194
+ *
195
+ * require_lib lib1 => <script src="/lib/javascripts/lib1.js" type="text/javascript"></script>
196
+ * require_lib lib2 => <script src="/lib/javascripts/lib2.js" type="text/javascript"></script>
197
+ * require /other_controller/path/to/file => <script src="/app/javascripts/other_controller/path/to/tile.js" type="text/javascript"></script>
198
+ */
199
+ ```
200
+
201
+ ## USAGE
202
+
203
+ 在 Gemfile 中添加下面的代码:
204
+
205
+ `gem 'view_assets'`
206
+
207
+ 接下来,需要在 `/app/helpers/application_helper.rb` include `ViewAssets`。
208
+
209
+ ```ruby
210
+ module ApplicationHelper
211
+ include ViewAssets
212
+ end
213
+ ```
214
+
215
+ 在你的 `/app/views/layouts/application.html.rb` 文件中需要添加下面代码:
216
+
217
+ ```ruby
218
+ <%= include_assets_with_assets_mvc(params[:controller], params[:action]) %>
219
+ ```
220
+
221
+ 如果你的 controller 使用了自己的 layout 的话,则需要将在 `app/views/layouts/application.html.rb` 添加的代码也添加进去。
222
+
223
+ ## OTHERS
224
+
225
+ 虽然这个 gem 有一定的方便性,但毕竟这是个简单的设计,目前支持简单的依赖管理,并不是个像 assets pipeline 一样十分成熟的程序。目前它还不支持许多 assets pipeline 实现的事情,比如在 production 模式下自动将所有 assets 压缩成一个文件等。
226
+
227
+ This project rocks and uses MIT-LICENSE.
data/test/test.rb ADDED
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/markdown_to_html')
2
+
3
+ require File.dirname(__FILE__) + '/../lib/markdown_to_html.rb'
4
+
5
+ MarkdownToHtml::Renderer.new 'index.md'
6
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown_to_html
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - bom.d.van
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redcarpet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.2.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: pygments.rb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.3.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.7
46
+ description: render a github-flavored markdown file into a beautiful html document
47
+ email:
48
+ - bom.d.van@gmail.com
49
+ executables:
50
+ - markdown_to_html
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/markdown_to_html
60
+ - lib/markdown_to_html.rb
61
+ - lib/markdown_to_html/template.html.erb
62
+ - lib/markdown_to_html/version.rb
63
+ - markdown_to_html.gemspec
64
+ - test/github.css
65
+ - test/index.md
66
+ - test/test.rb
67
+ homepage: ''
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ - lib/markdown_to_html
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.24
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: With the funtionality of rendering github flavored markdown file into a html
92
+ file, markdown_to_html also offers user a good-looking html style, making reading
93
+ rendered html document an enjoyment.
94
+ test_files:
95
+ - test/github.css
96
+ - test/index.md
97
+ - test/test.rb