Skip to content

Commit f752ca7

Browse files
committed
fix(moduleTypePrefix): remove prefix from moduleType when formatting
Closes #7
1 parent 83f8931 commit f752ca7

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

index.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ module.exports = (content, options) ->
1717
# add appName to moduleDetails
1818
details.forEach (detail) ->
1919
detail.appName = appName
20+
modDetails = moduleDetails detail, opts
2021

21-
modules.push moduleDetails detail, opts
22+
modules.push modDetails
2223

2324
# remove angular moduleTypes from content
2425
modTypes.forEach (moduleType) ->

lib/moduleDetails.coffee

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
applyCaseFilters = require './applyCaseFilters'
22

33
module.exports = (details, options) ->
4-
format = options.formats[details.moduleType.toLowerCase()]
5-
parts = format.split /{{(.*?)}}/
6-
compiled = []
4+
prefixLessModuleType = details.moduleType.split('.')[-1..][0]
5+
format = options.formats[prefixLessModuleType.toLowerCase()]
6+
parts = format.split /{{(.*?)}}/
7+
compiled = []
78

89
parts.forEach (part) ->
910
filters = part.split '|'
@@ -16,7 +17,8 @@ module.exports = (details, options) ->
1617

1718
if filters.length > 1
1819
filters = filters.slice(1)
19-
detail = applyCaseFilters detail, filters
20+
key = if component is 'moduleType' then prefixLessModuleType else detail
21+
detail = applyCaseFilters key, filters
2022

2123
compiled.push if detail then detail else component
2224

test/ng-classify.spec.coffee

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,42 @@ describe 'ng-classify', ->
647647
constructor: (baaa) ->
648648
'''
649649

650-
result = ngClassify input
650+
result = ngClassify input
651+
652+
it 'should compile with a moduleType prefix', ->
653+
input = '''
654+
class Home extends Ng.Controller
655+
constructor: ($log) ->
656+
$log.info 'controller with prefix'
657+
'''
658+
659+
result = ngClassify input, prefix: 'Ng'
660+
661+
expectation = '''
662+
class Home
663+
constructor: ($log) ->
664+
$log.info 'controller with prefix'
665+
666+
angular.module('app').controller 'homeController', ['$log', Home]
667+
'''
668+
669+
expect(result).toEqual(expectation)
670+
671+
it 'should compile with a namespace with an ending period (.)', ->
672+
input = '''
673+
class Home extends Ng.My.Controller
674+
constructor: ($log) ->
675+
$log.info 'controller with prefix'
676+
'''
677+
678+
result = ngClassify input, prefix: 'Ng.My.'
679+
680+
expectation = '''
681+
class Home
682+
constructor: ($log) ->
683+
$log.info 'controller with prefix'
684+
685+
angular.module('app').controller 'homeController', ['$log', Home]
686+
'''
687+
688+
expect(result).toEqual(expectation)

0 commit comments

Comments
 (0)