Module: Accio
- Defined in:
- lib/accio.rb,
lib/accio/code.rb,
lib/accio/group.rb,
lib/accio/parser.rb,
lib/accio/comment.rb,
lib/accio/content.rb,
lib/accio/snippet.rb,
lib/accio/version.rb,
lib/accio/formatter.rb
Overview
Public: Accio is a module that helps to organize and categorize code snippets in the terminal.
Defined Under Namespace
Modules: Formatter, Parser Classes: Code, Comment, Content, Group, Snippet
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
-
.configure(path) ⇒ Object
Public: Rewrites the snip configuration file in the home directory.
-
.copy(group, snippet = nil) ⇒ Object
Public: Searches code snippets for a specified group and optionally for a specified snippet title and copies the last found code snippet to the clipboard.
-
.show(group, snippet = nil) ⇒ Object
Public: Shows the code snippets for the specified group and optionally for the specified snippet title.
-
.show_groups ⇒ Object
Public: Shows all the groups that are existing in the markdown file.
Class Method Details
.configure(path) ⇒ Object
Public: Rewrites the snip configuration file in the home directory.
12 13 14 15 16 17 |
# File 'lib/accio.rb', line 12 def configure(path) File.open(File.join(Dir.home, ".accio"), "w") do |file| file.puts path end puts "Accio was configured successfully" end |
.copy(group, snippet = nil) ⇒ Object
Public: Searches code snippets for a specified group and optionally for a specified snippet title and copies the last found code snippet to the clipboard.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/accio.rb', line 45 def copy(group, snippet = nil) content = Accio::Parser.read matches = content.search(group, snippet) matches.each do |match| match.snippets.each do |submatch| # Copy code to clipboard. Clipboard.copy submatch.code.text.gsub(/^$\n/, '') # Format the output and display it. Accio::Formatter.template( match.title, submatch.title, submatch.comment, submatch.code ) end end puts "The last found code snippet has been copied to the clipboard" end |
.show(group, snippet = nil) ⇒ Object
Public: Shows the code snippets for the specified group and optionally for the specified snippet title.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/accio.rb', line 29 def show(group, snippet = nil) content = Accio::Parser.read matches = content.search(group, snippet) matches.each do |match| match.snippets.each do |submatch| # Format the output and display it. Accio::Formatter.template( match.title, submatch.title, submatch.comment, submatch.code ) end end end |