rails_embed_editor
#Installation Install the gem
gem 'rails_embed_editor'Include the assests
<%= javascript_include_tag 'rails_embed_editor/application' if Rails.env.development? %>
<%= stylesheet_link_tag 'rails_embed_editor/application' if Rails.env.development? %>#Configure Generate the config file
rails g rails_embed_editor:configAdd authorization. In the config file
config.authorize_with :cancan #only cancan is supported for nowThe user need the permission `:edit :local_file' to be edit a file.
#How it work Use the method helper to generate an editor
rails_embed_editor(somefile, options)You can give the follwoing options:
-
first_lineThe first line to read -
last_lineThe last line to read -
lineThe line where the editor will be centered(To be used withradius) -
radiusThe radius around the given line (To be used withline) -
editormodeSet what the editor can do. (AddRailsEmbedEditor::EditorMode::in front) -
READONLYThe editor will only be able to show the content -
READWRIEThe editor will start in readonly mode but an option to enable editing is displayed -
WRITEThe editor start in edit mode -
highlightHighlight some part of the code(String). It can have 3 difference format -
lineWill highlight the given line -
line_start, line_endWill highlight the range of line given -
line_start, col_start, line_end, cold_endWill highlight the given range with column start and end Example: (This will read 2 line around line 5 in the filewelcome/how.html.erb)
<%= rails_embed_editor("#{Rails.root}/app/views/welcome/show.html.erb", :line => 5, :radius => 2,
:highlight => '5'
:editormode => RailsEmbedEditor::EditorMode::READ_WRITE) %>This is what the editor looks like
#Customization ##Change default theme The plugin is using ace_rails_ap gem. You can include any theme the gem has included.
First require
#= require ace/theme-themeIwant
#Example
#= require ace/theme-chaosThen edit the global variable
window.rails_embed_editor_default_theme = 'themeIwant'
#Example
window.rails_embed_editor_default_theme = 'chaos'