mark_it_zero 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +26 -1
  4. data/README.md +121 -3
  5. data/app/assets/fonts/mark_it_zero/icomoon.dev.svg +56 -0
  6. data/app/assets/fonts/mark_it_zero/icomoon.eot +0 -0
  7. data/app/assets/fonts/mark_it_zero/icomoon.svg +56 -0
  8. data/app/assets/fonts/mark_it_zero/icomoon.ttf +0 -0
  9. data/app/assets/fonts/mark_it_zero/icomoon.woff +0 -0
  10. data/app/assets/javascripts/mark_it_zero/editor.js +7408 -0
  11. data/app/assets/javascripts/mark_it_zero/mark_it_zero.js +11 -0
  12. data/app/assets/javascripts/mark_it_zero/marked.js +1165 -0
  13. data/app/assets/stylesheets/mark_it_zero/custom.scss +31 -0
  14. data/app/assets/stylesheets/mark_it_zero/editor.scss +331 -0
  15. data/app/assets/stylesheets/mark_it_zero/icons.scss +72 -0
  16. data/app/assets/stylesheets/mark_it_zero/mark_it_zero.scss +3 -0
  17. data/app/helpers/mark_it_zero/editor_helper.rb +11 -0
  18. data/lib/mark_it_zero.rb +5 -0
  19. data/lib/mark_it_zero/converts_markdown.rb +53 -0
  20. data/lib/mark_it_zero/engine.rb +7 -0
  21. data/lib/mark_it_zero/version.rb +1 -1
  22. data/mark_it_zero.gemspec +4 -0
  23. data/test/dummy/app/assets/javascripts/application.js +3 -12
  24. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  25. data/test/dummy/app/assets/stylesheets/application.css +1 -0
  26. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  27. data/test/dummy/app/controllers/posts_controller.rb +46 -0
  28. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  29. data/test/dummy/app/models/post.rb +5 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +2 -2
  31. data/test/dummy/app/views/posts/_post.html.erb +14 -0
  32. data/test/dummy/app/views/posts/index.html.erb +2 -0
  33. data/test/dummy/app/views/posts/new.html.erb +7 -0
  34. data/test/dummy/config/initializers/simple_form.rb +166 -0
  35. data/test/dummy/config/locales/simple_form.en.yml +31 -0
  36. data/test/dummy/config/routes.rb +3 -1
  37. data/test/dummy/db/migrate/20150424103520_create_posts.rb +11 -0
  38. data/test/dummy/db/schema.rb +24 -0
  39. data/test/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  40. data/test/dummy/test/controllers/posts_controller_test.rb +7 -0
  41. data/test/dummy/test/fixtures/posts.yml +11 -0
  42. data/test/dummy/test/helpers/posts_helper_test.rb +4 -0
  43. data/test/dummy/test/models/post_test.rb +7 -0
  44. metadata +105 -1
data/lib/mark_it_zero.rb CHANGED
@@ -1,4 +1,9 @@
1
1
  require "mark_it_zero/engine"
2
+ require "mark_it_zero/converts_markdown"
3
+
4
+ # In case required gems are missing from project Gemfile
5
+ require 'jquery-rails'
6
+ require 'sass-rails'
2
7
 
3
8
  module MarkItZero
4
9
  end
