#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:config
Add authorization. In the config file
config.authorize_with :cancan #only cancan is supported for now
The 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_line
The first line to readlast_line
The last line to readline
The line where the editor will be centered(To be used withradius
)radius
The radius around the given line (To be used withline
)editormode
Set what the editor can do. (AddRailsEmbedEditor::EditorMode::
in front)READONLY
The editor will only be able to show the contentREADWRIE
The editor will start in readonly mode but an option to enable editing is displayedWRITE
The editor start in edit modehighlight
Highlight some part of the code(String). It can have 3 difference formatline
Will highlight the given lineline_start, line_end
Will highlight the range of line givenline_start, col_start, line_end, cold_end
Will 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-chaos
Then edit the global variable
window.rails_embed_editor_default_theme = 'themeIwant'
#Example
window.rails_embed_editor_default_theme = 'chaos'