Class: Jeny::Command::Snippets
- Inherits:
-
Object
- Object
- Jeny::Command::Snippets
- Includes:
- Support
- Defined in:
- lib/jeny/command/snippets.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(config, data, asset, from) ⇒ Snippets
constructor
A new instance of Snippets.
- #snippet_it(source, parent) ⇒ Object
Methods included from Support
#edit_changed_files, simplify_path
Constructor Details
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
12 13 14 |
# File 'lib/jeny/command/snippets.rb', line 12 def asset @asset end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/jeny/command/snippets.rb', line 12 def config @config end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/jeny/command/snippets.rb', line 12 def data @data end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
12 13 14 |
# File 'lib/jeny/command/snippets.rb', line 12 def from @from end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jeny/command/snippets.rb', line 14 def call puts sm, state = config.state_manager, OpenStruct.new sm.stash(state) if config.sm_stash? changed = [] from.each do |source| parent = source parent = source.parent until parent.directory? _call(source, parent, changed) end sm.commit(changed.map(&:first), state) if config.sm_commit? edit_changed_files(changed) rescue sm.reset(changed.map(&:first), state) raise ensure sm.unstash(state) if config.sm_stash? end |
#snippet_it(source, parent) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jeny/command/snippets.rb', line 54 def snippet_it(source, parent) target, target_content = nil if source.ext =~ /\.?jeny/ file = File::Full.new(source, config) if file.has_jeny_context? ctx = file.instantiate_context(data) if ctx target_content = file.instantiate(ctx) target = target_for(source, ctx) target.parent.mkdir_p target.write(target_content) puts "snippets #{simplify_path(target)}" end end else file = File::WithBlocks.new(source, config) if file.has_jeny_blocks? target_content = file.instantiate(data) target = target_for(source) target.write(target_content) puts "snippets #{simplify_path(target)}" end end target ? [target, target_content] : nil rescue => ex msg = "Error in `#{simplify_path(source)}`: #{ex.}" raise Error, msg, ex.backtrace end |