@@ -0,0 +1,53 @@
1
+ require 'redcarpet'
2
+ require 'pygments.rb'
3
+
4
+ class << ActiveRecord::Base
5
+
6
+ def converts_markdown(markdown = :markdown, html = :html)
7
+ markdown = markdown.to_s
8
+ html = html.to_s
9
+
10
+ after_save :"convert_#{markdown}_to_#{html}"
11
+
12
+ define_method "convert_#{markdown}_to_#{html}" do
13
+ renderer = Redcarpet::Markdown.new(
14
+ HTMLwithPygments.new(:hard_wrap => false, :with_toc_data => true),
15
+ {
16
+ :autolink => true,
17
+ :fenced_code_blocks => true,
18
+ :highlight => true,
19
+ :space_after_headers => true,
20
+ :strikethrough => true,
21
+ :tables => true,
22
+ :underline => true,
23
+ }
24
+ )
25
+
26
+ update_columns(
27
+ html.to_sym => renderer.render(self.send("clean_#{markdown}"))
28
+ )
29
+ end
30
+
31
+ define_method "clean_#{markdown}" do
32
+ md = self.send(markdown)
33
+ return "" if md.blank?
34
+ md.gsub(
35
+ /(?:http[s]?:\/\/)?(?:www\.)?(?:youtu\.be)\/(?:watch\?v=)?(.+)/,
36
+ '<iframe width="420" height="345" src="http://www.youtube.com/embed/\1" frameborder="0" allowfullscreen></iframe>'
37
+ ).gsub(
38
+ /[”“]/,
39
+ '"'
40
+ ).gsub(
41
+ /\[file\:(.*)\]/,
42
+ '<p class="file"><code>\1</code></p>'
43
+ )
44
+ end
45
+ end
46
+
47
+ class HTMLwithPygments < Redcarpet::Render::HTML
48
+ def block_code(code, language)
49
+ Pygments.highlight(code, lexer: language)
50
+ end
51
+ end
52
+
53
+ end
@@ -1,5 +1,12 @@
1
1
  module MarkItZero
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace MarkItZero
4
+
5
+ # Autoload the view helper
6
+ initializer 'mark_it_zero.action_controller' do |app|
7
+ ActiveSupport.on_load :action_controller do
8
+ helper MarkItZero::EditorHelper
9
+ end
10
+ end
4
11
  end
5
12
  end
@@ -1,3 +1,3 @@
1
1
  module MarkItZero
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  end
data/mark_it_zero.gemspec CHANGED
@@ -20,6 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "rails", "~> 4.1.0"
23
+ spec.add_dependency 'jquery-rails'
24
+ spec.add_dependency 'sass-rails'
25
+ spec.add_dependency 'redcarpet'
26
+ spec.add_dependency 'pygments.rb'
23
27
 
24
28
  spec.add_development_dependency "sqlite3"
25
29
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -1,13 +1,4 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require mark_it_zero/mark_it_zero
13
4
  //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -11,5 +11,6 @@
11
11
  * file per style scope.
12
12
  *
13
13
  *= require_tree .
14
+ *= require mark_it_zero/mark_it_zero
14
15
  *= require_self
15
16
  */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,46 @@
1
+ class PostsController < ApplicationController
2
+
3
+ def index
4
+ @posts = Post.all
5
+ end
6
+
7
+ def new
8
+ @post = Post.new
9
+ end
10
+
11
+ def create
12
+ @post = Post.new(post_params)
13
+ if @post.save
14
+ redirect_to posts_path, :notice => 'Post saved!'
15
+ else
16
+ render 'new'
17
+ end
18
+ end
19
+
20
+ def edit
21
+ @post = Post.find_by_id(params[:id])
22
+ render 'new'
23
+ end
24
+
25
+ def update
26
+ @post = Post.find_by_id(params[:id])
27
+ if @post.update(post_params)
28
+ redirect_to posts_path, :notice => 'Post saved!'
29
+ else
30
+ render 'new'
31
+ end
32
+ end
33
+
34
+ def destroy
35
+ @post = Post.find_by_id(params[:id])
36
+ @post.destroy
37
+ redirect_to posts_path, :notice => 'Post deleted!'
38
+ end
39
+
40
+ private
41
+
42
+ def post_params
43
+ params.require(:post).permit(:title, :markdown)
44
+ end
45
+
46
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ converts_markdown :markdown, :body
4
+
5
+ end
@@ -2,8 +2,8 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
5
+ <%= stylesheet_link_tag 'application', media: 'all' %>
6
+ <%= javascript_include_tag 'application' %>
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
@@ -0,0 +1,14 @@
1
+ <article>
2
+ <%= content_tag(:h2, post.title) %>
3
+ <div class="markdown">
4
+ <h4>Markdown:</h4>
5
+ <%= content_tag(:pre, post.markdown) %>
6
+ </div>
7
+ <div class="body">
8
+ <h4>Body:</h4>
9
+ <%= post.body.html_safe if post.body.present? %>
10
+ </div>
11
+ <%= link_to 'Edit', edit_post_path(post) %>
12
+ <%= link_to 'Delete', post_path(post), :method => :delete %>
13
+ <hr>
14
+ </article>
@@ -0,0 +1,2 @@
1
+ <%= link_to 'New Post', new_post_path %>
2
+ <%= render @posts %>
@@ -0,0 +1,7 @@
1
+ <%= simple_form_for @post do |f| %>
2
+
3
+ <%= f.input :title %>
4
+ <%= f.markdown :markdown %>
5
+
6
+ <%= f.submit %>
7
+ <% end %>
@@ -0,0 +1,166 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ # Wrappers are used by the form builder to generate a
4
+ # complete input. You can remove any component from the
5
+ # wrapper, change the order or even add your own to the
6
+ # stack. The options given below are used to wrap the
7
+ # whole input.
8
+ config.wrappers :default, class: :input,
9
+ hint_class: :field_with_hint, error_class: :field_with_errors do |b|
10
+ ## Extensions enabled by default
11
+ # Any of these extensions can be disabled for a
12
+ # given input by passing: `f.input EXTENSION_NAME => false`.
13
+ # You can make any of these extensions optional by
14
+ # renaming `b.use` to `b.optional`.
15
+
16
+ # Determines whether to use HTML5 (:email, :url, ...)
17
+ # and required attributes
18
+ b.use :html5
19
+
20
+ # Calculates placeholders automatically from I18n
21
+ # You can also pass a string as f.input placeholder: "Placeholder"
22
+ b.use :placeholder
23
+
24
+ ## Optional extensions
25
+ # They are disabled unless you pass `f.input EXTENSION_NAME => true`
26
+ # to the input. If so, they will retrieve the values from the model
27
+ # if any exists. If you want to enable any of those
28
+ # extensions by default, you can change `b.optional` to `b.use`.
29
+
30
+ # Calculates maxlength from length validations for string inputs
31
+ b.optional :maxlength
32
+
33
+ # Calculates pattern from format validations for string inputs
34
+ b.optional :pattern
35
+
36
+ # Calculates min and max from length validations for numeric inputs
37
+ b.optional :min_max
38
+
39
+ # Calculates readonly automatically from readonly attributes
40
+ b.optional :readonly
41
+
42
+ ## Inputs
43
+ b.use :label_input
44
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
45
+ b.use :error, wrap_with: { tag: :span, class: :error }
46
+
47
+ ## full_messages_for
48
+ # If you want to display the full error message for the attribute, you can
49
+ # use the component :full_error, like:
50
+ #
51
+ # b.use :full_error, wrap_with: { tag: :span, class: :error }
52
+ end
53
+
54
+ # The default wrapper to be used by the FormBuilder.
55
+ config.default_wrapper = :default
56
+
57
+ # Define the way to render check boxes / radio buttons with labels.
58
+ # Defaults to :nested for bootstrap config.
59
+ # inline: input + label
60
+ # nested: label > input
61
+ config.boolean_style = :nested
62
+
63
+ # Default class for buttons
64
+ config.button_class = 'btn'
65
+
66
+ # Method used to tidy up errors. Specify any Rails Array method.
67
+ # :first lists the first message for each field.
68
+ # Use :to_sentence to list all errors for each field.
69
+ # config.error_method = :first
70
+
71
+ # Default tag used for error notification helper.
72
+ config.error_notification_tag = :div
73
+
74
+ # CSS class to add for error notification helper.
75
+ config.error_notification_class = 'error_notification'
76
+
77
+ # ID to add for error notification helper.
78
+ # config.error_notification_id = nil
79
+
80
+ # Series of attempts to detect a default label method for collection.
81
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
82
+
83
+ # Series of attempts to detect a default value method for collection.
84
+ # config.collection_value_methods = [ :id, :to_s ]
85
+
86
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
87
+ # config.collection_wrapper_tag = nil
88
+
89
+ # You can define the class to use on all collection wrappers. Defaulting to none.
90
+ # config.collection_wrapper_class = nil
91
+
92
+ # You can wrap each item in a collection of radio/check boxes with a tag,
93
+ # defaulting to :span. Please note that when using :boolean_style = :nested,
94
+ # SimpleForm will force this option to be a label.
95
+ # config.item_wrapper_tag = :span
96
+
97
+ # You can define a class to use in all item wrappers. Defaulting to none.
98
+ # config.item_wrapper_class = nil
99
+
100
+ # How the label text should be generated altogether with the required text.
101
+ # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
102
+
103
+ # You can define the class to use on all labels. Default is nil.
104
+ # config.label_class = nil
105
+
106
+ # You can define the default class to be used on forms. Can be overriden
107
+ # with `html: { :class }`. Defaulting to none.
108
+ # config.default_form_class = nil
109
+
110
+ # You can define which elements should obtain additional classes
111
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
112
+
113
+ # Whether attributes are required by default (or not). Default is true.
114
+ # config.required_by_default = true
115
+
116
+ # Tell browsers whether to use the native HTML5 validations (novalidate form option).
117
+ # These validations are enabled in SimpleForm's internal config but disabled by default
118
+ # in this configuration, which is recommended due to some quirks from different browsers.
119
+ # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
120
+ # change this configuration to true.
121
+ config.browser_validations = false
122
+
123
+ # Collection of methods to detect if a file type was given.
124
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
125
+
126
+ # Custom mappings for input types. This should be a hash containing a regexp
127
+ # to match as key, and the input type that will be used when the field name
128
+ # matches the regexp as value.
129
+ # config.input_mappings = { /count/ => :integer }
130
+
131
+ # Custom wrappers for input types. This should be a hash containing an input
132
+ # type as key and the wrapper that will be used for all inputs with specified type.
133
+ # config.wrapper_mappings = { string: :prepend }
134
+
135
+ # Namespaces where SimpleForm should look for custom input classes that
136
+ # override default inputs.
137
+ # config.custom_inputs_namespaces << "CustomInputs"
138
+
139
+ # Default priority for time_zone inputs.
140
+ # config.time_zone_priority = nil
141
+
142
+ # Default priority for country inputs.
143
+ # config.country_priority = nil
144
+
145
+ # When false, do not use translations for labels.
146
+ # config.translate_labels = true
147
+
148
+ # Automatically discover new inputs in Rails' autoload path.
149
+ # config.inputs_discovery = true
150
+
151
+ # Cache SimpleForm inputs discovery
152
+ # config.cache_discovery = !Rails.env.development?
153
+
154
+ # Default class for inputs
155
+ # config.input_class = nil
156
+
157
+ # Define the default class of the input wrapper of the boolean input.
158
+ config.boolean_label_class = 'checkbox'
159
+
160
+ # Defines if the default input wrapper class should be included in radio
161
+ # collection wrappers.
162
+ # config.include_default_input_wrapper_class = true
163
+
164
+ # Defines which i18n scope will be used in Simple Form.
165
+ # config.i18n_scope = 'simple_form'
166
+ end
@@ -0,0 +1,31 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
4
+ "no": 'No'
5
+ required:
6
+ text: 'required'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Please review the problems below:"
13
+ # Examples
14
+ # labels:
15
+ # defaults:
16
+ # password: 'Password'
17
+ # user:
18
+ # new:
19
+ # email: 'E-mail to sign in.'
20
+ # edit:
21
+ # email: 'E-mail.'
22
+ # hints:
23
+ # defaults:
24
+ # username: 'User name to sign in.'
25
+ # password: 'No special characters, please.'
26
+ # include_blanks:
27
+ # defaults:
28
+ # age: 'Rather not say'
29
+ # prompts:
30
+ # defaults:
31
+ # age: 'Select your age'
@@ -1,4 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- mount MarkItZero::Engine => "/mark_it_zero"
3
+ # mount MarkItZero::Engine => "/mark_it_zero"
4
+
5
+ resources :posts
4
6
  end
@@ -0,0 +1,11 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.text :markdown
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end